I am attempting to design a straightforward layout where a heading, paragraph, and button are centered both horizontally and vertically on the page. My goal is for the .centered-div
to match the width of the .heading
.
The issue arises when the paragraph tag disrupts the layout by causing the .centered-div
to inherit the width of the .container
instead of the desired width of the .heading
.
If I eliminate the paragraph, the .centered-div
successfully takes on the width of the .heading
.
.container {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
}
.centered-div {
display: flex;
margin: auto;
align-self: center;
align-items: flex-end;
flex-direction: column;
}
.heading {
display: inline-block;
text-align: right;
}
.description {
display: inline-block;
width: 50%;
}
.link-button {
width: auto;
}
<div class="container">
<div class="centered-div">
<h1 class="heading">A Considerably Long Heading</h1>
<p class="description">
Lorem ipsum dolor...
</p>
<a class="button" href="/">Learn More</a>
</div>
</div>
In this visualization, the .container
is shown in grey while the .centered-div
is highlighted with a red outline.
https://i.sstatic.net/wXta4.png https://i.sstatic.net/8stw8.png
If further details are required, please don't hesitate to reach out. Thank you in advance for your assistance.