【发布时间】:2017-11-14 18:35:14
【问题描述】:
我来这里是为了知道我的代码哪里出了问题,我是 HTML/CSS 新手,正在尝试使用 Google 但没有运气。
问题:
- 无法根据需要放置图像和文本。
- 当我使用媒体查询时,图像不会自动替换为移动版本。
- 移动设备的断点约为 819 像素及以下。
这是我的代码
.main-wrapper {
max-width: 1300px;
}
img {
max-width: 100%;
}
.banner-container {
padding: 150px 0;
background-repeat: no-repeat !important;
background-size: cover;
background-position: center right !important;
.banner-content {
color: #3A1F17;
}
}
@media (max-width: 819px) {
.banner-container {
background-image: url("https://serving.photos.photobox.com/00758490381c3770325173d6abe930e9148d8f0582ad2407e9e775d8fe03b471331704e1.jpg") !important;
}
.banner-content {
text-align: center;
}
}
<div class='main-wrapper'>
<div class="banner-container" style="background: url('https://serving.photos.photobox.com/65771836f3f64d3b55f2ce69b7a8e93c69a822788f766366b80f47332a7b4c69dc47e4ef.jpg')">
<div class="banner-content">
<h1>Auto-Delivery</h1>
<p>NEVER RUN OUT OF YOUR FAVORITE MOROCCANOIL <br>PRODUCTS AGAIN.</p>
</div>
</div>
</div>
我的最终设计应该是这样的:
台式机:
对于移动设备:
【问题讨论】:
-
请编辑您的问题以在此处也包含代码。外部链接可能会随着时间的推移而改变或消失,然后在将来这个问题可能没有意义。您还可以在这个问题中制作一个可运行的 StackSnippet,而无需像 JSFiddle 这样的外部站点来制作演示。见stackoverflow.com/help/how-to-ask