简体   繁体   English

CSS-使文本在响应图像上停留在同一位置

[英]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.

相关问题 使文本在响应图像中停留在相同位置 - Making text stay in same location in responsive image 带有重叠文字的自适应图像保持在同一位置 - Responsive Image With An Overlay Text Stay on The Same Position CSS / HTML使文本相对于图像大小调整保持相同的位置? - CSS/HTML make text stay the same position relative to an image resizing? 带有CSS动画悬挂键的响应式图像,应保持响应式就位 - Responsive image with CSS animated dangling key that should stay responsively in place 如何将按钮隐藏在图像文本后面,并使它们在所有设备上都位于同一位置? - How to hide buttons behind image text and make them stay in the same place across all devices? CSS,即使浏览器尺寸不同,背景图片也可以保留在原位 - CSS to make background image stay in place even with different browser size 如何使文字停留在图像下(响应式设计) - How to make text stay under an image (responsive design) 调整大小时如何使文本相对于图像保持在相同位置? - How to make text stay in the same position relative to an image when resizing? 有没有办法调整图像大小并让图像映射保持在同一个地方? (HTML / JavaScript的/ CSS) - is there a way to resize an image and have an image map stay in the same place? (html/Javascript/CSS) 弹出图像不在同一位置 - Popup image does not stay in same place
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM