3 回答
TA贡献1890条经验 获得超9个赞
您必须float向选择器添加属性container2。请检查下面的 CSS 规则。
.container2 {
float: left;
position: relative;
width: 250px;
}
TA贡献1802条经验 获得超10个赞
.container {
width: 400px;
height: 400px;
padding: 0px;
display: grid;
grid-template-columns: auto auto auto;
}
.item {
width: 100px;
height: 200px;
margin: 2px;
}
<div class="container">
<div class="item" style="background-color:red">
</div>
<div class="item" style="background-color:blue">
</div>
<div class="item" style="background-color:yellow">
</div>
</div>
为什么不网格显示属性?
TA贡献1802条经验 获得超5个赞
对于这些这样的场景,有一个美丽/干净/简单的概念,flex它可以通过减少代码行数来提供帮助:
column这是,color和效果的示例hover,希望对您有所帮助:
#MainDiv {
height: 200px;
width: 650px;
display: flex;
/* here is a concept */
flex-direction: row;
/* you can either change it to row/columns */
padding: 5px;
}
#firstDiv {
width: 200px;
margin: 5px;
background-color: red;
}
#secondDiv {
width: 200px;
margin: 5px;
background-color: blue;
}
#thirdDiv {
width: 200px;
margin: 5px;
background-color: green;
}
#firstDiv:hover {
background-color: blue;
color: white;
}
#secondDiv:hover {
background-color: green;
color: white;
}
#thirdDiv:hover {
background-color: red;
color: white;
}
<div id="MainDiv">
<div id="firstDiv">First Div</div>
<div id="secondDiv">Second Div</div>
<div id="thirdDiv">Third Div</div>
</div>
- 3 回答
- 0 关注
- 103 浏览
添加回答
举报