I am beginning to dabble in responsive design, and as a result am trying to pinpoint best practices in my CSS. I am working on placing caption text over what will eventually be a custom, jquery driven image slider.
All of this is running at http://www.taylorp0994.net/websites/cincoschool/index.html , so please look to the live results and code for further information.
I have achieved what appears to be a workable solution; however, I fear it is not semantic to use pixels, regardless of context. How can I use percentages to achieve the same look and what approach should I take, (margin-top, position:relative/top, etc.)? I've yet to have much success with any of the obvious except for my current solution which is to position:relative the caption box and move it up via top:-46.5px.
The work you've posted looks really promising!
Two things worth mentioning from my cursory look:
The way I tend to tackle this type of task is to use positioning:
Two secs and I'll post an example.
Here you go: http://jsfiddle.net/HhuhR/ This is very quick-and-dirty but should help put you on the right track:
<style>
.img-wrap{
width: 60%; /*just here for the 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 the 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 that as your viewport width gets narrower, the caption text will dominate the image (as the image itself gets smaller). I tend to identify a point in my design where this becomes a problem and simply overwrite the caption position for bottom/left and set position: relative - this drops the caption directly beneath the image rather than over-lapping (and potentially fully covering) it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.