gpt4 book ai didi

css 背景颜色 child 不显示

转载 作者:行者123 更新时间:2023-11-28 02:30:08 27 4
gpt4 key购买 nike

我正在尝试响应式网格,但我无法让嵌套元素显示背景色。

我的 HTML 和 CSS 在这里:
https://jsfiddle.net/ro196bjr/9/

<body>  
<div class="grid-container">
<div class="row">
<div class="col-4 col-m-6 responsive-margin-bottom">
<div class="box primary">
<h1>Primary Box</h1>
<p>This is a paragraph</p>
</div>
</div> <!-- 25% -->
<div class="col-8 col-m-6">
<div class="box secondary">
<h1>Secondary Box</h1>
<p>This is a paragraph</p>
</div>
</div> <!-- 75% -->
</div>
</div>
</body>


* {
box-sizing: border-box;
}

body {
}

/*-------------Layout------------- */


#container {
}

/*----Grid---- */
.grid-container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}

/* For mobile phones: */
[class*="col-"] {
width: 100%;
float: left;
}

@media only screen and (min-width: 700px) {
/* For tablets: */
.col-m-1 {width: 8.33%;}
.col-m-2 {width: 16.66%;}
.col-m-3 {width: 25%;}
.col-m-4 {width: 33.33%;}
.col-m-5 {width: 41.66%;}
.col-m-6 {width: 50%;}
.col-m-7 {width: 58.33%;}
.col-m-8 {width: 66.66%;}
.col-m-9 {width: 75%;}
.col-m-10 {width: 83.33%;}
.col-m-11 {width: 91.66%;}
.col-m-12 {width: 100%;}
}

@media only screen and (min-width: 950px) {
/* For desktop: */
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
}

/*---- Box---- */

.box{
padding: 25px;
margin: 0 0 15px;
}

.box .primary{
color: #fff;
background-color: #74a57f;
}

.box .secondary{
color: #fff;
background-color: #077187;
}

我试过添加 overflow: auto;到网格容器,但这似乎没有帮助。有人知道我做错了什么吗?

干杯

最佳答案

.box 和.primary 之间不应有任何空格。中间有一个空格意味着 primary classbox class 的后代,但事实并非如此。它们都引用相同的容器类,因此删除它们之间的空格,您可以使用 .box.primary 或只是 .primary 以及相同的辅助标准。

.box.primary指的是同时具有box和primary类的容器。

.primary 指的是至少有primary class的容器。

* {
box-sizing: border-box;
}

body {
}

/*-------------Layout------------- */


#container {
}

/*----Grid---- */
.grid-container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}

/* For mobile phones: */
[class*="col-"] {
width: 100%;
float: left;
}

@media only screen and (min-width: 700px) {
/* For tablets: */
.col-m-1 {width: 8.33%;}
.col-m-2 {width: 16.66%;}
.col-m-3 {width: 25%;}
.col-m-4 {width: 33.33%;}
.col-m-5 {width: 41.66%;}
.col-m-6 {width: 50%;}
.col-m-7 {width: 58.33%;}
.col-m-8 {width: 66.66%;}
.col-m-9 {width: 75%;}
.col-m-10 {width: 83.33%;}
.col-m-11 {width: 91.66%;}
.col-m-12 {width: 100%;}
}

@media only screen and (min-width: 950px) {
/* For desktop: */
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
}

/*---- Box---- */

.box{
padding: 25px;
margin: 0 0 15px;
}

.box.primary{
color: #fff;
background-color: #74a57f;
}

.box.secondary{
color: #fff;
background-color: #077187;
}
<body>	
<div class="grid-container">
<div class="row">
<div class="col-4 col-m-6 responsive-margin-bottom">
<div class="box primary">
<h1>Primary Box</h1>
<p>This is a paragraph</p>
</div>
</div> <!-- 25% -->
<div class="col-8 col-m-6">
<div class="box secondary">
<h1>Secondary Box</h1>
<p>This is a paragraph</p>
</div>
</div> <!-- 75% -->
</div>
</div>
</body>

关于css 背景颜色 child 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47738140/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com