CSS Align all li items in single row

时间:2015-09-14 15:45:29

标签: html css

in li i have some element such as img and a and i want to align all of this items in single row. but i can not do that. for example you can see ONLINE DEMO

my html:

<div class="" id="menu_section">
    <ul id="menu">
        <li data-menuanchor="firstPage"><img src="imgs/verify.png"><a href="#firstPage">First Slide</a></li>
        <li data-menuanchor="secondPage"><a href="#secondPage">Second Slide</a></li>
    </ul>
</div>

my css:

#menu {
    direction: rtl;
    font-family: tahoma;
    font-size: 11px;
    white-space:nowrap;
}

#menu li {
    display: inline-block;
    float: right;
    margin: 10px;
    color: #000;
    background: #fff;
    background: rgba(255, 255, 255, 0.5);
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    border-radius: 2px;
}

#menu li.active {
    background: #666;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
}

#menu li a {
    text-decoration: none;
    color: #000;
}

#menu li.active a:hover {
    color: #000;
}

#menu li:hover {
    background: rgba(255, 255, 255, 0.8);
}

#menu li a,
#menu li.active a {
    padding: 9px 18px;
    display: block;
}

#menu li.active a {
    color: #fff;
}

#menu_section {
    position: fixed;
    top: 0;
    height: 58px;
    z-index: 70;
    width: 100%;
    padding: 0;
    margin: 0;
}

2 个答案:

答案 0 :(得分:0)

If all you want is to align them next to one another then float the li contents

#menu li > * {float: left;}

答案 1 :(得分:0)

You should set the a element to display inline-block instead of block if you want them to appear side by side. Img elements by default display inline so this shouldn't need to be set.

https://jsfiddle.net/0juxj7qn/1/

#menu li a,
#menu li.active a {
    padding: 9px 18px;
    display: inline-block;
}