/
Understand display : inline versus block
Understand display : inline versus block
Block elements start on a new line and take up as much width as they can by default. Inline elements stay in the current line and only take up as much width as necessary.
This is the main difference between span and div tags. By default the display property for div is “block” and for span it is “inline”.
Here’s the code to show the experiment:
<html>
<head>
<link rel="stylesheet" href="BLOCK.css">
</head>
<body>
<div class=''>Default<div>Div A</div><div>Div B</div></div>
<div class='BLOCKinline'>Inline<div>Div A</div><div>Div B</div></div>
<div class='BLOCKblock'>Block<div>Div A</div><div>Div B</div></div>
<div class=''>Default<span>Span A</span><span>Span B</span></div>
<div class='BLOCKinline'>Inline<span>Span A</span><span>Span B</span></div>
<div class='BLOCKblock'>Block<span>Span A</span><span>Span B</span></div>
</body>
</html>
with this for BLOCK.css
.BLOCKinline *{
display: inline;
}
.BLOCKblock * {
display: block;
}
div * {
outline: red solid 1px; /* Display red outlines for visualization */
}
This is what the result is:
Here you can see that div’s and spans are equivalent - the only difference is that by default the display property for div is “block” and for span it is “inline”.
The display property can also be set to inline-block - which is similar to inline except that one can specify the width and height of the block.
I suggest seeing this video for more flavour.
, multiple selections available,
Related content
Just use div elements - don't use span elements.
Just use div elements - don't use span elements.
More like this
How can we find simplicity in CSS?
How can we find simplicity in CSS?
More like this
Handling white space - ignoring line breaks in white space
Handling white space - ignoring line breaks in white space
More like this
How can we do a table like display with CSS grid?
How can we do a table like display with CSS grid?
More like this
Other choices for arrangement
Other choices for arrangement
Read with this
Use of classes and divisions in CSS
Use of classes and divisions in CSS
More like this