Unable to center h2 on smaller screens

yotube
0

Issue

It's good on big screens, but when I resize the window to less than 600px, everything aligns on left. I wanted it to break on different lines if the screen size is less + aligned centre. Can you please help, as I am frustrated with this...don't know what am I doing wrong. Also, is there a way to add some breakpoint manually to break text (or other things) on different screens manually.

Thankyou.



@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Exo:wght@900&family=Inter:wght@400;500;600;700;800;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Baloo+Da+2:wght@800&family=Exo:wght@900&family=Inter:wght@400;500;600;700;800;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Fira+Sans&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');

*,
::before,
::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}

html {
scroll-behavior: smooth;
}

body {
/* overflow-y:hidden; */
}
:focus {
outline: none;
}

:root {

/* Colors*/
--primary: #FF7300;
--primary-light: #FFE3CC;
--secondary: #334762;
--white: #ffffff;

/* Fonts */
--font-one: 'Poppins', sans-serif;
--font-two: 'Exo', sans-serif;
--font-three: 'Baloo Da 2', cursive;
--font-four: 'Fira Sans', sans-serif;
--font-five: 'Lato', sans-serif;
}

body {
background-color: var(--primary-light);
font-family: var(--font-four);
color: var(--secondary);
font-size: 16px;
}

section {
width: 100%;
height: 100vh;
}

.head__container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 0px 20px;
}

.head__container h2 {
font-family: var(--font-two) !important;
font-size: 36px !important;
font-weight: 900 !important;
line-height: 1.1;
color: var(--secondary);
margin-top: 20px;
}

.head__container > h2 span {
color: var(--primary) !important;
}

a.start-button {
margin-top: 30px;
font-family: var(--font-three);
min-width: 120px;
padding: 15px 28px;
background-color: var(--primary);
color: var(--white);
font-size: 18px;
font-weight: 900;
line-height: 18px;
text-decoration: none;
}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="csshake.min.css">
<link rel="stylesheet" href="color-brewer.min.css">
<title>Select10X</title>

</head>
<body>
<section id="main" class="head__container">
<div class="logo">
<img src="logo.svg" alt="" width="250px">
</div>
<h2>
Hello There!
</h2>
<a class="start-button" href="#name">
Explore
</a>
</section>

</body>
</html>




Solution

h2 is a block level element, whose default text-align is left unless specified.

What's happening is that while h2 block is center-aligned, its text content inside is left-aligned. You simply need to add text-align: center; to your h2 as in the snippet below.



@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Exo:wght@900&family=Inter:wght@400;500;600;700;800;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Baloo+Da+2:wght@800&family=Exo:wght@900&family=Inter:wght@400;500;600;700;800;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Fira+Sans&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');
*,
::before,
::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}

html {
scroll-behavior: smooth;
}

body {
/* overflow-y:hidden; */
}

:focus {
outline: none;
}

:root {
/* Colors*/
--primary: #FF7300;
--primary-light: #FFE3CC;
--secondary: #334762;
--white: #ffffff;
/* Fonts */
--font-one: 'Poppins', sans-serif;
--font-two: 'Exo', sans-serif;
--font-three: 'Baloo Da 2', cursive;
--font-four: 'Fira Sans', sans-serif;
--font-five: 'Lato', sans-serif;
}

body {
background-color: var(--primary-light);
font-family: var(--font-four);
color: var(--secondary);
font-size: 16px;
}

section {
width: 100%;
height: 100vh;
}

.head__container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 0px 20px;
}

.head__container h2 {
font-family: var(--font-two) !important;
font-size: 36px !important;
font-weight: 900 !important;
line-height: 1.1;
color: var(--secondary);
margin-top: 20px;
text-align: center;
}

.head__container>h2 span {
color: var(--primary) !important;
}

a.start-button {
margin-top: 30px;
font-family: var(--font-three);
min-width: 120px;
padding: 15px 28px;
background-color: var(--primary);
color: var(--white);
font-size: 18px;
font-weight: 900;
line-height: 18px;
text-decoration: none;
}

<section id="main" class="head__container">
<div class="logo">
<img src="logo.svg" alt="" width="250px">
</div>
<h2>
One-click Solution for <span>Hirings</span>.
</h2>
<a class="start-button" href="#name">
Start Assessment
</a>
</section>





Answered By - Bumhan Yu

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top