Why does child selector create different result when child is only element in class?

1 week ago 11
ARTICLE AD BOX

In this example, putting the font-size in the .header class makes the h1 text bigger than in the .header > h1. Why don't they produce the same size? The h1 is the only thing in the header class.

.header { grid-area: header; background-color: purple; text-align: center; color: #fffff5; font-size: 40px; } /*.header > h1 { font-size: 40px; }*/ <div class="header"> <h1>Chania</h1> </div>

mplungjan's user avatar

mplungjan

180k29 gold badges183 silver badges246 bronze badges

CEP's user avatar

New contributor

CEP is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1

Have you used your browser dev tools inspect facility to see exactly what CSS is being applied and where it is coming from?

2026-01-18 18:42:53 +00:00

Commented 12 hours ago

Read Entire Article