CSS - image refuses to vertical align in middle [duplicate] - css

This question already has answers here:
How to vertically align an image inside a div
(37 answers)
How can I vertically align elements in a div?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 3 years ago.
The image is not in the middle of the div.
Tried various solutions, such as line-height and vertical-align:middle;
.trio {
height: 80px;
line-height: 80px;
background: #f2f2f2;
}
.wp-image-6731,
.wp-image-6733,
.wp-image-6733 {
vertical-align: middle
}
<div class="trio">
<img class="wp-image-6733 size-full aligncenter" src="https://proef-domein.nl/chiropractic/wp-content/uploads/2019/06/2.png" alt="" width="103" height="31">
</div>

Related

Css - vertical centering of an image inside a div [duplicate]

This question already has answers here:
How to vertically align an image inside a div
(37 answers)
Flexbox: center horizontally and vertically
(14 answers)
How can I vertically align elements in a div?
(28 answers)
Closed 2 years ago.
here HTML:
<div class="user-image text-center">
<img class="avatars" src="css/img/avatar_1.jpg" alt="">
</div>
here CSS:
.user-image {
height: 10vh;
width: 15%;
float: left;
}
I'm trying to centering vertically my image inside my DIV (it's a square) but I'm a beginner and can't find the correct way. I tried vertical-align: middle; and margin: auto; but nothing. Can you suggest me some methods for that?
Use flex styles.
.user-image {
display: flex;
justify-content: center;
align-items: center;
}

Right align all elements when text makes a new line [duplicate]

This question already has answers here:
Make container shrink-to-fit child elements as they wrap
(4 answers)
CSS when inline-block elements line-break, parent wrapper does not fit new width
(2 answers)
Closed 2 years ago.
I have a set of divs and want the children to be right aligned:
.parent {
width: 150px;
border: solid;
display: flex;
align-items: center;
justify-content: flex-end;
}
<div class="parent">
<div class="icon">x
</div>
<div>Toooooooo looooooooong</div>
</div>
When the text breaks in a newline, it still occupies all the space, so it's not at the right. I could use width: min-length, but then all the short texts with spaces break in a new line, and I want it only for the long ones.
Here's the example in CodePen: https://codepen.io/rveciana/pen/eYpyKJX

How do I vertically center an element inside a table-like column? [duplicate]

This question already has answers here:
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
Flexbox: center horizontally and vertically
(14 answers)
How can I vertically align elements in a div?
(28 answers)
How can I vertically center a div element for all browsers using CSS?
(48 answers)
Closed 2 years ago.
I'm having a large div section divided into three columns (it's set to be displayed as a table so every column would be the same height), and I need to vertically center-align the elements (cards) that are located inside each column.
I tried to vertically align the elements (cards) by adding position: relative to the column's class, and adding the following code to the relevant cards' classes:
position: absolute;
top: 50%;
transform: translate(-50%);
But instead of working, it completely messed up and destroyed the page's structure.
I also tried to use vertical-align: middle, but it did absolutely nothing.
This is part of the code that I'm currently having (without the coding attempts mentioned above):
<div id="cards">
<div class="col">
<div class="card card-cyan">
<h2>Supervisor</h2>
<p>Monitors activity to identify project roadblocks</p>
</div>
</div>
<div class="col">
<div class="card card-red">
<h2>Team Builder</h2>
<p>Scans our talent network to create the optimal team for your project</p>
</div>
<div class="card card-orange">
<h2>Karma</h2>
<p>Regularly evaluates our talent to ensure quality</p>
</div>
</div>
<div class="col">
<div class="card card-blue">
<h2>Calculator</h2>
<p>Uses data from past projects to provide better delivery estimates</p>
</div>
</div>
</div>
#cards {
padding-left: 8%;
padding-right: 8%;
display: table;
}
.col {
display: table-cell;
padding: 2%;
}
.card {
border-radius: 10px;
border: none;
background-color: #ffffff;
padding: 2%;
width: 100%;
}
Any ideas on how to solve this trouble?

Centering <h1> in <body> depends on text [duplicate]

This question already has answers here:
How to align entire html body to the center?
(11 answers)
Closed 3 years ago.
Can I calculate with width of <h1> (depends on text) and center this <h1> horizontally in <body>?
Thanks for any help and hint!
Robin Zigmond is correct in their comment. You can center a block-level element by setting it's margin-left and margin-right to auto. It will appear centered if it's width is not 100% of it's parent container:
h1 {
margin-left: auto;
margin-right: auto;
}
If its width is 100% of its parent container, you could use text-align to set the text to center:
h1 {
text-align: center;
}

Vertically aligning <div> contents [duplicate]

This question already has answers here:
How do I vertically center text with CSS? [duplicate]
(37 answers)
Closed 5 years ago.
The simplest things... Why isn't the text in the below centered vertically? Isn't that what vertical-align: middle does?
<div style="width:100%;height: 300px;background-color: #0047b3;vertical-align: middle;">
Why are you not centered vertically?!?!?!
</div>
If you read some of the flex properties it gets lot easier see below
'
div {
width: 100%;
height: 300px;
background-color: #0047b3;
display: flex;
align-items: center;
}
<div>whatever you want to align vertically centre </div>

Resources