1

How do I position the icon to the far right and keep the text on the left with Bootstrap.

Here's my effort so far: https://www.bootply.com/5E2CGFEWdx

<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="container">
  <div class="row">
    <button class="btn btn-lg btn-success col-xs-12"> Call Us <span class="glyphicon glyphicon-earphone push-right"></span></button>
  </div>
</div>

5 Answers 5

3

You can use float: right to make your image stick to the right, and set the text-align: left so the text will start at the left end.

Example here

align-left {
  text-align: left;
}

.push-right {
  float: right;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="container">
  <div class="row">
    <button class="btn btn-lg btn-success col-xs-12 align-left"> Call Us <span class="glyphicon glyphicon-earphone push-right"></span></button>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

6 Comments

Fantastic - this worked perfectly. Thank you so much.
I wouldn't recommend applying these changes to button in general (even less so since you're also using !important) , and changing what an actual Bootstrap class does (.push-right). This will have tons of unwanted side effects in any project with more than one developer working on it. Instead, create your own CSS class and use that for the necessary changes.
@connexo That's good advice. I'll be careful how I roll this snippet out. Thank you.
Content shouldn't be placed directly in row... "Content should be placed within columns, and only columns may be immediate children of rows."
Thanks guys, indeed it was quick and dirty.
|
3

You can reposition the span holding the icon and make it float: right;:

.container {
  margin-top: 25px;
}

.call-us {
  text-align: left !important;
}

.call-us span {
  float: right;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <button class="btn btn-lg btn-success col-xs-12 call-us"><span class="glyphicon glyphicon-earphone"></span>Call Us</button>
  </div>
</div>

Comments

1

Try following

<style>
button {text-align:left}
</style>

<div class="container">
  <div class="row">
    <button class="btn btn-lg btn-success col-xs-12"> Call Us <span class="glyphicon glyphicon-earphone pull-right"></span></button>
  </div>
</div>

Comments

1

use pull-left, pull-right utility classes

<html>
<head>

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">

</head>
<body>

<div class="container">
  <div class="row">
    <button class="btn btn-lg btn-success col-xs-12">
      <span class="pull-left">Call Us</span>
      <i class="glyphicon glyphicon-earphone pull-right"></i>
    </button>
  </div>
</div>

</body>
</html>

Comments

1

In bootstrap 4 just need to use default float-right and text-left css classes like following:

<button type="button" class="btn text-left"> 
<span class="float-right"><i class="fas fa-question"></i></span> ClickMe &nbsp;
</button>


Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.