我有一些div用PHP生成的s,我希望divs 的宽度是偶数(即2 = 50%,3 = 33%,4 = 25%等),无论有多少divs.
我想用CSS做到这一点,有可能吗?
.container {
margin: 10px 0;
width: 100%;
}
.container div {
height: 50px;
}
.container div:nth-child(odd) {
background-color: red;
}
.container div:nth-child(even) {
background-color: blue;
}
.twoColumns,
.threeColumns,
.fourColumns {
height: 50px;
}
.twoColumns div,
.threeColumns div,
.fourColumns div {
float: left;
}
.twoColumns div {
width: 50%;
}
.threeColumns div {
width: 33.333333333%;
}
.fourColumns div {
width: 25%;
}Run Code Online (Sandbox Code Playgroud)
<div>
<h1>Example markup</h1>
<strong>This …Run Code Online (Sandbox Code Playgroud)