我正在努力使我的角色回应中心.但是我无法设置宽度
<div class="wrapper"> <div class="container"> <div class="left box">Content</div> <div class="right box">Content</div> </div> </div> .wrapper {text-align:center} .container {width:100%; margin: 10px auto} .left {width:69%;max-width:350px; background:blue} .right {width:29%;max-width:150px; background:red} .box {float:left;padding:20px}
我如何保持容器在中间?
解决方法
Flexbox甚至可以中心漂浮的孩子!
所以我可以简单地添加display:flex和justify-content:center;到容器
.container { margin: 10px auto; display:flex; justify-content: center; /* align horizontal */ }
Browser support这几天也不错
.wrapper { width: 100%; text-align: center } .container { margin: 10px auto; display: flex; justify-content: center; /* align horizontal */ } .left { width: 69%; max-width: 350px; background: blue } .right { width: 29%; max-width: 150px; background: red } .box { float: left; padding: 20px }
<div class="wrapper"> <div class="container"> <div class="left box">Content</div> <div class="right box">Content</div> </div> </div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。