【发布时间】:2016-02-20 23:01:14
【问题描述】:
我是 css 的初学者,我正在尝试仅使用 css 创建一个英雄横幅并使其具有响应性,如果我缩放页面或将其缩小,文本不响应。
<header class="main-header">
<img src="imgs/header.jpg"/>
<div class="title">
<h1>This is a title</h1>
<p>some texts here</p>
</div>
</header>
css:
.main-header img {
max-width: 100%;
margin: 0 auto;
position: relative;
}
.title {
position: relative;
top: -450px;
left: 10%;
text-align: center;
display: inline-block;
color: white;
margin: 0 auto;
width: 80%;
text-transform: uppercase;
}
.title h1 {
font-size: 2.7rem;
font-weight: 700;
margin: 0 auto;
width: 80%;
margin-bottom: 1.5%;
}
.title p {
font-size: .60rem;
width: 33%;
margin: 0 auto;
line-height: 1.8;
}
是否甚至可以仅使用 css 创建英雄横幅?因为我看不到任何教程..
【问题讨论】:
-
你能把这个和你的图片放在jsfiddle.net吗?
-
在您的示例中,背景图像使用的常见模式是将图像分配给包装容器 .main-header 的 baground。然后文本将在背景图像的前面,即使没有绝对定位。
-
当我把它作为背景图片时它不会出现..
-
我不完全理解你想要达到的目标。是不是图不行?没有的文字?两个都?如果您可以提供一个目标结果的示例,只要演示一下它现在的样子,那就更容易了(查看如何创建minimal reproducible example)。
-
它是顶部的图像不起作用......如果我放大或缩小浏览器,它们就会消失图像
标签: javascript jquery html css banner