html - 右浮动不起作用

标签 html css

您好,我只是想知道为什么我的 css float:right; 不起作用?

我创建了这个 DEMO 来自 codepen.io

在此演示中,您可以看到有一个红色的 div (.hm)。这个 div 应该在右 Angular ,但它向左浮动。有什么问题有人可以在这方面帮助我吗?

CSS

.header {
  position:fixed;
  width:100%;
  padding:20px 0px;
  box-sizing:border-box;
  border-bottom: 1px solid #dbdbdb;
  background-color:#ffffff; 
}
.header_in {
    position: relative;
    width: 100%;
    max-width: 1000px;
    margin: 0px auto;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -webkit-flex-direction: row;
    -ms-flex-direction: row;
    flex-direction: row;
    -webkit-box-align: stretch;
    -webkit-align-items: stretch;
    -ms-flex-align: stretch;
    align-items: stretch;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
}
.smatLogo {
  position:relative;
  float:left;   
  width:40px;
  height:40px;
   background-color:blue;
}
.smatLogo img {
  width:100%;   
}

.hm {
  float:right;
  position:relative;
  height:40px;
  width:100%;
  max-width:200px;
   background-color:red;
}

.mn {
  float:left;
  width:calc(100%/3 - 1px);
  width: -webkit-calc(100%/3 - 1px);
  width: -mox-calc(100%/3 - 1px);
  height:40px;  
}

.notif {
  width:100%;
  height:40px;
}

.exp{
  width:100%;
  height:40px;  
}

.user{
  width:100%;
  height:40px;
}

最佳答案

这是因为为 .header_in 类设置了 display:flex; 属性。 这就是 flex 对象的正确行为。

所以现在您的选择仍然是不使用 flex 属性,或者如果您需要 flexbox 的属性,那么您可以使用下面给出的解决方案。

为了解决这个问题,您必须对 .hm 类使用 margin-left: auto;

DEMO

注意:这也可以使用 tables 来完成,但稍后相同的 table 会回来咬你:D

关于html - 右浮动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37321940/

相关文章:

html - 使高度为页面的 100%?

html - 尝试将网站链接到我的样式表

html - 如何在CSS中制作底部完整的圆圈

javascript - 未显示警报之前的 HTML

html - 进行更改时 AngularJS 列表不更新

html - Bootstrap竖写

asp.net-mvc - 如何修改详情 View

javascript - 在 Firefox 中禁用滚轮更改数字和日期输入

html - 调整大小时,菜单栏会折叠,一半的选项显示在其他选项下方的一行中

html - 如何显示嵌入我网站的 Google 搜索结果?