Geek Answers Handbook
Why do the <p> and <h1> elements cause spaces in my layout?
If I have the following html:
<body>
<div id="mainTop">
</div>
<div id="main">
<h2>
<%= Html.Encode(ViewData["Message"]) %></h2>
<p>
To learn more about ASP.NET MVC visit
http://asp.net/mvc</a>.
</p>
</div>
<div id="mainBottom">
</div>
</body>
With the following CSS:
#mainTop
{
background: url('/Content/Images/bg_top.png') no-repeat;
width: 963px;
height: 65px;
margin: 0 auto;
text-align: left;
color: #5d676d;
}
#main
{
background: url('/Content/Images/bg_middle.png') repeat-y;
width: 963px;
min-height: 50px;
margin: 0 auto;
}
#mainBottom
{
background: url('/Content/Images/bg_bottom2.png') no-repeat;
width: 963px;
height: 128px;
margin: 0 auto;
}
It looks like this:

Why do some tags, such as <p> and header tags, cause spaces in my layout? Ideally, I would not want to have these huge spaces between my content.
+5
6 answers
By default, <p>and <h2>(among others) have fields and gaskets associated with them. Try adding the following to your CSS:
p, h2 {
margin: 0px;
padding: 0px;
}
If the filling does not affect the border and background of the elements, but depending on what you want, you can try deleting them, as well as I am here.
: Guffa , , DIVs, .
+17
All Articles