[英]CSS left and rghtDiv not aligning to left and right but top and bottom
My css and html looks like below.我的 css 和 html 如下所示。 mRow is the main div and within that is my mRowLeft and mRowRight.
mRow 是主要的 div,其中是我的 mRowLeft 和 mRowRight。 However instead of left and right I see them appear top left and bottom right.
但是,我看到它们出现在左上角和右下角,而不是左右。
div.mRow {
padding: 2px 25px 2px 0;
margin-top: 4px;
margin-bottom: 3px;
float: left;
text-align:left;
width: 350px;
/*border:1px solid green;*/
}
.mRowLeft {
padding: 2px 25px 2px 0;
margin-top: 4px;
margin-bottom: 3px;
float: left;
text-align:left;
width: 48%;
/*border:1px solid green;*/
}
.mRowRight {
padding: 2px 25px 2px 0;
margin-top: 4px;
margin-bottom: 3px;
float: right;
text-align:left;
width: 48%;
/*border:1px solid green;*/
}
///....
<div class="mRow">
<div class="mRowLeft"></div> --label
<div class="mRowLeft"></div> --10rows
<div class="mRowRight"></div> --label
<div class="mRowRight"></div> --10rows
</div>
...//
.mRow { display:flex; justify-content:space-around; }
<div class="mRow"> <div class="mRowLeft"> dfsf <div class="mRowLeft">sdfvs</div> </div> <div class="mRowRight"> sdfs <div class="mRowRight">sdfsd</div> </div> </div>
You should be putting your label and content under the same left/right div.您应该将 label 和内容放在相同的左/右 div 下。
<div class="mRow">
<div class="mRowLeft">
<div>--label</div>
<div>10rows</div>
</div>
<div class="mRowRight">
<div>label</div>
<div>10rows</div>
</div>
</div>
Then you can either use inline-blocks:然后你可以使用内联块:
.mRow {
white-space: nowrap;
width: 350px;
}
.mRowLeft,
.mRowRight {
display: inline-block;
white-space: normal;
width: 50%;
}
or use flexbox:或使用 flexbox:
.mRow {
display: flex;
flex-direction: row;
width: 350px;
}
.mRowLeft,
.mRowRight {
width: 50%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.