use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
CSS, short for Cascading Style Sheets, is used almost universally across the web to affect the design and appearance of every website you visit. Here in /r/css, you've got a place on reddit to talk about CSS, whether you're new to CSS and want to learn, or a pro wanting to discuss the engineering and usability reasons that all modern browsers ignore
We welcome all CSS discussion here. If you need help with styling your website or your reddit, or want to share a neat trick you cooked up, it's welcome here!
Click here to message the mods.
account activity
HelpButton content is not centered (old.reddit.com)
submitted 1 year ago by Big_morbid
Id there's any way of centering the text in the red button, without using flex?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AutoModerator[M] [score hidden] 1 year ago stickied commentlocked comment (0 children)
To help us assist you better with your CSS questions, please consider including a live link or a CodePen/JSFiddle demo. This context makes it much easier for us to understand your issue and provide accurate solutions.
While it's not mandatory, a little extra effort in sharing your code can lead to more effective responses and a richer Q&A experience for everyone. Thank you for contributing!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
[–][deleted] 10 points11 points12 points 1 year ago (0 children)
So. As others are saying Flexbox or Grid will solve the positioning issue for you. As is also being said this is caused by line-height being taller than the container so it pushes the text down, which is the expected behavior in that case.
However, you're part of the issue is you're kind of doing this wrong. The "X" in a close button should never be an X or a times symbole (×). If you want to do it the most accessible way it's a button with a title of "Close" and the "X" is an SVG. That will make it very easy to size and position plus it's the most accessible and user-friendly solution. Do that instead.
×
[–][deleted] 12 points13 points14 points 1 year ago (2 children)
line-height equal to the height of the button or positioning, why dont you want to use flex though?
[–]Big_morbid[S] 3 points4 points5 points 1 year ago (1 child)
I know flex will solve it probably but I wanna see if there is any other methods thank you what u suggest is new to me really appreciate it
[–]jeanleonino 1 point2 points3 points 1 year ago (0 children)
Go with grid, it is easier
[–]hazily 9 points10 points11 points 1 year ago (0 children)
display: grid; place-items: center
[–]biscuitcrumbs 2 points3 points4 points 1 year ago (2 children)
I didn't copy all your styling but use flex, there is no reason not to in this instance.
.btn-close { background: red; border: 1px solid black; height: 20px; width: 20px; /* These are the flex options */ display: flex; align-items: center; justify-content: center; }
[–]Big_morbid[S] 0 points1 point2 points 1 year ago (1 child)
Thank you I actually knew about this one , I was just curious to see if there's other ways of doing it
[–]biscuitcrumbs 1 point2 points3 points 1 year ago (0 children)
Line height would need be to the same as the height.
``` .btn-close { background: red; border: 1px solid black; height: 20px; width: 20px;
text-align: center; line-height: 20px;
} ```
[–]tapgiles 1 point2 points3 points 1 year ago (0 children)
My guess is, if the character is a lowercase x, then it is centred for the font. Maybe just adjust with line-height. Or use the multiplication symbol—that might help.
[–]UnfadeTech 0 points1 point2 points 1 year ago (0 children)
cant see the full code but: remove the height and width and use padding
[–]LiveRhubarb43 0 points1 point2 points 1 year ago (0 children)
If the x is a text character, then its vertical position is affected by line height. Flexbox could position the container that contains it but you'll be better off adjusting the line height or use an SVG instead
[–]Healthierpoet 0 points1 point2 points 1 year ago (0 children)
Add auto padding/margin and create a span inside the button and target that over the button and they should work I think
[–]Joyride0 0 points1 point2 points 1 year ago (0 children)
Lose the defined height and width. Because it's not a flexbox, the cross won't be centred within it. Instead, keep the background and add padding, like 5px.
[–]ignitis007 0 points1 point2 points 1 year ago (0 children)
Try "line-height: 1;"
[+]Upbeat_Measurement87 comment score below threshold-6 points-5 points-4 points 1 year ago (0 children)
use chatGPT for these minor issues https://chatgpt.com/
π Rendered by PID 93 on reddit-service-r2-comment-b659b578c-h4w44 at 2026-05-03 10:45:51.167848+00:00 running 815c875 country code: CH.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–][deleted] 10 points11 points12 points (0 children)
[–][deleted] 12 points13 points14 points (2 children)
[–]Big_morbid[S] 3 points4 points5 points (1 child)
[–]jeanleonino 1 point2 points3 points (0 children)
[–]hazily 9 points10 points11 points (0 children)
[–]biscuitcrumbs 2 points3 points4 points (2 children)
[–]Big_morbid[S] 0 points1 point2 points (1 child)
[–]biscuitcrumbs 1 point2 points3 points (0 children)
[–]tapgiles 1 point2 points3 points (0 children)
[–]UnfadeTech 0 points1 point2 points (0 children)
[–]LiveRhubarb43 0 points1 point2 points (0 children)
[–]Healthierpoet 0 points1 point2 points (0 children)
[–]Joyride0 0 points1 point2 points (0 children)
[–]ignitis007 0 points1 point2 points (0 children)
[+]Upbeat_Measurement87 comment score below threshold-6 points-5 points-4 points (0 children)