【发布时间】:2020-06-30 00:59:14
【问题描述】:
我有以下 HTML/CSS
.main {
display: grid;
grid-template-columns: 2fr 1fr;
}
/* The following is not essential - for decoration purposes only */
.left {
background-color: green;
}
.right {
background-color: orange;
}
<div class="main">
<div class="left">Left</div>
<div class="right">Right</div>
</div>
现在,有时,取决于 div 和 main 类,有时我没有 div 和 right 类(换句话说,html 可能看起来像这样
.main {
display: grid;
grid-template-columns: 2fr 1fr;
}
/* The following is not essential - for decoration purposes only */
.left {
background-color: green;
}
.right {
background-color: orange;
}
<div class="main">
<div class="left">Left</div>
</div>
如果div.right 不存在,我喜欢以将div.left 扩展到容器div.main 的整个宽度的方式编写CSS 代码。我该怎么做?
【问题讨论】: