i have a very simple page with a fixed footer. On this footer, i'd like to place 5 images centered with equals distances between them.
Here is my HTML/CSS :
Footer div :
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 100%;
height: 9%;
background-color: pink;
}
And the HTML :
<div class="fixed">
<img style="max-width: 80%; margin-left: auto; margin-right: auto; max-height: 80%;" src="images/icons/icon.png">
<img style="max-width: 80%; margin-left: auto; margin-right: auto; max-height: 80%;" src="images/icons/icon.png">
<img style="max-width: 80%; margin-left: auto; margin-right: auto; max-height: 80%;" src="images/icons/icon.png">
<img style="max-width: 80%; margin-left: auto; margin-right: auto; max-height: 80%;" src="images/icons/icon.png">
<img style="max-width: 80%; margin-left: auto; margin-right: auto; max-height: 80%;" src="images/icons/icon.png">
</div>
Here is what i obtain :
I would like to display the red icons at the center. It should be responsive depending on the display resolution with the use of '%' values. I thought about doing a grid in the footer. But is there an easier way to do it ? Couldn't find anything about this on the web, hope it's not a duplicate ! Thank you in advance for any help !
You basically need to set top and left to 50% to center the left-top corner of the div. You also need to set the margin-top and margin-left to the negative half of the div's height and width to shift the center towards the middle of the div.
Aligning an image means to position the image at center, left and right. We can use the float property and text-align property for the alignment of images. If the image is in the div element, then we can use the text-align property for aligning the image in the div.
You can just add text-align: center
on fixed
div.
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 100%;
height: 9%;
background-color: pink;
text-align: center;
}
<div class="fixed">
<img src="images/icons/icon.png">
<img src="images/icons/icon.png">
<img src="images/icons/icon.png">
<img src="images/icons/icon.png">
<img src="images/icons/icon.png">
</div>
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 100%;
height: 9%;
background-color: pink;
text-align: center;
}
div.fixed >img{
max-width: 80%;
margin-left: auto;
margin-right: auto;
max-height: 80%;
}
<div class="fixed">
<img src="images/icons/icon.png">
<img src="images/icons/icon.png">
<img src="images/icons/icon.png">
<img src="images/icons/icon.png">
<img src="images/icons/icon.png">
</div>
you can use flexbox to align child items vertically center and horizontally equally spaced.
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 100%;
height: 9%;
background-color: pink;
display: flex; //Set display to flex
justify-content : space-around; //space equally horizontally
align-items: center; //place at center vertically
}
No need to give any extra styling to child elements i.e. <img>
in your case. Flexbox will take care of alignments and is very well supported by most of the browsers.
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 100%;
height: 9%;
background-color: pink;
text-align: center
}
img
{
display:inline-block;
}
Just add text-align: center;
to the parent div.fixed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With