I am trying to overlay a caption on an image. However, the background is hidden under the image. Why is this happening?
http://jsfiddle.net/YRDFB/
<div class="header"> <img width="100%" height="200px" src="/path/to/image.jpg" /> <h1>Header Title</h1></div> h1 { background: rgba(67,67,67,0.8); margin-top: -3em; }
Here we have 2 solutions:
Using display:inline-blockand set width:100%to yours h1, instead use a negative margin-bottomon img:
display:inline-block
width:100%
h1
margin-bottom
img
h1 { background: rgba(67,67,67,0.8); display:inline-block; width:100%; } img { margin-bottom:-4em; }
Using position:relativefor img and set for it z-index:-1:
position:relative
z-index:-1
h1 { background: rgba(67,67,67,0.8); } img { margin-bottom:-4em; position:relative; z-index:-1; }
You are looking for this updated script
h1 { background: rgba(67, 67, 67, 0.8); position:relative; z-index:9; display:block; width:100%; padding:0; color:#fff; margin-top:-43px; }
Source: https://habr.com/ru/post/1623902/More articles:Can I configure OpenMP 4.0 in VisualStudio? - c ++How to change the color palette for GGally :: ggpairs? - rhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1623899/best-way-to-clone-a-git-repository-when-authenticating-via-ssh-key-forwarding&usg=ALkJrhgYAnyz10w5q9lYVrxhDV6FMjsJVATest Target for debugging as a root process - debuggingNegative field removes background property of static siblings - html@PreAuthorize Not working with spring security 4 - spring-mvcHow to convert JSON file to parquet using Apache Spark? - jsonCUDAfy module performance - c #Дни истечения срока действия пароля LDAP - c#Log4j2 - setting RolloverStrategy to delete old log files - javaAll Articles