我需要在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