我对编码很陌生,但即使我知道如何在
div
中设置背景颜色,但出于某种原因,我无法使用以下代码来完成:
<div class="text-center">
<h1>Welcome to Ika Ika Surf Camp Tenerife.</h1>
<h4>A NEW CONCEPT OF SURF CAMP AND SURF SCHOOL IN THE CENTER OF PLAYA DE LAS AMERICAS, TENERIFE</h4>
<div class="col-lg-4">
<h3>Surf School</h3> <img alt="surf-school" src="img/ika-ika-guias-surf.jpg">
<p>Our surf lessons are taught by our fully qualified instructors with extensive surfing experience.</p>
</div>
<div class="col-lg-4">
<h3>Surf Guides</h3> <img alt="surf-guides" src="img/ikaika-surf-school-tenerife.jpg">
<p>The surf camp is located in the center of Playa de las Americas, 50m of the best waves of the island.</p>
</div>
<div class="col-lg-4">
<h3>Surf School</h3> <img alt="activities" src="img/tenerife-actividades-skate.jpg">
<p>Ika Ika Surf camp is a 360º Sport center with Skate, Long Skate, Scuba, Yoga Surf, Pilates and Surf workout.</p>
</div>
</div>
所以在 css 中,如果我设置下面的代码,它只会影响 h1
和 h4
出于某种原因
div.text-center {
background-color:
}
尽管如果我从父级中删除 .text-center 类 div
,它会影响所有子 div
的
希望有人能解释我为什么。我想这与引导程序有关——这是我第一次尝试使用它进行编码。
原文由 vlad 发布,翻译遵循 CC BY-SA 4.0 许可协议
1)父块丢失了它的浮动子块
在宽屏上,Bootstrap 的列会浮动。因此,父块决定它只有两个标题。它的高度变小了。
这个问题有两个解决方案:
1.1)溢出
您可以将
.text-center
类的overflow
属性设置为hidden
。此属性使父块采用考虑其浮动子块的尺寸。1.2) 清除修复
Bootstrap 行使用此方法。您可以在 bootstrap.css 中看到它:
因此,您必须使用
.row
类将列包装到块中:2)容器>行>列
Bootstrap 的 网格系统 涉及块的层次结构。容器包含行,行包含列:
此外,
.row
类的边距为负。如果你不把它放入容器中,那么水平滚动条就会出现在你的页面上。3)不要改变
.text-center
类它是 Bootstrap 的 对齐类 之一。
您可以根据自己的目的定义自己的类。就像我在下面的代码中定义了
.my-background
类一样。请检查结果。这是你想要达到的目标吗?