2015-06-02 146 views
0

我无法调整图像的大小css/html。我可以在px中调整大小,但不能以%为单位。我已经尝试了最小高度,最小宽度。这是我的代码,我无法调整它。css html百分比调整图像

body{ 
 
    margin: 0; 
 
} 
 
#top{ 
 
    background-color: #53FF40; 
 
    width: 100%; 
 
    height: 50%; 
 
} 
 
#bottom{ 
 
    background-color: #FF5757; 
 
    width: 100%; 
 
    height: 50%; 
 
} 
 
.img-yes{ 
 
    width: 25%; 
 
    height: 25%; 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title>DoYouLoveDogs</title> 
 
<link rel="stylesheet" type="text/css" href="css/style.css"> 
 
<body> 
 
<div id="top"> 
 
<div class="img-yes"> 
 
    <img class="img-yes" src="img/yes.png"> 
 
</div> 
 
</div> 
 
<div id="bottom"> 
 
</div> 
 
<script src="js/jquery.js"></script> 
 
<script src="js/button.js"></script> 
 
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script> 
 
</body> 
 
</html>

+0

我不明白这个问题。你可以在JSFiddle.net中重现问题吗? – LinkinTED

+0

你到底想要什么?更改img的大小?你可以拨弄它 –

+0

我看到你给的代码没有问题。它调整完美。 – Anonymous

回答

1

display: block

.img-yes { 
    display: block; 
    width: 25%; 
    height: 25%; 
} 
1

添加

.img-yes 
{ 
width: 100%; 
height: auto; 
} 

fiddle

0

首先你需要在图像的外层div像素设置大小。然后用百分比调整图像大小。

.outerdiv{ 
    width:200px; 
    height:200px; 
} 
.img-yes{ 
    width: 50%; 
    height:30%; 
} 

但是,如果您只想调整图像大小,只能给出宽度百分比,高度会根据宽度自动设置。

0

我只是复制粘贴你的代码到记事本(更改内部CSS为内联css并更改图像路径)并执行它。它工作正常。当我增加宽度时,图像根据宽度调整大小。

0
.img-yes { 
    height: 40% !important; 
    margin: 5px 28px 22px 82px; 
    width: 50% !important; 
}