Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text align inheritance in CSS

Tags:

html

css

I have a HTML structure which contains div and some CSS rules. I want to know that why text-align:centre is inherit to its child div and why is only text-align:centre is inherit

.multi {
  width: 500px;
  text-align: center;
  float: left
}
<div class="multi">
  <div class="rr">Abc</div>
</div>
like image 431
Jitender Avatar asked Feb 20 '23 11:02

Jitender


1 Answers

In CSS, some properties are naturally inherited, by default. text-align is one of these, along with font, color, and others. Here is a rather small (but mostly robust) list of properties which will be, and will not be, inherited by children.

What you'll have to do in this case is something like this:

<style>
.multi {
    width: 500px;
    text-align: center;
    float: left;
}
.multi .rr {
    text-align: left; /* Or whatever value multi's parent has */
}
</style>
like image 170
Cat Avatar answered Feb 22 '23 01:02

Cat