Why Inherit?

First off my files works but I don’t know why!

http://www.c5d.co.uk/descriptioned11901.php (there are 20 similar pages …ed11901php to …ed201901.php

I want to center a block of text. and if I understand it W3c says I should use

    margin-left: auto;
    margin-right: auto;

The example quoted also quotes a width, but because I want to use the same class on twenty pages, I can’t specify a width other than say 100%.

Without a width, the block stays resolutely left side, but f I add inherit. It works fine.

When I inspect the block though, there is nothing to inherit other than

body {
    font-weight: 700;
    font-style: italic;
    font-size: 15px;
    font-family: "New Century Schoolbook", Times, serif;}

Slightly confused to start with, when you say inherit, I assumed you set width to inherit.
But what you have done is set display to inherit.
So the display property is inherited from the parent element, which in this case is display: table, as opposed to the default display of a block element which is of course block.
A table will only take the width it needs, whereas a block will default to width: auto and fill the parent container.
So effectively you do have a reduced width, which makes margin: auto relevant.
When you fill the parent width, margin: auto is pointless or equivalent to no margin.

1 Like

Thanks. I didn’t want to put a width in because the width of the blocks vary. I could have put 99% or something to get over that.

Selecting inherit was just playing with the options.

I don’t understand what you mean by <<So the display property is inherited from the parent element, which in this case is display: table, >> becuase the inspector says the only thng inherited is from CSS line2

The block is not in a table though

The inspector shows only inherited properties that are not defined on the property itself, the element does declare the display property, so it shows only on the element itself.

No, it is in a div with the class .container which has the display property of display: table which is being inherited.

1 Like

OK, thanks.

Points noted.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.