yanabeca yanabeca - 5 months ago 8
CSS Question

How do I margin a div as much as another?

I want my holder to not to overlap with my navbar, can I set holder's margin-top to be exactly as much as my navbar without putting in numbers?

Here's the html,



#navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: grey;
position: fixed;
top: 0;
width: 100%;
}
#holder {
min-height: 100%;
background-color: #F7F4EE;
position: relative;
}

<div>
<ul ID="navbar">
<li><a class="active" href="home.html">Home</a>
</li>
<li><a href="news.html">News</a>
</li>
<li><a href="about.html">About</a>
</li>
</ul>
</div>

<div id="holder">
<header>""</header>
<div id="body">""</div>
<footer>""</footer>
</div>





Thanks.

Answer

try to use this

margin: 0 auto;

and for addition, you can use this

display: block;
margin: 0 auto;

remember to put it on css so it become like this

#navbar {
    list-style-type: none;
    margin: 0;
    padding:0;
    overflow: hidden;
    background-color: grey;
    position: fixed;
    top: 0;
    width: 100%;
    display: block;
    margin: 0 auto;
}

#holder {
    min-height: 100%;
    background-color: #F7F4EE;
    position: relative;
    display: block;
    margin: 0 auto;
}
Comments