I have a header and a “p” element that I want on one horizontal line. I’ve managed to obtain the desired result manually using CSS “position” function, but I would like to learn the proper way to do this so that both elements are mathematically aligned for future reference. I want the middle of each element to be on the same horizontal line, as one element has more height than the other. I tried using “display: inline-block” and that didn’t work, perhaps because I have different margins set for each element but I’m not sure.
HTML:
<div class="head-one">
<h2 id="#about-me">About Me</h2>
<p id="cal">My name is Cal Cook. I'm 26 years old and live in Boston, Massachusetts. I'm from NYC originally. I'm passionate about cryptocurrency, web design and SEO. I built this site to feature my work.</p>
</div>
CSS:
h2 {
padding: 75px;
margin-left: 30px;
font-family: 'Nunito Sans', sans-serif;
}
#cal {
font-family: 'Roboto', sans-serif;
border: solid;
border-radius: 25px;
padding: 10px;
margin-left: 350px;
margin-right: 250px;
position: relative;
bottom: 140px;
}
2
Answers
I would suggest removing all of your positing code. Use
display: flex
on the container andflex: 1
on the#cal
element.It’s a perfect situation (like almost every other) for CSS_layout/Flexbox
CSS_layout/Flexbox