简体   繁体   中英

100% img div according to page

How can I stretch an image to use all the WIDTH of page?

I am using div tag.

<div align="center">
                <img class="s1" src="<%=image%>"/>
        </div>


img.s1
{
display: block;
margin-left: auto;
margin-right: auto;
border-width: 0px 0px 0px 0px;
size: 100%;
}

Thanks.

You can specify that the image be the width of its container, if that is the page, then so be it - but you need to specify width , not size :

width: 100%;

Similarly, you can also specify the height ; this might become useful in your case, as, if you check the test case provided by ShadowWizard then you'll notice, the aspect ratio may be kept (which could either shrink the height within its container or expand it out of the container). Using height will force it to size accordingly , obviously.

img.s1 {
  width: 100%;
}

or .. if you want absolute positioning

img.s1 {
  position: absolute;
  left: 0;
  right: 0;
}

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