Forum Moderators: not2easy
Here is how the page looks in Dreamweaver (the way it should): <snip>
However, look at how IE shows it: <snip>
The same problem in Opera too: <snip>
My HTML is completely simple and innocent:
<body>
<div id="sidebar">
<p>Introduction</p>
<p>Text 1 </p>
<p>Text 2 <br>
Subtext 1 <br>
Subtext 2 </p>
</div>
</body>
</html>
My CSS style is also free of any specific settings. That's the external style sheet:
body {
font-family: Arial, Helvetica, sans-serif;
}
#sidebar {
background-color: #00CCFF;
border: dashed #CCCCCC;
font-size: small;
left: 5px;
top: 5px;
}
I really can't understand where that inserted space comes from--there aren't any spaces, returns, padding or something like that (just look at the code). The only option that is set is the positioning which concerns the whole layer (not what's inside it). I appreciate any help--this is really holding me back at the moment.
Thanks in advance!
[edited by: Woz at 8:21 am (utc) on June 24, 2005]
[edit reason] No URLs please, see Tos#13 [/edit]
padding:0;
margin:0;
or
padding-top:0px; padding-bottom:0px;
margin-top:0px; margin-bottom:0px;
?
Also you might want to Google for "Box Model" there are a series of problems, mostly with I.E., and fixes (well, hacks anyway) for it.
Also you should probably review the TOS you agreed to, welcome aboard! :-)
clear the margins on the <p> text:
body{
font-family: Arial, Helvetica, sans-serif;
}
#sidebar{
background-color: #00CCFF;
border: dashed #CCCCCC;
font-size: small;
left: 5px;
top: 5px;
}
p{
margin-top: 0;
margin-bottom: 0;
}
Then add a couple of <br> to the html:
<div id="sidebar">
<p>Introduction</p>
<p><br>
Text 1 </p>
<p><br>
Text 2 <br>
Subtext 1 <br>
Subtext 2 </p>
</div>
This should be looking how you want. I'm guessing you have used the top/left properties to get a centered look on the div, with a couple of tweaks to the CSS this can be done by default:
Add text-align:center; to the body - any text/ containers etc will be center aligned.
body{
font-family: Arial, Helvetica, sans-serif;
text-align: center;
}
Add text-align:left; to the sidebar div, if not the text will center from the body.
#sidebar{
background-color: #00CCFF;
border: dashed #CCCCCC;
font-size: small;
text-align: left;
}
Hope this helps..
Thanks once again!
Great community here!
* {margin:0;padding:0;}
Also you can use short-hand for padding and margins.
instead of this,
body {margin-top:10px;margin-right:8px;margin-bottom:0;margin-left:6px;}
You can do this,
body {margin:10px 8px 0 6px;}
One of the best things you can do is use the universal selector (*) to set the padding and margins of all your elements at the begining of your style sheet.
Margin, yes, but there are issues with doing the same for padding which only become apparent later on. Such as Mozilla using padding in the <option> element for default positioning. To get <select>s to display properly you have to feed this padding back to *Mozilla only*.
Better to go for something like:
* {
margin: 0;
}
body, fieldset, legend, ol, ul, th, td {
padding: 0;
}