![](/img/trans.png)
[英]How can I create zoom 'windows' showing a zoomed portion of an image based on a div location using CSS3/HTML5 or Javascript?
[英]i cant make div or any image 100% in html5/css3
之前它很好,但是現在當我將寬度和高度設置為100%時,它並沒有真正顯示100%,而是在所有四個側面上都添加了10 px的邊距,這就是我嘗試過的
<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>
如何在任何瀏覽器中使其達到100%?
看一下這段代碼,在body標簽上設置margin:0px
<html>
<body style="margin:0px; ">
<div style="background-color:red; width:100%;">
hello
</div>
</body>
</html>
假設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%;
}
問題是不是100%清楚,但你在找的溶液等這樣 ?
.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;
}
您確定早些時候還不錯嗎?
圖像周圍的邊緣與圖像本身無關。
瀏覽器在所謂的“用戶代理樣式表”中定義默認樣式。 在這種情況下,白色邊框是主體上的8px邊距(在Chrome中)。
幸運的是,您可以輕松覆蓋這些用戶代理樣式表,在這種情況下,您應該這樣做。
可以如上Shreya所述,將margin:0添加到主體。 但是要避免類似的“錯誤”,最好包含reset.css或normalize.css。 這些文件“使瀏覽器一致地呈現所有元素並符合現代標准”( http://cdnjs.com/libraries/normalize )。 您不必自己寫一個,其他人也可以為您完成,例如Nicolas Gallagher: http : //necolas.github.io/normalize.css/
在此處閱讀有關用戶代理樣式表的更多信息: 什么是用戶代理樣式表
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.