我需要在html中直接设置样式的大小,但是我遇到了问题。 div容器大小只适用于在CSS类中设置高度的样式,否则容器将不会有任何高度(甚至可以在div标签中设置样式,而是尝试执行)。div样式高度不起作用
宽度和高度取自图像,我不知道任何其他方式来做到这一点;
list($width, $height) = getimagesize('dir/to/img.jpg');
echo $width . $height; //WORKING
// resizing the img...
// the resizing script have max width and height
$img_width = 'width="' . $width . '"';
$img_height = 'height="' . $height . '"';
<div class="img_container" ' . $img_width . ' ' . $img_height . '>
<img src="'. $img_dir . '" class="img"/>
</div>
// the html output is ok but maybe it's not overwriting the css
这是我使用的容器的CSS类:
.img_container {
overflow: hidden;
position: relative;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.05);
display: block;
width: auto;
min-height: 50px;
max-height: auto;
}
.img {
height: auto;
display: block;
}
如果我从.img_container
删除高度,DIV不会有任何的高度(和图像不显示,但div有宽度和高度)。
所以我想要的是div具有与图像相同的宽度和高度。
首先,当你高度后'插入分号发生什么:auto'? – 2014-10-26 22:10:32
什么是HTML的样子,你有任何额外的CSS(如绝对定位...)的图像? – jeroen 2014-10-26 22:12:40
你只是没有设置div的高度。只输出一些像素值,甚至没有div标签的任何属性(就像你做的那样)不会做任何事情。也许重新访问您选择的HTML/CSS指南? – hakre 2014-10-26 22:23:57