[英]CSS - make text stay on same place on responsive image
I'm trying to make text stay on same place on responsive image. 我正在尝试使文本在响应图像上停留在同一位置。
The HTML I have is: 我拥有的HTML是:
<div class="container">
<img src="http://i.imgur.com/K6XP6tp.png" alt="">
<div class="counter">
<span class="days">1</span>
<span>2</span>
<span>3</span>
</div>
<div class="counter2">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
</div>
The CSS: CSS:
.container {
position: relative;
}
.container img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: auto;
}
.days {
position: absolute;
top: 30%;
left: 50%;
}
.counter span {
font-size: 25px;
}
cannot make this work. 无法完成这项工作。 I created a jsfiddle .
我创建了一个jsfiddle 。 Any ideas how to make this work?
任何想法如何使这项工作?
You should do this from an image within the flux, so it allows it's container (here body) to grow. 您应该从通量内的图像中执行此操作,以便它可以使容器(在此为主体)生长。
then your 30% comes efficient (25% used inthe snippet below). 那么您的30%就会变得有效(下面的代码段中使用了25%)。 :):
:):
.container { position: relative; } .container img { display: block; width: 100%; } .days {/* other spans to position through coordonates as well */ position: absolute; top: 25%; left: 50%; } [class*="counter"] span { font-size: 25px; position: absolute; }
<div class="container"> <img src="http://i.imgur.com/K6XP6tp.png" alt=""> <div class="counter"> <span class="days">1</span> <span>2</span> <span>3</span> </div> <div class="counter2"> <span>1</span> <span>2</span> <span>3</span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.