Request: CSS width with Percent and Pixels

Started on the old forum in November 2011 · view the original in the archive · old links redirect here

4 replies · 772 views · started 15 years ago · 1 min read

3 participants
kei_ki7 Senior · 431 posts #1

Hello!

I want to make a 2 column which has a percent and a pixel width. Is there any trick to make this without using JavaScript?

Output that I expected is like this A fixed 50 pixel, and the rest is for the 2nd column.

<html>
<frameset cols="50,*" border="1">
  <frame src="frame_a.htm" />
  <frame src="frame_b.htm" />
</frameset>
</html>

Added after 24 minutes:

Hmmm, I guess i can use margin...

Did I help you? You can help me too Your donations will help me finance my studies.

Mysterio Lead · 630 posts #2

Here is your code mate:

<script type="text/javascript"> onload=function() { var leftWidth = document.getElementById('left').offsetWidth; var winWidth = document.body.offsetWidth; var rightWidth = winWidth - leftWidth; document.getElementById('right').style.width = rightWidth+'px'; } </script>

red

blue

So what happens: row 1: get width from left div/frame row 2: get screen width row 3: screen width - (minus) left div/frame row 4: we set width to right div/frame

I made it with divs to test out, you can just make them frames

mysterio.al - programming is a functional art

kei_ki7 Senior · 431 posts #3

Thanks! But I want to make it without using a javascript. I got it using margin.

<html>
<head>
<title></title>
<style type="text/css">
.left {
	background: red;
	clear: both;
	display: block;
	float: left;
	position: relative;
	width: 50px;
}

.right {
    background: blue;
    margin-left: 50px;
}
</style>
</head>
<body>
<div id="wrap">
	<div class="left">
	Left Content
	</div>
	<div class="right">
	Right Content
	</div>
</div>
</body>

Did I help you? You can help me too Your donations will help me finance my studies.

Mysterio Lead · 630 posts #4

Yes you are right, you said without Javascript but I wrongly skiped that part.

For CSS, you can simply do: .left { background: red; float: left; width: 50px; }

.right { background: blue; }

Its the "float" property which makes the .left to lie over .right without the need of margins or something. But I dont suggest it! Still you know!

mysterio.al - programming is a functional art

arnage Lead · 811 posts #5

If its for mobile than is better to use max-width: 50px; instead width: 50px;

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close