+ 6
How to center an image vertically ?
Hello sololearners ! I found no way to center an image vertically and i would like to know if somebody here knows a way to do this.
13 ответов
+ 6
Place the image into a button.
<button>
<img src="your-image">
</button>
Add css like this:
button {
outline:none;
display:block;
height:100vh;
background:transparent;
padding:0;
border:none;
}
img {
width:100vw;
height:50vh;
}
+ 6
No bro..button is not created to store images. It is just a trick.
+ 1
you can create this class
.valign-wrapper {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
and assign it to the wrapper, not to the image
-> from materializecss
try for example:
<div style="height: 100vh;" class="valign-wrapper">
<img src="" alt="">
</div>
+ 1
this is the easier way: flexbox
+ 1
it was an example 😑
+ 1
yes because buttons were created to store images...sigh 😣😣😣
0
Try out something like this CSS snippet below:
img {
display: block;
margin-left: auto;
margin-right: auto;
}
0
Oh excuse me i did an error i meant vertically
0
There is not a easier way ?
0
But i can't choose a personalized height ? Or i'm obliged to choose 100vh
0
ok
0
Align it to the center just!!