这是我的HTML:
<div class="data">
<div class="dataispod">
<div class = "detaljilevo">
<div class="detaljilevosub">
<h1 class="naslovdetalji"><?=$podaci->naziv?></h1>
<h4 class="kategorijadetalji"><span><?=$podaci->nazivKategorije?> zadatak • Neizvršen</span></h4>
<h4 class="opisdetalji"><?=$podaci->opis?></h4>
<h5 class="datum">Datum kreiranja: <?=$noviDatumKreiranja?></h5>
</div>
<div id="buttonwrapperdetalji">
<button type="submit" class="dugmedetalji" name="button" onclick="izvrsiZadatak();"><span class="puntekst">Izvrši zadatak</span><span class="krataktekst">Izvrši</span></button>
<form action="izmeni.php">
<button type="submit" class="dugmedetalji" name="button2" onclick="izmeni();"><span class="puntekst">Izmeni zadatak</span><span class="krataktekst">Izmeni</span></button>
</form>
</div>
</div>
<div class="slikacontainer">
<div class="slikawrap">
<img src="../slike/<?=$podaci->slika?>"/>
</div>
</div>
</div>
</div>
这是我的CSS:
.data {
margin: 80px 60px 0px 80px;
position: relative;
background-color: #BEBDC3;
border-radius: 5px;
display: flex;
flex-direction: row;
justify-content: space-between;
height: 400px;
width: 70%;
}
.dataispod {
background-color: #ffffff;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
height: 400px;
width: 100%;
}
.detaljilevo {
display: flex;
flex-direction: column;
justify-content: space-between;
background-color: green;
height: 400px;
width: 50%;
}
.detaljilevosub {
display: flex;
width: 100%;
flex-direction: column;
}
.slikacontainer {
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
width: 50%;
background-color: rebeccapurple;
}
.slikawrap {
height: 60%;
width: 60%;
display: flex;
justify-content:center;
align-items:center;
overflow: hidden;
border-radius: 5px;
box-shadow: 5px 5px 20px #555555;
}
.slikawrap img {
border-radius: 5px;
overflow:hidden;
}
用户应该上传图片,我应该在元素中显示它。用户被允许上传任何尺寸的图片,所以我试图找出一种方法来显示它们。
我花了几个小时想弄明白,但似乎什么都不管用。我将宽度作为百分比放在slikawrap
类上,这样它就可以响应,但这会导致父div data
和dataispod
在我希望它保持不变时调整大小。
1条答案
按热度按时间jv4diomz1#
您可以尝试使用
background-image
CSS property或object-fit
CSS property,其值为contain
,以确保它始终适合您的容器。示例如下:(The示例包括
filter
属性,以允许在contain
-艾德图像中设置border-radius
)