How should I set this caption over my image using CSS? -



    i beginning dabble in responsive design, , result trying pinpoint best practices in css. working on placing caption text on custom, jquery driven image slider.

    all of running @ http://www.taylorp0994.net/websites/cincoschool/index.html, please live results , code further information.

    i have achieved appears workable solution; however, fear not semantic use pixels, regardless of context. how can use percentages achieve same , approach should take, (margin-top, position:relative/top, etc.)? i've yet have success of obvious except current solution position:relative caption box , move via top:-46.5px.

the work you've posted looks promising!

two things worth mentioning cursory look:

  • there's nothing particularly 'wrong' using pixel measurements. time potentially become problem caption's length. if text change length (and thus: roll onto 2 lines), using set height adjustment won't work.
  • there's lot of empty 'p' tags within caption, deliberate?

the way tend tackle type of task use positioning:

  • have single div wrap contains both image , caption. position relative;
  • set image z-index low number;
  • set caption's z-index higher, , set position: absolute, bottom: 0. position caption off bottom edge of parent div, in turn inherit it's height image.

two secs , i'll post example.

here go: http://jsfiddle.net/hhuhr/ quick-and-dirty should put on right track:

<style>     .img-wrap{         width: 60%; /*just here preview */         position: relative;     }         .img-wrap img{             max-width: 100%;             z-index: 1         }         .img-wrap .caption{             display: block;             width: 100%;             position: absolute;             bottom: 5px; /*if using padding in caption, match here */             left: 0;             z-index: 2;             margin: 0;             padding: 5px 0;             text-indent: 5px;             color: #fff;             font-weight: bold;             background: rgba(0, 0, 0, 0.4);         } </style>  <div class="img-wrap">     <img src="http://taylorp0994.net/websites/cincoschool/img/slide1.png" alt= "">     <span class="caption">lorem ipsum dolor sit amet</span> </div> 

do remember viewport width gets narrower, caption text dominate image (as image gets smaller). tend identify point in design becomes problem , overwrite caption position bottom/left , set position: relative - drops caption directly beneath image rather over-lapping (and potentially covering) it.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -