left

HTML left and right alignment elements

For this, I did this:

<table style="width:100%;">
 <tr>
    <td style="width:50%;text-align: left;">left</td>
    <td style="width:50%;text-align: right;">right</td>
  </tr>
</table>

How could I accomplish this in the simplest way (least markup) without using tables? I just want to align 2 elements with max left and right.

There are hundreds of two column layouts, but they are more aligned for the page layout and seem redundant.

+3
source share
2 answers

Some html:

<div class="left">left</div>
<div class="right">right</div>

Some CSS:

.left, .right {
  width: 50%; /* Floated elements technically need a width specified. */
}

.left {
  float: left;
}

.right {
  float: right;
}
+8
source

Something like that:

CSS

<style type="text/css">
#primary {
   width: 100%;
}

.secondary {
   width: 50%;
}

.leftcolumn {
   float: left;
   text-align: left;
} 

.rightcolumn {
   float: right;
   text-align: right;
}
</style>

HTML

<div id="primary">
   <div class="secondary leftcolumn">
      <p>This will be on the left</p>
   </div>
   <div class="secondary rightcolumn">
      <p>This will be on the right</p>
   </div>
</div>

Although I would change leftcolumnand rightcolumnfor something concrete for the content that each will contain (in favor of the semantic approach to CSS naming rather than structural).

+3
source

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


All Articles