![](/img/trans.png)
[英]How to place a text as a overlay on a image vertically aligned to top left in a div
[英]How to place <span overlay text vertically over an image?
我在页面中有一些相互下方的图像,并希望在图像上垂直而不是水平添加跨度覆盖文本。我当前的代码水平显示(在 iPhone 屏幕上)跨度覆盖文本,但我想垂直显示它并从中读取自下而上。希望你们帮助我。 谢谢
<html>
<head>
<style>
</style>
<script>
//here I get the items information from db using ajax method and construct the item information blocks and append it to div called demo
</script>
</head>
<body>
<div id="demo">
<strong>1)Item 1</strong><br>
<div style="text-align: right;">70<br> </div>
<div style="position: relative; z-index: 1;">
<img src="https://assets.adidas.com/images/w_840,h_840,f_auto,q_auto:sensitive,fl_lossy/8e2d81eb3e854642b5dca97600fd73c7_9366/Firebird_Track_Pants_Black_ED6897_25_model.jpg" height="768" width="980" alt="Flower" style="position: absolute; z-index: 2;"> </div>
<span id="overlay_text" style="position: relative; top: -10px; z-index: 3;background-color:white;line-height:50px">SOLD OUT</span>
<br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br>
<a href="https://www.mywebsite.com/item1.html">https://www.mywebsite.com/item1.html</a>
<br>Available Sizes:XS,S,M,L,XL,2XL
<br>------------------------------------------------------------------------------------<br>
<strong>2)Item 2</strong><br>
<div style="text-align: right;">65<br> </div>
<div style="position: relative; z-index: 1;">
<img src="https://assets.adidas.com/images/w_840,h_840,f_auto,q_auto:sensitive,fl_lossy/bf500e3fd9c74e458cf4aaf00125990a_9366/Firebird_Track_Pants_Blue_FM3813_01_laydown.jpg" height="768" width="980" alt="Flower" style="position: absolute; z-index: 2;">
<span id="overlay_text" style="position: relative; top: -10px; z-index: 3;background-color:white;line-height:50px"></span></div>
<br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br>
<a href="https://www.mywebsite.com/item2.html">https://www.mywebsite.com/item2.html</a>
<br>Available Sizes:XS,S,M,L,XL,2XL
<br>------------------------------------------------------------------------------------<br>
</body>
</html>
Css 变换Css 变换和变换原点不会伤害任何一个变换原点这里是一个简单的例子。
.wrapper{ height: 500px; width: 500px; position:relative; background: rgb(220,220,220); }.wrapper span{ position:absolute; top:100px; left: 20px; font-size: 20px; font-weight: bold; /*important part below*/ transform: rotate(-90deg); transform-origin: top left; }
<div class="wrapper"> <span>Sold Out</span> </div>
因此,使用您的代码将类似于:
<html> <head> <style> </style> <script> //here I get the items information from db using ajax method and construct the item information blocks and append it to div called demo </script> </head> <body> <div id="demo"> <strong>1)Item 1</strong><br> <div style="text-align: right;">70<br> </div> <div style="position: relative; z-index: 1;"> <img src="https://assets.adidas.com/images/w_840,h_840,f_auto,q_auto:sensitive,fl_lossy/8e2d81eb3e854642b5dca97600fd73c7_9366/Firebird_Track_Pants_Black_ED6897_25_model.jpg" height="768" width="980" alt="Flower" style="position: absolute; z-index: 2;"> </div> <span id="overlay_text" style="position: relative; z-index: 3;background-color:white;transform: rotate(-90deg); transform-origin: top left; display:inline-block; top: 100px;left: 10px">SOLD OUT</span> <br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br> <a href="https://www.mywebsite.com/item1.html">https://www.mywebsite.com/item1.html</a> <br>Available Sizes:XS,S,M,L,XL,2XL <br>------------------------------------------------------------------------------------<br> <strong>2)Item 2</strong><br> <div style="text-align: right;">65<br> </div> <div style="position: relative; z-index: 1;"> <img src="https://assets.adidas.com/images/w_840,h_840,f_auto,q_auto:sensitive,fl_lossy/bf500e3fd9c74e458cf4aaf00125990a_9366/Firebird_Track_Pants_Blue_FM3813_01_laydown.jpg" height="768" width="980" alt="Flower" style="position: absolute; z-index: 2;"> <span id="overlay_text" style="position: relative; z-index: 3;background-color:white;transform: rotate(-90deg); transform-origin: top left; display:inline-block; top: 100px;left: 10px">Sold Out</span></div> <br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br> <a href="https://www.mywebsite.com/item2.html">https://www.mywebsite.com/item2.html</a> <br>Available Sizes:XS,S,M,L,XL,2XL <br>------------------------------------------------------------------------------------<br> </body> </html>
您确实需要在 HTML 内联样式编写之外开始使用 CSS 等等。 在这里阅读为什么内联转换对您不起作用: CSS 转换对内联元素不起作用
<div id="demo"> <strong>1)Item 1</strong><br> <div style="text-align: right;">70<br> </div> <div style="position: relative; z-index: 1;"></div> <img src="https://assets.adidas.com/images/w_840,h_840,f_auto,q_auto:sensitive,fl_lossy/8e2d81eb3e854642b5dca97600fd73c7_9366/Firebird_Track_Pants_Black_ED6897_25_model.jpg" height="768" width="980" alt="Flower" style="position: absolute; z-index: 2;"> <span id="overlay_text" style=" transform: rotate(270deg); position: absolute; top: +90px; z-index: 3; background-color:white; line-height:50px"> SOLD OUT </span> <br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br> <a href="https://www.mywebsite.com/item1.html">https://www.mywebsite.com/item1.html</a> <br>Available Sizes:XS,S,M,L,XL,2XL <br>------------------------------------------------------------------------------------<br> <strong>2)Item 2</strong><br> <div style="text-align: right;">65<br> </div> <div style="position: relative; z-index: 1;"></div> <img src="https://assets.adidas.com/images/w_840,h_840,f_auto,q_auto:sensitive,fl_lossy/bf500e3fd9c74e458cf4aaf00125990a_9366/Firebird_Track_Pants_Blue_FM3813_01_laydown.jpg" height="768" width="980" alt="Flower" style="position: absolute; z-index: 2;"> <span id="overlay_text" style="position: relative; top: -10px; z-index: 3;background-color:white;line-height:50px"></span> <br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br> <br><br><br> <a href="https://www.mywebsite.com/item2.html">https://www.mywebsite.com/item2.html</a> <br>Available Sizes:XS,S,M,L,XL,2XL <br>------------------------------------------------
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.