【发布时间】:2018-01-27 13:44:10
【问题描述】:
我知道有一百万个关于 div 差距的问题,但我似乎无法找到任何适合我的解决方案。我的网页目前如下所示:
图片横幅和文字之间有明显的差距。我想缩短它,使它看起来更像这样:
我很确定这是我的一个 div 的 CSS 问题,但我不确定是什么。如果有帮助,这是检查员的样子:
我尝试在我的 bootstrap.min.css 中创建一个新类,该类对 col-lg-12 div 和 row div 都没有顶部填充,但这并没有改变任何东西。我真的不确定从这里去哪里。
这是我的代码 (and here is the website in action on JSFiddle)。 (我只复制/粘贴了它的相关部分,因为整个代码很长。如果有任何代码错误或令人困惑,我深表歉意!)
<div class="intro-header-homepage">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="intro-message">
<h1>Website Homepage</h1>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class = "col-lg-6 col-lg-offset-3" text-align="center">
<p class="p-homepage">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</body>
CSS:
.p-homepage {
padding: 0px 0px 30px 0px;
font-weight: normal;
font-size: 18px;
}
.intro-header-homepage {
text-align: center;
color: #f8f8f8;
background: url(http://imgur.com/20qY3EH.jpg) no-repeat;
background-size: 100% 80%;
}
.intro-message {
padding-top: 20%;
padding-bottom: 20%;
}
【问题讨论】:
-
好像和
.intro-header-homepage的规则里你的background-size: 100% 80%;有关 -
是的 - 这是背景尺寸。更改为
background-size: cover。 -
div.intro-message有padding-top: 20%和padding-bottom: 20%; -
谢谢。有没有办法做到这一点,同时保持背景与使用
background-size: 100% 80%;所产生的高度相同?我不希望图像占据页面的一半。我尝试将行 div 更改为<div class = "row" style="height:300px;">但这并没有改变任何东西。 -
@JamesDouglas 我想保留它,因为我想保留“网站主页”文本和图像横幅顶部/底部之间的填充。
标签: html css twitter-bootstrap