Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS Text align on small button

  • Thread starter Deleted member 2829
  • Start date
D

Deleted member 2829

Guest
I'm struggling to get a tiny button on my page to look exactly the way I want it to. Unfortunately I'm one of these OCD types who cannot rest before everything is absolutely pixel-perfect šŸ¤£.
The button has the text X and I want the X to fit snugly inside the area. Initially I had this styling
CSS:
#btnclearfilter
{
    width               : 19px;
    height              : 19px;
    font-size           : 19px;
    font-weight         : bold;
    color               : red;
}
but then the button X is half outside the button both horizontally and vertically. I've done much experimenting, using any number of CSS tips I could find, but the best I could achieve is this:

CSS:
#btnclearfilter
{
    width               : 19px;
    height              : 19px;
    font-size           : 19px;
    font-weight         : bold;
    color               : red;
    padding-left        : 0px;
    padding-top         : 0px;
}

which looks as follows

a.jpg

The padding-left : 0px; nicely fits the X horizontally, but the padding-top : 0px; doesn't do as much - only shifts the X a few pixels upward.
Damn, this is annoying. Any ideas would be appreciated !
 
Solution
If you will add this two lines it will align the X vertically. Don't know you want to use it or not -
CSS:
display: inline-flex;
align-items: center;
CSS:
#btnclearfilter
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width               : 19px;
    height              : 19px;
    font-size           : 19px;
    font-weight         : bold;
    color               : red;
}
If you will add this two lines it will align the X vertically. Don't know you want to use it or not -
CSS:
display: inline-flex;
align-items: center;
CSS:
#btnclearfilter
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width               : 19px;
    height              : 19px;
    font-size           : 19px;
    font-weight         : bold;
    color               : red;
}
 
Solution
If you will add this two lines it will align the X vertically. Don't know you want to use it or not -

CSS:
#btnclearfilter
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width               : 19px;
    height              : 19px;
    font-size           : 19px;
    font-weight         : bold;
    color               : red;
}

That is great, many thanks !!

First, I found the font also matters. After changing it, things were a little better but not good enough. Your suggestions (those were things I had NOT tried yet) made it almost perfect. Adding a little top padding and slightly decreasing the font size made it perfect:

a.jpg

Final styling:

CSS:
#btnclearfilter
{
    width               : 19px;
    height              : 19px;
    font-family         : arial;
    font-size           : 18px;
    font-style          : normal;
    font-weight         : bold;
    color               : red;
    background-color    : white;
    display             : inline-flex;
    align-items         : center;
    justify-content     : center;
    padding-top         : 3px; 
}

Ha ! Everything pixel perfect !! I can die a happy man now šŸ˜„

But sheesh, there's enough CSS styling options (justify, align, center, flex, padding, margin...) to make me dizzy. In hindsight, finding a suitable background image would have been less hassle šŸ™„
 

Buy us a coffee!

Back
Top Bottom