码迷,mamicode.com
首页 > Web开发 > 详细

css浮动元素居中,右边宽固定而左边宽自适应

时间:2017-04-18 16:02:31      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:浮动   nbsp   ack   div   position   black   lock   inline   html   

   1、浮动元素居中

   固定宽高的情况下:

width:200px;
height: 200px;
position: absolute;
left:50%;
top:50%;
margin-left: -100px;
margin-top: -100px;

未知宽高的情况下:
width:200px;
height: 200px;
position: absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);

2、右边宽固定,左边宽自适应
html:
<div class="all">
<div class="left"></div>
<div class="right"></div>
</div>
css:
.all{
display: flex;
}
.left,.right{
height: 2px;
display: inline-block;
}
.right{
width:200px;
background: red;
}
.left{
width:calc(100% - 200px);
background: black;
}

css浮动元素居中,右边宽固定而左边宽自适应

标签:浮动   nbsp   ack   div   position   black   lock   inline   html   

原文地址:http://www.cnblogs.com/LingZi-0214/p/6727888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!