How does vertical-align change where text appears? [duplicate] - html

This question already has answers here:
How does the vertical-align property work?
(2 answers)
Line height issue with inline-block elements
(1 answer)
Closed 2 years ago.
Shouldn’t vertical-align be changing where the text appears (relative to line-height)? It seems to just stays the same as its default (which I believe in baseline)
<div style="margin: 0;">
I sit ontop.
</div>
<span style="line-height: 100px; vertical-align: top;">I am a span.</span>
<div style="margin: 0;">
I sit below.
</div>

Related

Why isn't the background applied to child element's margin? [duplicate]

This question already has answers here:
Why does this CSS margin-top style not work?
(14 answers)
Closed 7 months ago.
<div style="background-color: #666">
<div style="margin: 20px">Some Content - no border</div>
</div>
However, if I add a border, background color is applied to the whole content including child element's margin:
<div style="background-color: #666; border: 1px solid">
<div style="margin: 20px">Some Content - has border</div>
</div>
What's the reason for this behavior? What's the specification explains this?
Since the parent Div is Empty, and the Child should have a distance to the border of the parent element, no background is shown in the margin. If you use Padding or a Border, you extend the area of the Child element to that border.

How do I make a text block sit besides an image using flex? [duplicate]

This question already has answers here:
How do I get a div to float to the bottom of its container?
(37 answers)
Align <div> elements side by side
(4 answers)
Closed 12 months ago.
I'm trying to have an image on the left of some text, then another paragraph with the image on the right of the text blow it. But when I try to use inline-blocks or similar I end up with this: https://imgur.com/nr6IoNk
I want there to be a separation between the paragraphs. All the answers I found are pre-flex and also don't work.
This is my code, that I copy pasted from some tutorial website.
<div class="section">
<img align="left" src="images/placeholder.png"/>
<p>Lorem ipsum</p>
</div>
<div class="section">
<img align="right" src="images/placeholder.png"/>
<p>Lorem ipsum</p>
</div>
.section img p {
display: flex;
flex-flow: row wrap;
align-items: center;
}

How to achieve an underline style left justified of centered text? [duplicate]

This question already has answers here:
Any way to declare a size/partial border to a box?
(6 answers)
CSS - Border where only half of a border is visible
(5 answers)
Closed 4 years ago.
How would I be able to achieve this decoration style look in a full width container? I want it to be positioned left of the start of the text, with a maximum width.
<div>
<h2 style="margin-bottom: 0; position: relative;display: inline;" >
BLOG
<div style="width: 20px;border: 2px solid red;position: absolute;">
</div>
</h2>
</div>

sum of elements' width is 100% but the last element goes to next line [duplicate]

This question already has answers here:
Why is there an unexplainable gap between these inline-block div elements? [duplicate]
(6 answers)
Closed 7 years ago.
I have 3 <img> elements in a div like this:
<div>
<img style="width: 10%;">
<img style="width: 80%;">
<img style="width: 10%;">
</div>
but the last image goes to next line. the box-sizing property of the div is border-box.
what is the problem?
Images and other inline elements are affected by whitespace in the html. This example shows your html with whitespace removed. http://jsbin.com/qoxedepifi/1/edit?html,css,output. You could set the display: inline-block; float:left which will ignore white-space. Or you could set the property white-space-collapse: discard; on the parent element.
img{float:left;}
Your can add float left on the images.

padding in one div affects other divs [duplicate]

This question already has answers here:
Using display inline-block columns move down
(2 answers)
Closed 9 years ago.
I have three inline-block divs like this:
<div style="display:inline-block">div1</div>
<div style="display:inline-block; padding-top:5px">div2</div>
<div style="display:inline-block">div3</div>
I added a padding to the second div to display it a little lower, but this makes others divs to go down as well. How to make only the second div to display lower?
Here is a JSFiddle: http://jsfiddle.net/mY6hP/
The same thing was asked here, but the accepted answer suggests using absolute positioning, which i would not like to do.
Change the alignment on the other divs so they allign themselves at the top (via vertical-align:top;):
<div style="display:inline-block; vertical-align:top;">div1</div>
<div style="display:inline-block; padding-top:5px">div2</div>
<div style="display:inline-block; vertical-align:top;">div3</div>
Try float:left instead of inline-block display:
<div style="float:left">div1</div>
<div style="float:left; padding-top:5px">div2</div>
<div>div3</div>