html - 菜单 float 问题

标签 html css css-float

我尝试使用图像来描述我的问题。

*这是我喜欢的东西

enter image description here

*这是我得到的:

enter image description here

HTML

<div class="header">
    <ul class="menu">
        <li>Home</li>
        <li>Contant</li>
    </ul>
</div>
<div class="container>
    ....
</div>

CSS

    .header     {
        background: #77bbf5;
        width : 100px;
        height: 75px;
        line-height: 75px;
    }
    .menu   {
        float: left;
        list-style-type: none;
        background: #955d5d;
        position: absolute
    }
    .menu li    {
        display: inline;
        position: relative;
    }
    .menu li a {
        float: left;
        width: 35px;
        height: 35px;
        line-height: 35px;
        margin-left: 12px;
        margin-top: 50px;
        text-align: center;
        display: inline-block;
}

我试过了,试了又试了,请帮忙。

如何解决?

最佳答案

试试这个:

<div class="header">
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
</div>
<div class="container">
    ....
</div>  

CSS:

.header     {
    background: #32aaff;
    width : 400px;
    height: 75px;
    line-height: 75px;
}
ul   {
    width:300px;
    height:40px;
    list-style-type: none;
    background: #955d5d;
margin-top:50px;
    position:absolute;
    margin-left:30px;
}
ul li    {
    width:80px;
    height:30px;
    margin:10px;
    float:left;
    background: #d2d2d2;
}
ul li a {
    float: left;
    width: 35px;
    height: 35px;
    line-height: 35px;
    margin-left: 12px;

    text-align: center;
    display: inline-block;

}    
.container{
    width:400px;
    height:500px;
    background:#323232;
}

参见 Here

关于html - 菜单 float 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21672850/

相关文章:

javascript - 防止 div 中的元素随其余内容一起滚动

css - 保持基于 vw 的恒定 margin

html - CSS中的背景颜色问题

html - float 上的困惑。为什么设置第二个元素的宽度会影响 float ?

javascript - 无法使用 Javascript 编辑 CSS 样式

html - 如何仅将背景颜色添加到主要元素而不是 :before and :after

javascript - 单击文本以选中一个表列中的复选框

javascript - 单击触发器内的元素时如何防止 Bootstrap Modal 打开?

css - float 列表问题 : Removing Indentation

html - 左浮动元素未对齐