Align the icon to the right in a table cell?

I have a simple table cell that contains text and an icon. I want to align the text on the left and the icon on the right. I tried it like this, but it will not work. The only solution I know is to create another one tdwhere I put the icon inside. But I want both the text and the icon in onetd

    table {
        border: 1px solid red;
    }

    td {
      border: 1px solid black;
      width: 200px;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
    <table>
    <tr>
    <td>Text <span align="right"><i class="fa fa-toggle-on"></i></span></td>
      <td>Test</td>
    </tr>
    </table>
Run codeHide result
+4
source share
6 answers

Try using

style="float:right;"

like this:

table {
    border: 1px solid red;
}

td {
  border: 1px solid black;
  width: 200px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<table>
<tr>
<td>Text <span style="float:right;"><i class="fa fa-toggle-on"></i></span></td>
  <td>Test</td>
</tr>
</table>
Run codeHide result

As in the comments on the website, the attribute is now deprecated. . So try to avoid this.

+8
source

    table {
        border: 1px solid red;
    }

    td {
      border: 1px solid black;
      width: 200px;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
    <table>
    <tr>
    <td>Text <span ><i class="fa fa-toggle-on pull-right"></i></span></td>
      <td>Test</td>
    </tr>
    </table>
Run codeHide result

This is the best way, I think ...

+2
source

, .

span {
    float: right;
}

:

table {
    border: 1px solid red;
}

td {
  border: 1px solid black;
  width: 200px;
}

td > span {
    float: right;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<table>
<tr>
<td>Text <span><i class="fa fa-toggle-on"></i></span></td>
  <td>Test</td>
</tr>
</table>
Hide result
+1

:

<style>
/*If not using bootstrap add this to you css*/
 .pull.right{
   float:right;
 }


 <table width="100%">
  <tr>
  <td>Text <span><i class="fa fa-toggle-on pull-right">      </i></span></td>
  <td>Test</td>
 </tr>
 </table>
+1

If you want them to be in the same td (without adding another for the icon), you can try the following:

<td>
  <div style="float:left;width:50%;">I stay at left</div>
  <div style="float:right;width:50%;">And I stay at right</div>
</td>
+1
source

add another class to your css

table i.fa{
    float: right;
}
+1
source

Source: https://habr.com/ru/post/1627408/


All Articles