You can use the child selector >
, thus #conteudo > img
and apply width
and height
with 100%;
, so it will only affect the image that is child direct from #conteudo
Example:
#conteudo{
width:600px;
height:600px;
float:left;
background-color:#ff1;
display: initial;
margin: auto;
z-index: 6;
overflow: hidden;
}
#conteudo > img {
width: 100%;
height: 100%;
}
<div id='conteudo'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Hazard_X.svg/500px-Hazard_X.svg.png"></div>
Itmayoccurthattheimageisdistorted,soyoucanchoosetouse100%
onlyinheightorwidth,whichwillnotfill,fillordistorttheimage(perhapsitismorerectangularthanthe"parent" element) ) or you should exceed the width or height, for example see how it gets distorted:
#conteudo{
width:600px;
height:600px;
float:left;
background-color:#ff1;
display: initial;
margin: auto;
z-index: 6;
overflow: hidden;
}
#conteudo > img {
width: 100%;
height: 100%;
}
<div id='conteudo'>
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f7/Stack_Overflow_logo.png"></div>
Fillandmaintainproportion
Toexceedsizeandstillbeabletokeepratio,youcanusemin-width
andmin-heigth
,forexample:
#conteudo{
width:600px;
height:600px;
float:left;
background-color:#ff1;
display: initial;
margin: auto;
z-index: 6;
overflow: hidden;
}
#conteudo > img {
min-width: 100%;
min-height: 100%;
}
<div id='conteudo'>
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f7/Stack_Overflow_logo.png"></div>
Inthiswayyouwillmaintaintheaspectratiooftheimagerelativetothe"parent" element without distorting.