简体   繁体   中英

Extend image 100% width beyond parent

So I'm trying to extend these slideshow images beyond the parent element of the container which is 1024px. I've tried setting max-width:100% to both the img selector, inline styling,etc. I can easily get the image 100% width but then that also sets the container to 100% which I don't want. I want the container element to remain the same, but only make the image 100% of the container.

JSFiddle: http://jsfiddle.net/schermerb/tK6H9/1/

<div class="main-inner">
    <div class="slider">
        <img alt="" src="images/slide1.jpg" />
        <img alt="" src="images/slide2.jpg" />
        <img alt="" src="images/slide4.jpg" />
    </div>
</div>

.main-inner {
    position: relative;
    width: 1024px;
    height: 475px;
    margin: auto;
}
.slider {
    width: 100%;
    height: 475px;
}
.slider img {
    width: 100%;
    height: 475px;
    margin: 0;
    position: absolute;
}
/* SLIDER CONTAINER */
 .slider-container {
    width: 1024px;
    margin: auto;
    height: 475px;
}
.previous-btn, .next-btn {
    position: absolute;
    top: 200px;
    width: 35px;
    height: 60px;
    margin: auto;
}
.previous-btn {
    left: 0;
    background: url(images/prev.png);
}
.next-btn {
    background: url(images/next.png);
    right: 0;
}
/* PAGiNATION */
 .pagination {
    position: absolute;
    top: 450px;
    right: 6px;
    margin: auto 0;
    padding: 0;
}
.pagination li {
    list-style: none;
    float: left;
    margin: 0 5px;
    width: 15px;
    height: 15px;
    position: relative;
}
.pagination li a {
    position: absolute;
    width: 15px;
    height: 15px;
    background: #fff;
    text-indent: -9999px;
    display: block;
    opacity: 10;
}
.pagination li.current-pagination a, .pagination li a:hover {
    opacity: 0.9;
    background: #00a1f1;
}

Alright, so some small changes were done.

To prevent scrolling from the big image:

body {
    overflow-x: hidden;
}

To have the image the size you want:

.slider img {
    width: 1900px;
    height: 475px;
    left:50%;
    margin: 0 auto;
    margin-left: -950px;
    position: absolute;
}

And finally, add overflow:visible; on .slider , to avoid the images from being cut on your prototype.

FIDDLE

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM