...

View Full Version : body {width: xxx}



Tolstoy
01-21-2005, 08:09 AM
Hello. I'm a noob and aplogise for it.

I want to specify that my html body text only fills a certain width. That is, to override the default of have the browser decide my line width.

Reading a few O'Reilly books, I had thought that the following would work, but it doesn't. I'd be very grateful of any advice. I'm using IE 6.0 to view.

<style type="text/css">
body { width : 10cm }
</style>

If something like this has been answered before, please point me to the post. I tried searching and failed to find it.

Thanks,
Tolstoy.

]|V|[agnus
01-21-2005, 08:45 AM
Centimeters should be used for print, if anything. Measurements like that have no real meaning when your canvas' base unit is a pixel, whose size is relative to the monitor resolution.

If you use something like pixels, percentages or em units, what you're attempting should work fine.

_Aerospace_Eng_
01-21-2005, 08:52 AM
the post before this is correct u really dont want to use cm for a measure like what u want, since a screen resolution is in pixels, u can try using percentages or pixels, however if u want to use cm try this instead

<style type="text/css">
body { width : 10cm;overflow:auto;}
</style>

Tolstoy
01-21-2005, 08:57 AM
Many thanks to you both for your help.

I tried putting the units into px but it didn't work. I then tried specifying
p {width: 500px}
and it works just fine. I had expected the body to feed down to the p, but it doesn't. If that can't be fixed, at least I have a workaround.

Thanks again. It's appreciated,
Tolstoy

Jan
01-21-2005, 09:13 AM
Another way would be to put the text inside a container, and apply the width to it:


#container {
width: 500px;
}

and


<div id="container">
<p>Text comes here.</p>
</div>

Just a suggestion :D

Tolstoy
01-21-2005, 09:54 AM
Thanks.

I found a site that states that in IE 6 the CSS1 implementation is almost complete and that width doesn't always work correctly (http://www.nic.fi/~tapio1/Teaching/IE5_5.php3#IE60).
So I'm scuppered :mad:

Jan
01-21-2005, 10:12 AM
Thanks.

I found a site that states that in IE 6 the CSS1 implementation is almost complete and that width doesn't always work correctly (http://www.nic.fi/~tapio1/Teaching/IE5_5.php3#IE60).
So I'm scuppered :mad:

The article you are referring to only states that IE6 has some issues when applying width: 100% to the body. The example I posted earlier is just one of several methods that should work just fine.

Tolstoy
01-21-2005, 10:30 AM
Yes, using your suggestion fixes my width problem for me. Thanks :)
Specifying width to body in any units (not just %) doesn't seem to work.

Whilst the code you kindly provided works perfectly, I'm having other problems. In particular, I'm not getting :before to do what I expect it to.

h1.author:before {content : "Author: "}

I've tried copy-typing textbook examples, but I'm having no fun.

I really appreciate your answering noob questions like this. You've already saved me half a day.

Ta,
Tol

Jan
01-21-2005, 10:59 AM
I'm glad I can help! Concerning you're other problem, I'm not quite sure what you're trying to accomplish. I can however recommend you to take a look at W3Schools (http://www.w3schools.com/) and the CSS2 reference (http://www.w3schools.com/css/css_reference.asp) provided there. Hope this helps.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum