我正在尝试使此布局响应。我遇到的问题就像图像在前景上。我已尝试过背景位置封面,但确实没有成功。我不应该使用任何javascript这个
以下是小提琴链接
HTML:
<div class="page-wrap">
<h1>Make This Responsive</h1>
<p>While maintaining the heirarchy of importance.</p>
<article class="main-story">
<img src="http://f.cl.ly/items/2e3c2a1Z0D1H3u0W2K12/shera.jpg" alt="Sha Ra Rocking" />
<div class="story-intro">
<h1>Most Important Story</h1>
<p>This article has the most visual weight. <a href="http://nebezial.deviantart.com/art/she-ra-115867096">image source.</a>
</p>
</div>
</article>
<section class="sub-stories">
<article class="sub-story">
<img src="http://placekitten.com/250/350" />
<div class="story-intro">
<h2>Less Important Story</h2>
<p>This story has less visual weight.</p>
</div>
</article>
<article class="sub-story">
<img src="http://placecage.com/250/350" />
<div class="story-intro">
<h2>Less Important Story</h2>
<p>This story has less visual weight.</p>
</div>
</article>
<article class="sub-story last">
<img src="http://placebear.com/250/350" />
<div class="story-intro">
<h2>Less Important Story</h2>
<p>This story has less visual weight.</p>
</div>
</article>
</section>
</div>
CSS:
* {
box-sizing: border-box;
}
.page-wrap {
width: auto;
margin: 20px auto;
}
.main-story {
position: relative;
margin: 0 0 25px 0;
}
img {
display: block;
max-width: 100%;
height: auto;
}
a {
color: lightblue;
}
.story-intro {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: rgba(0, 0, 0, 0.75);
padding: 20px;
color: white;
}
h1 {
font-size: 4em;
}
h1, h2 {
margin: 0 0 10px 0;
}
.story-intro h1 {
font-size: 2.5em;
}
.story-intro p {
margin: 0;
}
.sub-stories {
overflow: hidden;
margin: 0 0 25px 0;
}
.sub-story {
float: left;
width: 250px;
margin-right: 25px;
position: relative;
font-size: 80%;
}
.last {
margin-right: 0;
}
提前致谢..
答案 0 :(得分:3)
现在定义您的课程.main-story
img
此风格
.main-story > img{
width:100%;
}
答案 1 :(得分:0)
您需要在图像的容器中设置最大宽度,然后将图像宽度设置为100%。像这样
.sub-story {
float: left;
max-width: 250px;
margin-right: 25px;
position: relative;
font-size: 80%;
}
img {
width:100%;
}
答案 2 :(得分:0)
你好,你的意思是你想要设计流畅,没有反应, 一种解决方案是将宽度设置为百分比,如下所示:
http://jsfiddle.net/6jhx7du6/1/
.sub-stories {
overflow: hidden;
margin: 0 0 25px 0;
max-width:800px;
}
.sub-story {
float: left;
width: 31%;
margin-right: 3.5%;
position: relative;
font-size: 80%;
}
答案 3 :(得分:0)
为此,请添加.sub-story { width: x%;}
和.sub-story img { width: 100%;}
。
因此,图像将填充现在响应的.sub-story
。
您可以使用CSS中的 @media查询将.sub-story
的宽度调整为 33.33%或 50%或任何其他值
答案 4 :(得分:0)
Hey try this replace this css to your css code.
and after resizing you need change width and font size according to media queries.
JS Fiddle Link:
http://jsfiddle.net/abidkhanweb/r97d1w64/
* {
box-sizing: border-box;
}
.page-wrap {
width: auto;
margin: 20px auto;
}
.main-story {
position: relative;
margin: 0 0 25px 0;
}
img {
display: block;
max-width: 100%;
height: auto;
width:100%;
}
a {
color: lightblue;
}
.story-intro {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: rgba(0, 0, 0, 0.75);
padding: 20px;
color: white;
}
h1 {
font-size: 4em;
}
h1, h2 {
margin: 0 0 10px 0;
}
.story-intro h1 {
font-size: 2.5em;
}
.story-intro p {
margin: 0;
}
.sub-story img{
width:100%;
height:auto;
}
}
.sub-stories {
overflow: hidden;
margin: 0 0 25px 0;
}
.sub-story {
float: left;
width: 32%;
margin-right: 2%;
position: relative;
font-size: 80%;
}
.last {
margin-right: 0;
}