CSS. Can't center class and it's ':before' element [duplicate] - html

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 6 years ago.
I'm learning the :before and :after pseudo-elements but I don't understand why it's not centering.
what I have:
my code :
jsfiddle down here
https://jsfiddle.net/ecfobu3g/
If I remove display: inline-block; the :before element would transition from the left of the page, But I want it from the left of the .title main element.
In short I want to achieve the same effect of transition but I want the text to be centered horizontally.
I want the .title class to be centered horizontally and the .title:before also to be centered horizontally.

Add a div around and text-align: center;
Like this
<div style="text-align : center; ">
<h1 data-title='TiPS' class='title'>TiPS</h1>
</div>

You can add
width: 100%;
to your h1 element. I'm not entirely sure if that's what you wanted.

Related

Unable to vertically center text in div with image [duplicate]

This question already has answers here:
Vertically align text next to an image?
(26 answers)
Vertically-aligned inline-block element not perfectly centered within container
(2 answers)
Closed 6 months ago.
I have a div that contains an image and text. I'm trying to simply vertically align the text.
I've tried setting vertical-align: center; and line-height:90px, but neither seem to be having any effect.
If I remove the image, even just line-height:90px does the job, so I suspect it's something to do with the image affecting the baseline of the div.
If possible I'd prefer solutions without flexbox.
My code:
.menubuttons{
height:90px;
background-color: red;
font-size:30px;
/*my unsuccessful attempt at centering the text vertically*/
vertical-align: middle;
line-height:90px;
}
.menubuttons img{
height:50px;
margin:20px;
}
<div class="menubuttons"><img src='https://cdn-icons-png.flaticon.com/512/2111/2111806.png'/>Stack Overflow</div>
jsfiddle in case SO code snippet isn't added
Just add these two properties in .menubuttons
.menubuttons{ display:flex; align-items:center; }

How do I center an icon with a text within a span? [duplicate]

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Vertically align text next to an image?
(26 answers)
How to vertically align text with icon font?
(10 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 2 years ago.
I have an icon and text next to each other in a span element. I have tried using padding and margin on the icon and/or text. The padding applies to the whole row instead of just the icon itself which is about 1rem too high.
[Edit] I would like to see centered VERTICALLY:
Instead, the icon is a tad too high.
<span><mat-icon>arrow_left_alt</mat-icon>Drag workflow </span>
adds a class to your span
.btn_container {
display: flex;
flex-direction: row;
justify-content: center;
}
Give the icon a relative position and move it down slightly:
<span><mat-icon style="position:relative; top:3px;">arrow_left_alt</mat-icon>Drag workflow </span>
You'll have to adjust the value of 3px, the higher it is, the further down the icon will move.
Other answers may give you methods of centering the object properly, but the actual centre might not be the same as the visual centre. I would use this method and simply adjust by eye to get the best result.

CSS vertical-align paragraph into div [duplicate]

This question already has answers here:
How to align content of a div to the bottom
(29 answers)
Put text at bottom of div
(5 answers)
CSS Text Align Bottom of Container
(4 answers)
How do I vertically align text in a div?
(34 answers)
Vertically centering a div inside another div [duplicate]
(24 answers)
Closed 4 years ago.
I have a div (with fixed height) with this CSS:
.div {
color: white;
font-family: Bahnschrift;
text-align: justify;
vertical-align: text-top;
}
As you can see, in this div there are paragraphs vertical aligned at the top. I want to align only the last paragraph (class="lastpar") at the bottom of the div, this is the CSS:
.lastpar {
position: relative;
vertical-align: text-bottom;
}
But it doesn't work, could you please help me to align it at the bottom of the div? Thanks
Vertical-align is not intended for aligning block elements.
Use flexbox for this
apply the following rule to the parent
div {
display: flex;
justify-content: flex-end;
}
then in another div wrap all elements but the paragraph you want to remain at bottom, and you're all set.

Logo and image on same row issue [duplicate]

This question already has answers here:
Vertically align text next to an image?
(26 answers)
vertical align middle in <div>
(11 answers)
Closed 5 years ago.
Logo and image on the same row.But padding top only the issue.Check the fiddle.
http://jsfiddle.net/6Rpkh/443/
<img class='likeordislike' src='image'><h4 class='liketext'>Twitter</h4>
The issue is the text below the image. So I want to place into the middle of the image. Padding style not working on that
First note that your image class is likeordislike, yet your selector is likeordisklike (with an extra k), so it will never apply. You'll also want to remove the width from it (to prevent stretching), and give it a taller height.
Now that the image is sorted, the text can be vertically aligned to the middle by:
Giving it display: inline-block
Setting the height equal to the height you're trying to align with
Setting vertical-align: middle
This can be seen in the following:
img.likeordislike {
height: 50px;
margin-right: 4px;
}
h4.liketext {
color: #F00;
display: inline-block;
height: 50px;
vertical-align: middle;
}
<img class='likeordislike' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAjCAMAAAA3znPYAAAAXVBMVEVVrO7///9yuvHu9/36/P5st/Dm8/1br+/K5fp3vfGQyfSFw/OazvXX6/tmtPD1+v6m0/bg8PyUy/Ss1/fQ6Pq43PjE4vnF4/me0PWm1Pa93/h1vPGJxfPk8vzZ7PuSFyAkAAABYElEQVQ4jYXU67aCIBAFYIY7qKhJZZq+/2Mejzdk0Nw/WivXZ+6mCQLXKbVRtGOHK+TS8sYoQojqq9mzpl50WbEUy4xsoQUvPo6Wi/bEcoxZT0KcmV7qtUlFUm5JHFfAWMz6O73L4jIe4+ZlvnLWc0PhjzpHWiki5NJkfWouw+wowemHtXezP27z0mG8NP3XdaiX+3KeCNZqDL/OcQD08fSDxE2UD5oJNAGhsC42zTUbTPKt0P31rnvR5vjDUATbm+DhnsTArvW9zoPm/a1+Bw3+pjVx7KChu9EWjhp0uhjH6FgD636MnPJYf2z7Q3cQa7z9UQxHGtprvO7IUXP8RwypINFT9YuhZ3CmoW5Nn95BL88q3iSaSrjQ4yPBJsJBM23TGhYdeQTYq9NdY0VCiXsCYM3f5zuiconxst/6m5wfIh8Tu/ceng/j1t5KZO3r5IyOZlLWnRXKmdbL5Hze8gfIkQ1q4RZTDwAAAABJRU5ErkJggg=='>
<h4 class='liketext'>Twitter</h4>

What is the need to make image display property as block inside div to center it? [duplicate]

This question already has answers here:
Center image inside div horizontally
(4 answers)
How to center image horizontally within a div element?
(23 answers)
Closed 5 years ago.
I am new to css and want to understand some basics. What is the need to set image display property as block to center it inside div ?
#logo {
display: block;
margin-left: auto;
margin-right: auto;
}
How does changing the display to block change the behaviour of img element inside div (how does it help center image)?
img is an inline element so setting it display: block will completely change how it flows on the page