Reputation: 167
I'm trying text-align: right
in my CSS, but text-align is not moving it for some reason. I want the website title left aligned and the icon right aligned on the same line. Here's what I am trying.
HTML
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<div class="top-container">
<h2>Website Title</h2>
<i class="fas fa-bars"></i>
</div>
CSS
body {
margin: 0;
}
.top-container {
padding: 20px;
margin: 0;
width: 100%;
color: rgb(255, 255, 255);
background-color: rgba(0, 0, 0, 0.75);
font-size: 2em;
font-weight: bold;
}
.top-container i {
color: red;
display: inline-block;
text-align: right;
}
.top-container h2 {
display: inline-block;
}
h2 {
margin-top: 10px;
}
Upvotes: 9
Views: 39434
Reputation: 7289
The display must be changed for text-align to apply
.myClass {
display: block;
text-align: right;
}
Upvotes: 0
Reputation: 1
Can use either pull-right or align-right or float-right
<a class="btn btn-lg btn-success" href="#">
<i class="fa fa-flag fa-2x pull-left"></i> Font Awesome<br>Version 4.7.0</a>
<a class="btn btn-default" href="#">
<i class="fa fa-align-right" title="Align Right"></i>
</a>
Upvotes: 0
Reputation: 1
Make a custom Id to the element --> <i class="fal fa-phone" id="customfa"></i>
Head to your CSS file and right these -->
#customfa{right: 10%;} You can use right, left , top and bottom attributes.
Upvotes: 0
Reputation: 447
* {
padding: 0;
margin: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.top-container {
position: relative;
background: #eaeaea;
width: 100%;
padding: 30px;
}
.top-container.float-style>h2 {
display: inline;
}
.top-container.float-style>i {
float: right;
line-height:26px;
}
.top-container.absolute-style > i {
position: absolute;
top: 50%;
right: 30px;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
z-index: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<div class="top-container float-style">
<h2>Website Title float style</h2>
<i class="fas fa-bars"></i>
</div>
<hr style="margin:30px 0px;">
<div class="top-container absolute-style">
<h2>Website Title absolute</h2>
<i class="fas fa-bars"></i>
</div>
Upvotes: 0
Reputation: 67748
text-align
will align the text within the element which you are assigning it to, which doesn't do anything in an inline-block
element like this (since that's just as wide as its contents). Use float: right;
instead of text-align: right
https://jsfiddle.net/s4a9sct9/1/
Upvotes: 8