Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing unecessary margins and adjusting height with CSS

Tags:

html

css

There are two issues that I'm trying to fix, but can't find a solution

The first one is that the space between the li fields is way wider than the 2px than it should be. How do I remove it?

And other is that the a fields are only as high as the text, although the field height is defined to be 50px.

I also have the normalize.css file enabled from GitHub.

Any suggestions?

HTML

<nav class="nav-box">
    <div class="row">
        <ul class="main-nav">
            <li><a href="#">YES</a></li>
            <li><a href="#">NO</a></li>
        </ul>
    </div>
</nav>

CSS

.row {
    max-width: 1140px;
    margin: 0 auto;
}
.nav-box {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    box-shadow: 0 2px 2px #f2f2f2;
    min-height: 65px;
}
.main-nav {
    float: right;
    margin-top: 7px;
}
.main-nav li {
    list-style: none;
    display: inline-block;
    font-size: 100%;
}
.main-nav li a {
    height: 50px;
    background-color: #ee4723;
    padding: 0 18px 0 18px;
    font-size: 1.4rem;
    color: #fff;
    font-family:'Oswald', sans-serif;
    border:solid #fff;
    border-width: 0 1px 1px 0;
    line-height: 54px;
}

Here's a fiddle.

like image 766
TacoCat Avatar asked Jun 01 '15 17:06

TacoCat


1 Answers

For the spacing issue

This is an issue with inline-block elements (extra spacing appears between two such elements). One way to solve this is to give the parent element (in this case <ul>) font-size of 0 and then setting the font-size of the <li> element explicitly. There are other ways like negative margin but I find font-size: 0 method to be the most convenient. You can read about other methods here https://css-tricks.com/fighting-the-space-between-inline-block-elements/

For the height issue

While you have given the inline-block property to the <li> elements, the child <a> elements are still inline. Attributes such as height and width would have no effect on inline elements. Add display: inline-block to the <a> element as well for the desired effect

like image 107
Rahul Nanwani Avatar answered Sep 21 '22 12:09

Rahul Nanwani