I have some buttons but the button with google icon inside produce a white space, if I change the icon (span) using text the circle one will be aligned to another correctly, i think its the span of the google icon but have no idea how to fix it, hope someone can help, thanks in advance
this is html
<div className="col-left">
<Button icon="add" className="mr-8" theme="primary|md" handleClick={()=> alert(1)} label="Create" />
<Button className="mr-5" theme="primary-transparent|md" handleClick={()=> alert(1)} label="Approve" />
<Button className="mr-5" theme="primary-transparent|md" handleClick={()=> alert(1)} label="Decline" />
<Button className="mr-5" theme="primary-transparent|md" handleClick={()=> alert(1)} label="Approve" />
{/* <span className="separator"></span> */}
<Button icon="add" className="mr-5" theme="primary-transparent|circle|md" />
</div>
this is the scss
.btn {
display: inline-grid;
border: 0;
background: red !important;
cursor: pointer;
&.btn-md {
font-size: 22px;
height: 40px;
}
&.btn-sm {
font-size: 18px;
span {
font-size: inherit;
}
}
&.btn-a {
color: #777;
background: transparent;
&:hover {
background: #e7e6e5;
}
}
&.btn-circle {
display: inline-grid;
background: $clr-primary;
place-items: center;
&.btn-sm {
#include circle(40px);
}
&.btn-md {
#include circle(40px);
}
span {
grid-column: 1/2;
margin: 0;
}
}
&.btn-primary {
background: $clr-primary;
color: white;
border-radius: 2px;
padding: 0px 16px;
font-size: 13px;
align-items: center;
}
span {
display: inline-block;
grid-column: 2/3;
margin-left: 10px;
font-size: 16px;
}
&.btn-primary-transparent {
border-radius: 2px;
padding: 8px 8px;
font-weight: 700;
color: $clr-primary;
font-size: 13px;
background: #fafafa;
align-items: center;
}
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
display: inline-block;
line-height: 4px;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
-moz-osx-font-smoothing: grayscale;
font-feature-settings: 'liga';
You can add css to the parent div. This should work without any other modifications as you have margins set to your buttons. The display: flex; (on the parent) will remove the need of using inline-block on the buttons.
.col-left {
display: flex;
align-items: center;
}
Related
This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
How can I vertically align elements in a div?
(28 answers)
Closed 10 months ago.
I'm trying to vertically center icon and text in a background, but I guess I'm doing something wrong. The dot before the text is not perfectly centered with the background. Why is this happening ?
Is there a better way to do this ? Sorry but I'm new.
.status {
display: inline;
}
.success {
font-family: roboto;
color: #27ae60;
background: #e1e1e1;
border-radius: 50px;
padding: 0px 50px 0px 50px;
font-size: 38px;
}
.success:before {
font-family: FontAwesome;
content: "\f111";
font-size: 10px;
margin-right: 16px;
color: #27ae60;
vertical-align: middle;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" rel="stylesheet">
<div class="status success">Purchuased</div>
You can use a flexbox or grid to center the text en icon perfectly.
Below an example using flexbox.
.status {
/* Added */
display: flex;
align-items: center;
}
.success {
font-family: roboto;
color: #27ae60;
background: #e1e1e1;
border-radius: 50px;
padding: 0px 50px 0px 50px;
font-size: 38px;
}
.success:before {
font-family: FontAwesome;
content: "\f111";
font-size: 10px;
margin-right: 16px;
color: #27ae60;
/* vertical-align: middle; Removed */
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" rel="stylesheet">
<div class="status success">Purchuased</div>
The best way would be to utilise flexbox:
CSS:
.status {
display: inline-flex; // flex or inline-flex here
}
.success:before {
font-family: FontAwesome;
content: "\f111";
font-size: 10px;
margin-right: 16px;
color: #27ae60;
align-self: center; // use this instead of vertical-align: middle;
}
if its just 1 line of code You can simply add center tag to align both of them in the middle, inline-flex then align-items center to be vertically align Let me know if this is what you mean.
.status {
display: inline-flex;
align-items:center;
}
.success {
font-family: roboto;
color: #27ae60;
background: #e1e1e1;
border-radius: 50px;
padding: 0px 50px 0px 50px;
font-size: 38px;
}
.success:before {
font-family: FontAwesome;
content: "\f111";
font-size: 10px;
margin-right: 16px;
color: #27ae60;
vertical-align: middle;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" rel="stylesheet">
<center><div class="status success">Purchased</div></center>
.status {
display: inline;
}
.success {
font-family: roboto;
color: #27ae60;
background: #e1e1e1;
border-radius: 50px;
padding: 0px 50px 0px 50px;
font-size: 38px;
}
.success:before {
font-family: FontAwesome;
content: "\f111";
font-size: 10px;
margin-right: 16px;
color: #27ae60;
vertical-align: 10px;
}
this worked for me
.status {
display: inline;
position: relative;
}
.success {
font-family: roboto;
color: #27ae60;
background: #e1e1e1;
border-radius: 50px;
padding: 0px 50px 0px 50px;
font-size: 38px;
}
.success:before {
position: absolute;
font-family: FontAwesome;
content: "\f111";
font-size: 10px;
margin-right: 16px;
color: #27ae60;
transform: translate(-25px, 21px);
}
This is another "how do I vertically center" question in HTML. This one is when using the :before modifier.
HTML
<div style="border: 1px solid blue">
<div class="status-yellow">vertically center me</div>
</div>
CSS
.status-yellow {
display: inline-block;
padding: .35em .65em;
font-size: .75em;
font-weight: 400;
line-height: 1;
color: #000;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
text-transform: uppercase;
background-color: #fff;
}
.status-yellow:before {
display: inline-block;
content:"\2022";
margin-right: 0.5rem;
color: yellow;
font-size: 48px;
}
Here's a CodePen showing the issue
I have a div tag and I'm using the :before modifier to inject a bullet before the text. When the bullet increases in size, the vertical centering doesn't work. When the bullet is tiny (too tiny) it's all centered. I'm missing something. What am I missing?
You can use flexbox.
.status-yellow {
display: inline-block;
padding: .35em .65em;
font-size: .75em;
font-weight: 400;
line-height: 1;
color: #000;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
text-transform: uppercase;
background-color: #fff;
display:flex;
align-items:center;/*for vertical align*/
justify-content:center;/*for horizontal align*/
}
.status-yellow:before {
display: inline-block;
content:"\2022";
margin-right: 0.5rem;
color: yellow;
font-size: 48px;
}
I have a span like this:
<span class="indicator"></span>
Inside this span sometimes I have numbers like this:
<span class="indicator">
<span>10</span>
</span>
And, sometimes some Kendo-UI icons, like this:
<span class="indicator">
<span class="k-font-icon k-i-checkmark"></span>
</span>
And, here is my css:
span.indicator {
position: relative;
border: 1px solid #8a8a8a;
background: #8a8a8a;
color: #ffffff;
font-size: 0.85em;
font-family: helvetica;
padding: 2px;
margin: 2px;
width: 30px;
overflow: visible;
text-decoration: none;
text-align: center;
display: inline-block;
border-radius: 4px;
}
.k-font-icon {
font-family: KendoUIGlyphs;
speak: none;
font-style: normal;
font-weight: 400;
font-variant: normal;
text-transform: none;
font-size: 1.3em;
line-height: 1;
opacity: 1;
text-indent: 0;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-image: none;
font-size: 16px;
}
There are two problems:
I want the two span indicators to have the same heights. The height of
the one with icon is one pixel more than the other one.
The icon in the span with icon is not vertically aligned.
UPDATE:
I realized if I change the font-size of .k-font-icon to 1em, both issues will be resolved, but the icon will be too small.
UPDATE 2:
Here's a Kendo UI Dojo.
.k-font-icon {
vertical-align: middle;
}
Simplest way, hope this help.
if you're setting the height and with of your .indicator, there are a few ways you could do this, but the easiest is probably to change the display to flex instead of inline-box and add a couple of properties (I haven't added the vendor prefixes, mostly because I'm lazy…):
.indicator {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #8a8a8a;
background: #8a8a8a;
color: #ffffff;
font-size: .85em;
font-weight: 400;
font-family: helvetica;
padding: 2px;
margin: 2px;
width: 30px;
height: 20px;
border-radius: 4px;
}
Unrelated side note: unless you have an .indicator class that behaves different ways depending on what HTML element it's on (and if that's the case, you should probably refactor that) you shouldn't add a span at the beginning of you CSS rule. It increases the specificity for no reason and makes your CSS less flexible/future proof.
Try using line-height and vertical-align css:
span.indicator {
position: relative;
border: 1px solid #8a8a8a;
background: #8a8a8a;
color: #ffffff;
font-size: .85em;
font-weight: 400;
font-family: helvetica;
padding: 2px;
margin: 2px;
width: 30px;
height: 20px;
line-height: 20px;
vertical-align: middle;
overflow: visible;
text-decoration: none;
text-align: center;
display: inline-block;
border-radius: 4px;
}
span.indicator .k-font-icon {
line-height: 20px !important;
}
DEMO
Updated
what about this?
span.indicator {
background: #8a8a8a;
color: #ffffff;
font-size: 1.35em;
font-family: helvetica;
padding: 2px;
margin: 2px;
width: 30px;
overflow: visible;
text-decoration: none;
text-align: center;
display: inline-block;
border-radius: 4px;
}
.k-font-icon {
font-family: KendoUIGlyphs;
font-style: normal;
font-weight: 400;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
I have an edit button, that i want to increase in size when the user hovers over it. It does however stay in line with the text, and doesnt expand equally on every side of the icon, it only expands in the right upper corner.
#quiznavn::after {
font-size: 10pt;
font-family: "FontAwesome";
content: "\f044";
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1em;
-webkit-font-smoothing: antialiased;
width: 1em;
display: inline-block;
margin-left: 10px;
margin-right: 5px;
color: black;
}
#quiznavn:hover::after {
font-size: 13pt;
font-family: "FontAwesome";
content: "\f044";
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1em;
-webkit-font-smoothing: antialiased;
width: 1em;
display: inline-block;
margin-left: 10px;
margin-right: 5px;
}
https://jsfiddle.net/kbw1yurh/
Use
transform:scale(1.5)
instead with transform-origin set to 50% 50%.
https://jsfiddle.net/foreyez/c17fjsx8/
note: if you're using this on iOS you made need to prefix this with -webkit-transform, -webkit-transform-origin, etc or it won't work.
I don't see this button you're referring to in your code, so I'll assume you have one.
.btn {
width: 120px;
height: 60px;
padding: 0;
font-size: 12pt;
display: table;
}
.btn span {
padding: 0;
vertical-align:middle;
display: table-cell;
width: 70px;
}
.btn span:nth-of-type(1) {
width: 30px;
}
.btn:hover i {
font-size: 17pt;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<button class="btn">
<span><i class="fa fa-user"></i></span><span>Click me!</span>
</button>
Why does firefox misplace the :before element??
<div id='remember_forgot' class='no_hl'>
<div>
<input id='remember_me' type='checkbox'>
<label for='remember_me'>Remember me</label>
</div>
</div>
* {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.3;
font-weight: normal;
}
input[type='checkbox'] {
display: none;
}
#remember_forgot {
display: flex;
align-items: center;
justify-content: space-between;
margin: 2px 0;
}
#remember_forgot>div {
position: relative;
display: flex;
align-items: center;
}
#remember_me+label:before {
position: relative;
top: 1px;
content: "";
display: block;
float: left;
width: 13px;
height: 13px;
margin-right: 4px;
font-size: 15px;
line-height: 0.8;
border: 1px solid black;
}
#remember_me:checked+label:before {
content:'✓';
color: black;
}
#remember_me+label {
display: inline-block;
margin-left: 0px;
color: black;
font-size: 13px;
}
#remember_me+label:hover {
color: #e1b941;
}
#remember_me,
#remember_me+label,
#forgot {
cursor: pointer;
}
#remember_me+label {
transition: 0.2s all;
}
All of the relevant code is here in the fiddle: http://jsfiddle.net/kjf8h5m6/7/
When I open it in chrome the checkbox :before element is properly centered:
But when it is viewed in firefox the checkbox looks like it is not centered:
This is very annoying.. please help!
(Left is chrome, right is firefox)
Removing the wildcard line-height: *{line-height:1.3;}, and adding a line-height of 1.5 to the label element solves this in both Firefox and Chrome.
Working fix: http://jsfiddle.net/kjf8h5m6/9/