css - 上线 float

标签 css html

我想要在我的网站的上部有一个全屏栏,在左侧和右侧有一个列表(任何元素)。为什么这不起作用?

#upperline{
background:brown;
width:100%;}

#upperline ul{
float:left;}

#upperline p{
float:right;}


<div id="upperline">

    <ul>
        <li>our team</li>
        <li>help</li>
        <li>contact</li>
    </ul>
    <p>log in</p>

</div>

我很困惑

最佳答案

在 float 元素的父元素上放置一个overflow:hidden; 以使其工作

See it here

#upperline{
background:brown;
width:100%;
overflow: hidden;}

来自 this post并适应你的情况:

div is a block-level element (they stretch to 100% of the parent width).

Now in your example the div contains only floated elements. This makes it collapse to a height of 0px (It still has 100% width though as you can see in the example).

Now declaring overflow (any value other than visible) establishes a new block formatting context, which makes the div contains its children. Suddenly the div "reappears", not having size 0px anymore.

关于css - 上线 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36505430/

相关文章:

javascript - 使用这个经过 CSS 转换的翻盖卡片,我怎样才能让背面的内容易于访问?

html - 如何在TD元素中垂直对齐图像和文本?

javascript - 多种预定义样式或动态更改内联样式?

javascript - 为什么不能删除EventListener

javascript - PreventDefault() 不适用于图像链接

html - 过滤器 :Alpha(opacity=50) doesn't pass CSS validation

css - 即使没有设置清除属性,Div 也会清除 float

css - 条件注释 ie7 不工作

javascript - 在 Jquery 库中选择一个特定的标签

javascript - 我应该采用哪种圆 Angular 方法?