What is the difference between a Line Box and Inline Box? [duplicate] - html

This question already has answers here:
Understanding CSS2.1 specification regarding height on inline-level boxes
(2 answers)
Vertical align not working on inline-block
(3 answers)
Inline elements and line-height
(2 answers)
Closed 9 months ago.
I know that an inline box does not occupy whole width. It only takes required width. While referring a book on CSS, I learned that an Inline Box consists: Content Area (which is equal to em boxes stacked next to each other horizontally) + Leading (which itself is equal to sum of Top and Bottom leading). The height of this box is the Line height.
Inline Box Diagram
For Line Box, the diagram shown is this:
Line Box Diagram
My main concern here is the definition of vertical-align says that (as per MDN docs: https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align) "..vertical-align only applies to inline, inline-block and table-cell elements: you can't use it to vertically align block-level elements."
Another use case says: ".....To vertically align an inline element's box inside its containing line box."
Here the last bold term is very confusing to me. I am not able to make sense out of it and not able to visualize what these two definition says. Can any body help me with this?

Related

What is the difference between div and span? [duplicate]

This question already has answers here:
What is the difference between HTML div and span elements?
(14 answers)
Closed 2 months ago.
there are two tags in html , one is div and another one is span.. now I wish to know the difference between these two tags according to their functions and roles...
I tried both the tag but I didn't found any unique difference between both, so I am expecting to get the detailed answer .
Div element defines a section in a document (block-level).
Span elememt also defines a section in a document (inline).
So what's the difference between block-level and inline.
There are two types of elements in html.
Block-Level Elements.
Inline Elements.
Block-Level Element always starts on a new line and takes up the full width as possible.
Inline Elements doesn't starts on a new line and takes up as much width as necessary.
You cannot put a block-level elememt into an inline element.
Div is a block-level element and Span is an inline element.

Why does displaying my divs as inline cause them to overlap my h1? [duplicate]

This question already has answers here:
Padding for Inline Elements
(3 answers)
Closed 2 years ago.
I'm just playing around with the border/content box CSS properties in the very early stages of learning.
Trying to make the two boxes line up next to one another- I've achieved it with using the float left and right properties.
However, when I use display inline, it causes an overlap with the above block element h1. I've displayed it as a table here, so the background colour I've set on it only spans the width of the content, but that shouldn't change the fact that it is still a block element.
More than the overlap, display: inline on the div causes the boxes to shrink in size as well.
Can anyone explain why this is happening?
Please see the code here: https://jsfiddle.net/gouvrze1/
Only block elements respect width and height rules. Inline elements just flow with their text content. The overlap is caused by the padding and the fact that the divs are further down in the DOM, so they're drawn after and on top of previous elements.
Try changing your divs to display: inline-block instead.

Trying to understand float and text [duplicate]

This question already has answers here:
Does width property affects clear?
(1 answer)
Why is text wrapping around a floating element instead of going belows like another div?
(1 answer)
floating elements behavior
(2 answers)
Closed 4 years ago.
I'm trying to understand how float works with different elements. The first example have 2 <div> which is floated to left with one of the div having some text. As expected, both are placed next to each other horizontally.
Example 1
The second example have the same setup except that the last <div> with text is not floated to left. Now, I was expecting that <div> to go underneath the first floated <div>. But, the result is different. The second <div> went beneath the first <div> but the text is placed under the first <div>.
Example 2
Can anyone explain me what's happening?
Because overflow happens for yellow div and default is overflow: visible, text inside the yellow div creates a new block formatting context.
Overflow docs
Block formatting context

Multiple lines of text, should be width auto but instead is 100% [duplicate]

This question already has answers here:
Make container shrink-to-fit child elements as they wrap
(4 answers)
Closed 6 years ago.
Firstly, apologies for the hard to understand question title.
In HTML/CSS, I want my multiple line text element to inherit it's width from the text inside. It does this if the contained text only spans one line, but when the text spans multiple lines, it forces itself to width:100%;.
Here's a fiddle of the problem: https://jsfiddle.net/guzvpe2q/
This is what happens:
This is what should happen:
Thanks in advance.
The div really is being pushed that wide by the text, but the text cannot fit so it needs to be pushed down a line.
You also need display:inline-block.
One way around it would be to add manual line-breaks after the first word (not exactly ideal i know)
See (https://www.w3.org/TR/CSS21/visudet.html#inlineblock-width)

Why does the blue box not surround the child div-elements? [duplicate]

This question already has answers here:
Why doesn't the height of a container element increase if it contains floated elements?
(7 answers)
Closed 7 years ago.
I published a simple example on jsbin. And I do not understand why The blue box does not surround the child elements if the childs have a float:left.
http://jsbin.com/saluxapiti/1/edit?html,css,js,output
When you set property to float.It takes your element over html surface.Looks like an air baloon.
Summarizing what this page states:
Elements after a floating element will flow around it; therefore the border of the parent class is flowing around the floated child.