I'm trying to center text using CSS and HTML. I'm very new to web development so I'm just getting started. I watched the basics course (made the first page) and now I'm working on my own project (other pages)
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html {
/* font-size: 10px; */
font-size: 62.5%
}
body {
font-family: "Rubik", sans-serif;
line-height: 1;
font-weight: 400;
color: #FFFFFF;
}
.second-page {
background-color: #04041af9;
padding: 4.8rem 0 9.6rem 0;
}
.our-news {
max-width: 130rem;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9.6rem;
align-items: center;
}
.heading-secondary {
font-size: 5.2rem;
font-weight: 700;
/*line-height: 1.05;*/
align-items: center;
text-align: center;
color: #FFFFFF;
letter-spacing: -0.5px;
margin-bottom: 3.2rem;
}
<section class="second-page">
<div class="our-news">
<h1 class="heading-secondary">
Why buy through us?
</h1>
</div>
</section>
But, it won't be centered at all! I spent hours researching it so I finally came here to ask for help. I've attached an image of what it looks like:
All I want is for it to appear in the center) - at least horizontally! How should I achieve this (note that this part is part two)? Thanks.
The padding in your
sectionis uneven. You need to provide uniform values such aspadding: 5rem 0;so that the entire section is evenly spacedYou used
grid-template-columns: 1fr 1frin.our-news, which tells that there will be 2 columns inside the container, taking up the same space. So you need to change this line to:grid-template column: 1fr;You provide a margin bottom for
heading-secondary. Delete the line so there won't be any unwanted space below the text.Modified code:
* { padding: 0; margin: 0; box-sizing: border-box; } html { /* font-size: 10px; */ font-size: 62.5% } body { font-family: "Rubik", sans-serif; line-height: 1; font-weight: 400; color: #FFFFFF; } .second-page { background-color: #04041af9; padding: 5rem 0; } .our-news { max-width: 130rem; margin: 0 auto; display: grid; grid-template-columns: 1fr; gap: 9.6rem; align-items: center; } .heading-secondary { font-size: 5.2rem; font-weight: 700; /*line-height: 1.05;*/ align-items: center; text-align: center; color: #FFFFFF; letter-spacing: -0.5px; }