html - 仅使用 Css 将 Logo 向左浮动

标签 html css

我想让我的导航栏看起来像这样 enter image description here

但到目前为止,这就是我到目前为止所做的,当我尝试将 Logo float 到左侧时,标题背景消失了。我很困惑为什么会这样?

*{margin: 0;padding: 0;}
img, fieldset{border: 0; }
img{vertical-align: middle}
h1,h2,h3,h4,h5,h6{font-weight: normal;}

.site-body, .site-header-outer, .site-header, .tag{
  width: 58.7em;
  margin:auto;
}

*{margin: 0;padding: 0;}
img, fieldset{border: 0; }
img{vertical-align: middle;}
h1,h2,h3,h4,h5,h6{font-weight: normal;}

.site{
  width: 58.7em;
  margin:auto;
}

/*Header*/
.header{
  background-color:#3088f0;
}

.Logo{
  background-color: #f07a30;
  float: left;
  color: #ffffff;
}
<!DOCTYPE HTML5>    
<html>
  <head>
    <title>The Title</title>

    <link href="css/stylesheet.css" rel="stylesheet">
  </head>    
  <body>
    <div class="site">
      <h1>
        <div class="header">
          <div class="Logo">Vatpaints.tk</div>

        </div>
      </h1>    
      <div class="navigation"></div>
      <div class="content"></div>
      <div class="footer"></div>
    </div>
  </body>    
</html>

最佳答案

当使用 overflow:hidden; 时,还可以考虑添加 width: 100%;。对于某些浏览器,没有宽度的解决方案不起作用。

您的问题的另一个解决方案是清除 float 。您可以通过添加一个 html 元素作为元素在其中 float 的容器的最后一个子元素来实现。通过添加 style="clear: both;" 作为最后一个子项的属性,使用内联 CSS 清除 float ,或者更好地使用 css 类。

使用内联 CSS

<div class="header">
    <div class="Logo">Vatpaints.tk</div>
    <div style="clear: left;"></div>
</div>

使用 CSS 类

<style>
    .clear{
        clear: left;
        /* clear: right; */
        /* clear: both; */
    }
</style>

<div class="header">
    <div class="Logo">Vatpaints.tk</div>
    <div class="clear"></div>
</div>

关于html - 仅使用 Css 将 Logo 向左浮动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31053637/

相关文章:

html - flex-grow 在列布局中不起作用

javascript - 让用户调整 div 容器的大小,页面刷新后保存

HTML 边框 float 中心位置固定

css - Safari 中的边距与 Chrome 和 Firefox 中的边距截然不同

javascript - 如何防止用户在html中提交虚假的datalist值?

javascript - 左 div 容器作为链接/导航,单击链接后,在右 div 容器中显示内容?

css - 仅将 img hover 应用于某张图片?

html - 在网格中分隔 Bootstrap Div

html - Angular .js "typeError: V2.example is not a function"错误

javascript - 使用表单输入访问相机并使用网络应用程序立即上传照片