html - Why is the text being transparent? -


html:

<!doctype html> <html> <head>     <link rel="stylesheet" type="text/css" href="style.css">     <script src="script.js"></script>     <title>cool effect</title> </head> <body>      <div class="imageholder">         <span class="note">hello!</span>         <img src="picture1.jpeg">     </div>  </body> </html> 

css:

.imageholder {     position: relative;     border: 1px solid black;     width: 300px;     height: 250px;     text-align: center;     overflow: hidden;     background-color: black; }  .note {     position: absolute;     top: 50%;     left: 50%;     -webkit-transform: translate(-50%, -50%);     transform: translate(-50%, -50%);     border: 2px solid white;     padding: 8px;     color: white;     opacity: 1;     font-size: 24px;     display: inline-block; }  img {     width: 300;     opacity: 0.4;     height: 250px; } 

fiddle: https://jsfiddle.net/xsqosw0c/1/

the text in span appears transparent, instead of solid white. i'm not sure why happening. more clear if make font-size larger.

thanks.

it's because text behind image. use z-index fix this:

.note {     position: absolute;     top: 50%;     left: 50%;     -webkit-transform: translate(-50%, -50%);     transform: translate(-50%, -50%);     border: 2px solid white;     padding: 8px;     color: white;     opacity: 1;     font-size: 24px;     display: inline-block;      z-index:2000; } 

z-index moves element forward or backward css "layers". default, html elements "layered" in order shown in html code. can either re-order html lines, or apply z-index


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -