Skip to content
Advertisement

Span text pushes other elements (buttons) to the right and left

I am trying to create an voting system for my website but am currently struggling with upvote and downvote counters styling. Here is how it looks right now:

enter image description here

As you can see, the problem is that whenever the number on the right or left side of the buttons gets large, it pushes other elements. I want the two buttons to stay in the center and the upvote counter to grow to the left, and downvote to the right. This way, everything will be centered.

Here is my current CSS code:

JavaScript

And my HTML code:

JavaScript

Thank you!

Advertisement

Answer

If you always want the buttons to be center and dont care about the numbers breaking into new lines for exceptionally large numbers, you can solve this by position: absolute quite easily:

JavaScript

And then wrapping the counters inside the buttons:

JavaScript

Extra changes: You can remove all text align/direction styles If this doesnt work properly you can try putting the icons in specific containers (Divs/spans) If the counters dont get an auto width (their width doesnt grow based on their content) you can calculate and give them a fixed value.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement