I think you are looking to display your content in a row rather than a column. Using flex, simply add all your display items into div
child elements. Flex by default aligns horizontally so there is no need to define a direction unless you are changing the direction. So the h2
and divs that hold the smaller text can live in a div
, then the parent div should have the flex display and you can add any other flex properties to the parent element.
So on the parent class, I added display: flex; justify-content: space-around; align-content: center;
. I also added p tags instead of divs as this will help to reduce any confusion in your html.
Note that by adding the class to the parent, you can reference the parent element and any of its children using CSS, this allows me to affect multiple elements with one block of code. Example .parent h2
or .parent p
. the HTML looks much cleaner.
As to the responsiveness with flex… the flex value is an alternative to block elements floated and manipulated using media queries. Instead, developers can build a flexible container, flexbox for short. It’s great for mobile screens and responsive content for dynamic layouts and webapps. Adding media queries in your CSS will allow your app/site to be more responsive. I suggest having a look at the following article on media queries by a well respected site called CSS Tricks, there are alot of media devices out there and building a responsive app/site will need thought out css to accommodate css media queries.
Let me know if this was not what you were looking to achieve.
* {
margin: 0;
padding: 0;
}
#main section div {
color: rgb(255, 255, 255);
margin: 40px 0px;
}
.parent {
display: flex;
justify-content: center;
align-content: center;
}
.parent h2 {
margin: 0px 0px 12px;
line-height: 48px;
font-size: 56px;
font-weight: 500;
}
.parent p {
line-height: 24px;
font-size: 16px;
opacity: 0.7;
}
@media (max-width:499px) {
#main section div {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#main {
display: flex;
flex-direction: column;
justify-content: center;
}
.parent {
flex-direction: column;
justify-content: center;
align-content: center;
}
}
<div id="main" style="background: rgb(22, 82, 240);">
<section style="width: 100vw; padding: 24px">
<div>
<div class="parent">
<div>
<h2>$320B+
</h2>
<p>
Total Volume Traded
</p>
</div>
<div>
<h2>
100+
</h2>
<p>Countries supported
</p>
</div>
<div>
<h2>
35M+
</h2>
<p>
Verified users
</p>
</div>
</div>
</div>
</section>
</div>
I also suggest separating your HTML and CSS. You have a lot of in line style that is repeating, use classes for this. You define the class once in your css file or style tag, then add the class to the class attribute in your HTML. Then if you need to change it, you’re only changing it once in your CSS.