Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9117391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:53:12+00:00 2026-06-17T04:53:12+00:00

This should be simple, but I’m having problems getting a robust solution. Basically I’m

  • 0

This should be simple, but I’m having problems getting a robust solution. Basically I’m trying to achieve this:

button examples

So, an element (a or button) with an icon right-aligned, using an icon font. I need to ensure that:

  1. The button can be any width
  2. Without an icon present, there is no excess padding on the button
  3. The text and icon always remain on the same line (don’t wrap)

Here’s the HTML:

<button class="btn">Download <span data-icon="+"></span></button>

And the (S)CSS:

.btn {
    margin: 0;
    padding: 3px 6px;
    vertical-align: middle;
    border: none;
    background-color: #535B99;
    color: white;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    text-transform: uppercase;
    [data-icon] {
        float: right;
        padding-left: 10px;
        &:before { content: attr(data-icon); }
    }
}

You can see this in a jsFiddle. The problem is, unless I add a width to the .btn class, the icon always drops a line. Absolute positioning would work, but then I’d fail to meet (2) above as it would require some padding. What am I missing?

EDIT

I missed one other criteria:

4.) At 100% width, the icon is aligned to the right (not next to the text)

So in some cases, it’ll look like:

100% width version

Which is why the float is necessary in my CSS.

SOLUTION

Based almost entirely on @Riskbreaker’s solution, here’s what I settled on:

<button data-button-icon="+" class="btn" href="#">Click Me :P</button>

.btn {
    display: inline-block;
    margin: 0 0 10px 0;
    padding: 3px 6px;
    border: medium none;
    background-color: #535B99;
    color: #FFFFFF;
    cursor: pointer;
    text-align: left;    
    text-decoration: none;
    white-space: nowrap;
    &:after {
      content: attr(data-button-icon);
      float: right;
      padding-left: 1em;
    }
}

Basically, abandoning the separate span and using just the button element, which has the benefit of less extraneous markup.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:53:13+00:00Added an answer on June 17, 2026 at 4:53 am

    Just take float:right out of [data-icon]

    DEMO

    If you need to be specific with width (Pixels or Percentages),… then yes you do need float: right so you then need an inner div to control both:

    <div>Create Advert HELLO YOU ALL <span aria-hidden="true" data-icon="+"></span></div>
    

    Demo with float:right

    As you can see I added width: 300px, and width: 100% works but this is more manual….this is construsively more manual(meaning being specific with your button)…but it works.

    So either no width/no float:right needed or add width/float:right needed.

    ================================================================================
    OK so your dilemma is you do not want to deal with dimensions, I made this not using your method but mines using no spans at all…this is my last suggestion:

    http://jsfiddle.net/Riskbreaker/st3m2/1/

    What you see here is the :before or :after(doesn’t matter which just as long as you have the right padding and float method) method is the best way to get this resolve and my class added the content: plus. Removing “add” class will make the button look right and adding 100% will always have the icon right 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this should be simple but I'm having issues getting it to
I feel this should be a simple solution but I'm having trouble finding anything
I think this should be simple but I am having some difficulty implementing it.
This should be simple, but I'm getting confused. I have a parent/child tables -
I have been having problems with this. I think this should be pretty simple
I'm sure this should be very simple - but I'm having trouble with context!
This should be simple but it's not working. I am trying to strip single
This should be simple but I can't find a solution: I have a custom
This should be really simple but I'm having trouble with it. How do I
This should be so simple but it's driving me crazy. I'm trying to insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.