I have some centered divs that have a title and text below the title. The title is centered but the text is aligned on the left and starts from where the title starts. I used inline-block
to make the div adjust in size based on the content. However, if the text is longer than the title, the container adjusts its width based on the text, not the title, so then the text appears wider than the title. How do I keep the width based on the title, not the text? I've included my code below as well as a badly drawn image to better understand what happens.
HTML and CSS:
.projects {
width: 30vw;
left: 10vw;
right: 10vw;
margin: 50px auto 0 auto;
text-align: center;
}
.pContent {
display: inline-block;
margin-bottom: 10px;
}
.pInfo {
text-align: left;
}
<div class="projects">
<h2>My Projects:</h2>
<div class="pContent">
<h3 id="p1" class="pTitle">Project Title</h3>
<div id="p1Info" class="pInfo">
<p class="desc">This is a project description Lorem Ipsum Dolor</p>
<p class="demo">View a demo of the project.</p>
</div>
</div>
<br>
<div class="pContent">
<h3 id="p2" class="pTitle">Another Project Title</h3>
<div id="p2Info" class="pInfo">
<p class="desc">This is a project</p>
<p class="demo">View.</p>
</div>
</div>
</div>