简体   繁体   中英

i cant make div or any image 100% in html5/css3

earlier it was good but now when I put width and height 100% it doesn't really displays 100% instead a 10 px margin come on all four sides here's what I tried

 <html>
    <head>


    <style>

    .cont img {
        display: inline-block;
        width :100%;
        height : 100%;
        margin:0;
    padding:0;



    }    


    </style>




    </head>
    <body>
       <div class="cont">
    <img src="IMG_5913-2.jpg" class="imgmy" name="imgmy">

    </div>
    </body>
</html>

what can I do to make it 100% with in any browser?

have a look at this code, set margin:0px on body tag

<html>
<body style="margin:0px; ">
<div style="background-color:red; width:100%;">
hello
</div>
</body>
</html>

Assuming HTML

<body>
<div class="cont">
<img src="IMG_5913-2.jpg" class="imgmy" name="imgmy">

</div>
</body>

CSS

  .cont img {
    max-width: 100%;
    max-height: 100%;
}

Question is not 100% clear, but are you looking for a solution like this ?

.container {
    height:100%;
    width: 100%;
    border: 1px red solid;
    margin:0;
    padding:0;
    line-height: 0;
}
.container .imgmy{
   height:100%;
    width: 100%;
    margin:0;
    padding:0;
}

Are you sure it was good earlier?

The margins around the image have nothing to do with the image itself.

Browsers define default styles in a so called User Agent Stylesheet. In this case, the white border is the 8px margin (that is in Chrome) on the body.

Luckily you can easily override these user agent stylesheets, and you should in this case.

You can add margin:0 to the body, as mentioned above by Shreya. But to avoid similar 'errors' it is a good idea to include a reset.css or normalize.css. These files "make browsers render all elements consistently and in line with modern standards" ( http://cdnjs.com/libraries/normalize ). You don't have to write one yourself, others have done this for you, like Nicolas Gallagher: http://necolas.github.io/normalize.css/

Read more about User Agent Stylesheets here: What is user agent stylesheet

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