margin-left失效

<div class="area clearfix">
   <div class="box"></div>
</div>
css
.area {
  width: 400px;
  height: 400px;
  background: red;
}
.area .box {
  width: 100px;
  height: 100px;
  background: green;
  float: right;
  margin-left:1000px
}
这里的margin-left为什么失效?因为右浮动的关系吗?
阅读 8.6k
3 个回答

右浮动用margin-right

CSS的float 属性可以使一个元素脱离正常的文档流,然后被安放到它所在容器的的左端或者右端,并且其他的文本和行内元素围绕它安放。

参考资料:float-CSS| MDN

float: right;
margin-left:1000px

the reason why this code doesn't work is that you can't combine "float:right and margin-left",target css code can write as below:

float:right
margin-right:-1000px

or

float:left
margin-left:-1000px

you can have a try

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题