Although both the font-sizes and margin-tops are the same, the heading has more space below than above. How do I make the space below the same as the space above? Or is this how the markup should look? This is one instance of the problem!
.top-heading {
font-size: 3rem;
width: 100%;
text-align: center;
margin-top: 3rem;
}
.text {
font-size: 3rem;
margin-left: 10rem;
margin-right: 10rem;
margin-top: 3rem;
}
<main class="entire-section">
<!-- main part of program, not including aside -->
<section class="main-part-of-page">
<article class="">
<h1 class="top-heading">Keep Cooking Simple</h1>
<div class="text">
        Lorem ipsum dolor sit amet, consectetur adipisci elit, sed
I tried using em instead of rem. I expect the space above and below the heading to be the same.
3
Answers
Well, these solutions did not work, however, I have determined that I need a font that has an Ascent and Baseline equally distanced to the Top and Bottom. These look like they would work: font-family:'Gill Sans', 'Gill Sans MT', 'Calibri', 'Trebuchet MS', 'sans-serif'. Please do comment!
Joshua
It’s worth noting that certain browsers include pre-loaded CSS code as a default setting. It’s common for developers to add this code at the beginning of their CSS file or global CSS file to override any default styles.
*
selects all the HTML elements, and here you can learn more aboutbox-sizing
.If you haven’t already tried it, consider using it to overwrite any default styles that come with the browser. This way, you can ensure that your project’s styling adheres to your own custom design rather than relying on the browser’s defaults.
You can also select the
pseudo-elements
and do the same thing for them like so:Add the CSS property line-height to both the heading and the .text class to ensure that the line height is consistent throughout the text, including the heading.
This example makes sure that there is no extra space above or below the text by setting the line-height property to 1. If necessary, you can change the line-height value to get the spacing you want.