<div class="activities">
<h3>Top three activities to do at Torshov</h3>
<img class="activities-img" src="images/deniz.jpg">
<img class="activities-img" src="images/muze.jpg">
<img class="activities-img" src="images/bar.jpg">
</div>
body {
margin: 0;
}
.activities-img {
width: 100%;
width: 100px;
height: 100px;
margin-left: auto;
margin-right: auto;
justify-content: center;
}
I want to center the images, I have tried with "justify content", "text-align" and all but didn’t work, could you help me? Thanks.
4
Answers
Wrap the images in a container with the
display
property set toflex
. Then you can use thejustify-content
property.I think you forgot centering content in parent div .activities
There are several ways to do this. It depends on whether you should do it with flexbox or without flexbox. Also, it depends on whether the html can be changed or should not be changed.
With flexbox, changes in your html:
Without flexbox, but the same html
You could need "text-align" to center de content of the h3 tag
You can simply use the center tag, no need to change the css, center tag always helps, you HTML code should be like this :-
<div class="activities"> <h3>Top three activities to do at Torshov</h3> <center><img class="activities-img" src="images/deniz.jpg"> <img class="activities-img" src="images/muze.jpg"> <img class="activities-img" src="images/bar.jpg"></center> </div>