html - Centering a div which contains images -
i'm trying centre images failed so. added margin: auto; images not working. when removing float: left; carousel, structure gets messed up.
how can centre images?
thanks
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { var showing_default = true; var did_scroll = false; $(window).on("scroll", function (e) { did_scroll = true; }); window.setinterval(function () { if (did_scroll) { did_scroll = false; if (showing_default && $(document).scrolltop() >= 100) { showing_default = false; $("#header").css('position', 'fixed'); $("#default").stop().hide(); $("#sticky").fadein(500); } else if (! showing_default && $(document).scrolltop() < 100) { showing_default = true; $("#sticky").stop().hide(); $("#default").fadein(500); $("#header").css('position', 'fixed'); } } }, 250); }); </script> <style> * { margin: 0px; padding: 0px; } #header, #default, #carousel, #body, #footer { display: block; width: 100%; } /* --- header ------------------------------------------------------------------ */ #header, #default, #sticky { background: #eeeeee; } #header { position: fixed; z-index: 100; border-bottom: 1px solid #cccccc; } #default { height: 100px; } #sticky { display: none; height: 50px; } /* --- carousel ---------------------------------------------------------------- */ #carousel { margin-top: 101px; float: left; height: 400px; background: #ffffff; } #images { position: absolute; } .image { display: none; position: absolute; width: 900px; height: 400px; } .image img { width: 900px; height: 400px; } .first { display: block; } /* --- body -------------------------------------------------------------------- */ #body { background: #eeeeee; } /* --- footer ------------------------------------------------------------------ */ #footer { background: #dddddd; } </style> </head> <body> <div id="header"> <div id="default">default header</div> <div id="sticky">sticky header</div> </div> <div id="carousel"> <div id="images"> <div class="image first"><img src="images/1.jpg" /></div> <div class="image"><img src="images/2.jpg" /></div> <div class="image"><img src="images/3.jpg" /></div> <div class="image"><img src="images/4.jpg" /></div> </div> </div> <div id="body">top<br /><br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br /><br />bottom</div> <div id="footer">footer</div> </body> </html>
you have used structure this:
<div id="images"> <div id="image">...</div> <div id="image">...</div> <div id="image">...</div> <div id="image">...</div> </div>
so suggest center divs instead, , adapt image on div width... unique problem solution may images different sizes.
u can check example fiddles: http://jsfiddle.net/zsfjl/11/ http://jsfiddle.net/zsfjl/10/embedded/result/
Comments
Post a Comment