Inline
The default value for elements. Think of elements like<span>, <em>, or <b> and how wrapping text in those elements within a string of text doesn't break the flow of the text. The
<em> element has a 1px red border. Notice it sits right inline with the rest of the text.height and width. It will just ignore it.Inline Block
An element set toinline-block is very similar to inline
in that it will set inline with the natural flow of text (on the
"baseline"). The difference is that you are able to set a width and height which will be respected.Block
A number of elements are set toblock by the browser UA stylesheet. They are usually container elements, like <div>, <section>, and <ul>. Also text "blocks" like <p> and <h1>.
Block level elements do not sit inline but break past them. By default
(without setting a width) they take up as much horizontal space as they
can.<p>s which are block level elements. The <em> element in between them doesn't sit inline because the blocks break down below inline elements.Run-in
First, this property doesn't work in Firefox. Word is that the spec for it isn't well defined enough. To begin to understand it though, it's like if you want a header element to sit inline with the text below it. Floating it won't work and neither will anything else, as you don't want the header to be a child of the text element below it, you want it to be its own independent element. In "supporting" browsers, it's like this:None
Totally removes the element from the page. Note that while the element is still in the DOM, it is removed visually and any other conceivable way (you can't tab to it or its children, it is ignored by screen readers, etc).Table Values
There is a whole set of display values the force non-table elements to behave like table-elements, if you need that to happen. It's rare-ish, but it sometimes allows you to be "more semantic" with your code while utilizing the unique positioning powers of tables.div {
display: table;
display: table-cell;
display: table-column;
display: table-colgroup;
display: table-header-group;
display: table-row-group;
display: table-footer-group;
display: table-row;
display: table-caption;
}
To use, just mimic normal table structure. Simple example:<div style="display: table;">
<div style="display: table-row;">
<div style="display: table-cell;">
Gross but sometimes useful.
</div>
</div>
</div>
Flexbox
Thedisplay property is also used for new fangled layout methods like Flexbox..header {
display: flex;
}
There are some older versions of flexbox syntax, so please consult this article for the syntax in using flexbox with the best browser support. Be sure to see this complete guide to Flexbox.Grid
Grid layout will also be initially set by the display property.body {
display: grid;
}
Although at the time of this update, only IE 10 is supporting it. Here's the spec on grids.
No comments:
Post a Comment