Html Image help

why does this show nothing?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<style>
#container {
height: 500px;
width: 500px;
background-color: darkcyan;
}

#image {
background-image: url("https://wallpapercave.com/wp/wp2599594.jpg");
}
</style>

</head>
<body>
<div id="conatiner">
<div id="image"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<style>
#container {
height: 500px;
width: 500px;
background-color: darkcyan;
}

#image {
background-image: url("https://wallpapercave.com/wp/wp2599594.jpg");
}
</style>

</head>
<body>
<div id="conatiner">
<div id="image"></div>
</div>
</body>
</html>
51 Replies
xKevinFPx
xKevinFPx11mo ago
the style doesnt work
Mannix
Mannix11mo ago
container and conatiner 🙂 a typo
xKevinFPx
xKevinFPx11mo ago
oh xD thanks
Mannix
Mannix11mo ago
np 🙂 dev tools are good for those sort of things 😄
xKevinFPx
xKevinFPx11mo ago
could you also help me with my main problem, please?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<style>
#container {
height: 200px;
width: 500px;
background-color: darkcyan;
}

#image {
height: 100%;
width: auto;

background-size: contain;
background-repeat: no-repeat;
background-image: url("https://wallpapercave.com/wp/wp2599594.jpg");
outline: 1px;
}
</style>

</head>
<body>
<div id="container">
<div id="image"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<style>
#container {
height: 200px;
width: 500px;
background-color: darkcyan;
}

#image {
height: 100%;
width: auto;

background-size: contain;
background-repeat: no-repeat;
background-image: url("https://wallpapercave.com/wp/wp2599594.jpg");
outline: 1px;
}
</style>

</head>
<body>
<div id="container">
<div id="image"></div>
</div>
</body>
</html>
Mannix
Mannix11mo ago
what's the problem?
xKevinFPx
xKevinFPx11mo ago
it doesent matters how big or small the hight or the width of the container is, the image always fits in there. The problem now is, that i dont set a borderradius or background color for the image anymore
xKevinFPx
xKevinFPx11mo ago
than it would look like this
xKevinFPx
xKevinFPx11mo ago
i hope you can understand it 🥲
Mannix
Mannix11mo ago
you want something like this ? https://codepen.io/MannixMD/pen/oNQVKXZ
Mannix
CodePen
oNQVKXZ
...
xKevinFPx
xKevinFPx11mo ago
no, i want the border for the image
Mannix
Mannix11mo ago
your image is not covering the whole element try cover not contain in background-size
xKevinFPx
xKevinFPx11mo ago
but i want, that the image still automaticlly fit inside the contanier, yk?
Mannix
Mannix11mo ago
background-size: 100% 100%;
xKevinFPx
xKevinFPx11mo ago
wait i try to explain again, its a bit hard 🥲 So the image has to fit in the container and all parts of the image have to be visible + the image needs a border
Mannix
Mannix11mo ago
what border ?
xKevinFPx
xKevinFPx11mo ago
sorry i mean border-radius
xKevinFPx
xKevinFPx11mo ago
yea
Mannix
Mannix11mo ago
i said you should set background-size: 100% 100%; earlier 😉
xKevinFPx
xKevinFPx11mo ago
wait 😅 its not the solution i dont know how to say it in english xD
xKevinFPx
xKevinFPx11mo ago
the image goes like ---------------->>>>>>>>>>>>>>>>>>>>
xKevinFPx
xKevinFPx11mo ago
but i want that the scale? is the same
Mannix
Mannix11mo ago
then it won't cover the whole container since it's to small
xKevinFPx
xKevinFPx11mo ago
thats okay how to do it?
snxxwyy
snxxwyy11mo ago
Could you perhaps draw out what'd you'd like? And that might help us understand better 😄
xKevinFPx
xKevinFPx11mo ago
okay, ill draw it 😅
snxxwyy
snxxwyy11mo ago
Awesome 👍🏻
xKevinFPx
xKevinFPx11mo ago
xKevinFPx
xKevinFPx11mo ago
so the image must always have the same aspect ratios, and has to fit inside the container. And as extra, but its not such important, it should be centered in the middle of the container and it needs a small borderradius
Mannix
Mannix11mo ago
you gonna use img element instead of background-image https://codepen.io/MannixMD/pen/vYQPogp
Mannix
CodePen
vYQPogp
...
snxxwyy
snxxwyy11mo ago
Set a max width on the container, set the image inside to be height of a 100% and width of 80% and margin 0 auto
xKevinFPx
xKevinFPx11mo ago
thannnkssssssss thank you very much oh no wait 🥲
xKevinFPx
xKevinFPx11mo ago
xKevinFPx
xKevinFPx11mo ago
is it possible to fix this?
Mannix
Mannix11mo ago
don't put height on the #image ??
xKevinFPx
xKevinFPx11mo ago
yea, but then it goes over the container
xKevinFPx
xKevinFPx11mo ago
I'm sorry 🥲
Mannix
Mannix11mo ago
you gotta make up your mind you either want the container to have 100px or 500px of width or try setting max-width/height as snxxwyy suggested
xKevinFPx
xKevinFPx11mo ago
yea its workinggggg
Mannix
Mannix11mo ago
oh no wait 🥲
xKevinFPx
xKevinFPx11mo ago
what?
Mannix
Mannix11mo ago
jk jk 😄
xKevinFPx
xKevinFPx11mo ago
xD oh man thank you for your time
Mannix
Mannix11mo ago
np thumbup
xKevinFPx
xKevinFPx11mo ago
now it looks good this way
xKevinFPx
xKevinFPx11mo ago
and this 😀
Mannix
Mannix11mo ago
change the height of the container ?
xKevinFPx
xKevinFPx11mo ago
yes Heres the full code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<style>
#container {
height: 95svh; /* can be changed */
width: 100%; /* can be changed */
display: flex;
margin: 0px;
}

#image {
max-height: 100%;
max-width: 100%;
margin: auto;
outline: 1px;
border-radius: 2em;
background-color: red;
}
</style>

</head>
<body>
<div id="container">
<img id="image" src="https://wallpapercave.com/wp/wp2599594.jpg" alt="">
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<style>
#container {
height: 95svh; /* can be changed */
width: 100%; /* can be changed */
display: flex;
margin: 0px;
}

#image {
max-height: 100%;
max-width: 100%;
margin: auto;
outline: 1px;
border-radius: 2em;
background-color: red;
}
</style>

</head>
<body>
<div id="container">
<img id="image" src="https://wallpapercave.com/wp/wp2599594.jpg" alt="">
</div>
</body>
</html>
its so cool
Mannix
Mannix11mo ago
if the width and height of container can be changed you will also need to change the image at the same time to achieve desired outcome
xKevinFPx
xKevinFPx11mo ago
no its alright this everything i wanted :D