I’m having trouble placing this button beside the paragraph element. I don’t want it under it, rather I want it placed on the same line.
</div>
<div class="up">
<div class="ban">
<div class="act">
<h2>Join The Action</h2>
<p>Sign up for our product by clicking that button right over there!</p>
<button>Join Up</button>
</div>
</div>
</div>
I tried changing the flex direction to row, however that just leaves me with all three elements on the same line, and not the header on top of the paragraph element, with the button on the same line.
.up {
display: flex;
justify-content: center;
height: 19vh;
align-items: center;
}
.ban {
width: 1150px;
height: 250px;
border-radius: 25px;
background-color: red;
color: white;
}
.act {
display: flex;
flex-direction: column;
align-items:flex-start;
font-size: 25px;
padding: 50px 50px;
}
.act p {
padding: 10px 0;
}
.act button {
display: inline-block;
padding: 15px 30px;
background-color: red;
border: 2px solid white;
color: white;
font-weight: 700;
text-transform: uppercase;
border-radius: 10px;
font-size: 18px;
margin-top: 10px;
}
3
Answers
You can group
<h2>
and<p>
in a single div like belowNote: This
<div>
should still be inside your act div like below.Also adjust your css for
.act
to set yourflex-drection
to row and justify your content as space-between.Put the
p
andbutton
inside adiv
and apply flexbox to that container.(I realized that Shodipo Ayomide posted a similar answer as I was composing this one. However, you said you wanted the button next to the paragraph.)
You don’t need extra containers when using flex. You can instead set the heading to fill the row.