css .. how can i make button show image -
i have question making button show image example, have 4 buttons want each button showing image in same content images
in other words: when press 1 of buttons show image
here example: http://jsfiddle.net/i5yal/yvctq/1/
<div id="section-container"> <div class="section-img-container"><a>images appear here</a> </div> </div> <div id="section-button-container"><div> <div class="section-button1"><a>1</a> </div> <div class="section-button2"><a>2</a> </div> <div class="section-button3"><a>3</a> </div> <div class="section-button4"><a>4</a> </div> </div> </div>
css code:
#section-container { background-color: #c0c0c0; width: 300px; height: 300px; margin:0 auto; } #section-button-container { width: 300px; height: 30px; margin:0 auto; } .section-button1 { background-color: #808000; width: 30px; height: 30px; float: left; display: block; margin-left: 30px; margin-right: 20px; } .section-button2 { background-color: #808000; width: 30px; height: 30px; float: left; display: block; margin-left: 20px; margin-right: 20px; } .section-button3 { background-color: #808000; width: 30px; height: 30px; float: left; display: block; margin-left: 20px; margin-right: 20px; } .section-button4 { background-color: #808000; width: 30px; height: 30px; float: left; display: block; margin-left: 20px; margin-right: 20px; } .section-img-container { background-color: #008080; background-position: center center; width: 270px; height: 270px; margin: 0 auto; }
to avoid using javascript, it's possible use css (albeit there has minor adjustments html in order so); given amended html:
<div id="section-container"> <div class="section-img-container"> <input type="radio" name="images" id="img1" /> <img src="http://placekitten.com/300/300/" /> <input type="radio" name="images" id="img2" /> <img src="http://lorempixel.com/300/300/nightlife" /> <input type="radio" name="images" id="img3" /> <img src="http://lorempixel.com/300/300/people" /> <input type="radio" name="images" id="img4" /> <img src="http://dummyimage.com/300x300/000/f90.png&text=image+lorem+ipsum" /> </div> </div> <div id="section-button-container"><div> <div class="section-button1"> <label for="img1">1</label> </div> <div class="section-button2"> <label for="img2">2</label> </div> <div class="section-button3"> <label for="img3">3</label> </div> <div class="section-button4"> <label for="img4">4</label> </div> </div> </div>
and following css:
#section-button-container label { display: block; text-align: center; height: 100%; line-height: 30px; cursor: pointer; } input[type=radio], input[type=radio] + img { display: none; } input:checked + img { display: block; }
this require browser supports :checked
pseudo-selector , css next-sibling +
combinator, however; , takes advantage of label
being able check/uncheck radio input (so long for
attribute of label
identifies id
of relevant input
).
references:
Comments
Post a Comment