【发布时间】:2017-12-17 12:17:34
【问题描述】:
我检查了相关帖子的答案,但它们没有帮助。我想让文本居中在响应式背景图像之上 - 仅在可能的情况下使用 CSS。
/*beginning of styling for background img per smashing mag article*/
.hero {
position: relative;
}
.hero #page1img {
width: 100%;
display: inline-block;
vertical-align: middle;
font: 0/0 serif;
text-shadow: none;
color: transparent;
background-size: 100%;
background-position: 50% 50%;
background-repeat: no-repeat;
}
.hero #page1img .inner {
padding-top: 64.700855%; /* 757px h divided by 1170w width/height of image */
display: block;
height: 0;
}
/*end of styling for background img per smashing mag article*/
h3 .intro-lead-in {
padding-top: 100px;
text-align: center;
font-family: 'Josefin Slab', serif;
font-style: italic;
font-size: 22px;
}
h1 .intro-heading {
display: inline-block;
text-align: center;
font-family: 'Spinnaker', sans-serif;
text-transform: uppercase;
font-weight: 700;
font-size: 50px;
}
/* beginning of media queries for background image per smashing mag article*/
/* default screen, non-retina */
.hero #page1img { background-image: url("https://s9.postimg.org/6c1bhr9u7/header-970px-wide.jpg"); }
@media only screen and (min-width: 321px) and (max-width: 538px) {
/* Medium screen, non-retina */
.hero #page1img { background-image: url("../img/header-538px-wide.jpg"); }
}
@media only screen and (max-width: 320px) {
/* Small screen, non-retina */
.hero #page1img { background-image: url("../img/header-290px-wide.jpg"); }
}
/* end of media queries for background image per smashing mag article*/
<div class= "row">
<div class= "col-12">
<div class="hero">
<h3 class="intro-lead-in">Welcome to our Club!</h3>
<h1 class="intro-heading">It's Nice to Meet You</h1>
<span id="page1img" aria-label="MacGregor boats">
<span class="inner"></span>
方法取自 Stephen Thomas 在 Smashing Magazine 上的文章。 此处实现/工作的文章演示:http://sathomas.me/continental/
这是我的第一个问题,如果我没有把它发布得非常正确,敬请见谅。欢迎提出改进建议!
【问题讨论】:
-
你能给我们看一些代码吗?
-
HI Moses 刚刚将我的代码添加为代码片段
标签: html css image responsive