css - 两个行块宽度50%却不在同一行
本文介绍了css - 两个行块宽度50%却不在同一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
padding:0;
margin: 0;
border: none;
}
.wrapper {
width: 500px;
overflow: hidden;
background-color: grey;
}
.cell {
display: inline-block;
width: 50%;
}
.left {
background-color: red;
}
.right{
background-color: blue;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="cell left">left</div>
<div class="cell right">right</div>
</div>
</body>
</html>
直觉认为红块和蓝块应该是在同一行,然而并不是
设置float:left
属性后两块并排了,width:49%
也并排了,width:250px
还是两排。造成这个问题的关键点在哪?
解决方案
在于 两个子div之间有一个 空白文本节点!去掉后就好了
<div class="cell left">left</div><div class="cell right">right</div>
或者
<div class="cell left">left</div><!--
--><div class="cell right">right</div>
这篇关于css - 两个行块宽度50%却不在同一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文