0

i am using .section-title h1 in my css to and align the text to centre but it doesnt work but it surely work if i just use h1 to align text.

<div id="section-title">
    <h1>GET IN TOUCH</h1>
    <p>Make sure to subscribe to this channel</p>
</div>

For the CSS I have tried

h1.section-title {
    text-align: center;
}

and

.section-title h1
{
    text-align: center;
}
geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
  • section-title is the ID of the H1. So please use # instead of . in your css – Azeez Kallayi Oct 29 '19 at 06:49
  • 1
    That is because you assigned it as an ID but in your css, you are calling it as a class, thus , there is no such class. Change the `.` to `#` in your css . eg; `#section-title h1` – Gosi Oct 29 '19 at 06:49

3 Answers3

1

Answer:

Instead of using Class selector replace with ID selector(#).

#section-title h1
{
    text-align: center;
}
0

There are two options:

Option1 using a div class:

<div class="section-title">
    <h1>GET IN TOUCH</h1>
    <p>Make sure to subscribe to this channel</p>
</div>
.section-title h1 
{
    text-align: center;
}

Or option2 using the h1 ID:

<div>
    <h1 id="section-title">GET IN TOUCH</h1>
    <p>Make sure to subscribe to this channel</p>
</div>

and

h1#section-title
{
    text-align: center;
}
Jan Dolejsi
  • 1,389
  • 13
  • 25
  • Because there are fundamental differences between classes and IDs in html/css. You are using an id so you have to use Id selector. – cloned Oct 29 '19 at 07:00
0

Please try this

'section-title' is the ID of the H1. So please use '#' instead of '.' in your css

h1#section-title
{
    text-align: center;
}
<div>
    <h1 id="section-title">GET IN TOUCH</h1>
    <p>Make sure to subscribe to this channel</p>
</div>
Azeez Kallayi
  • 2,567
  • 1
  • 15
  • 19