How can I create even column with items in them left and right aligned

flexbox
css grid
flex order
css vertical-align
align text left and right on same line google docs
grid align-items
flexbox vertical-align
inline-flex

1) I'm creating a list of paragraphs(2 column count) that has item name and price in it. I want items to be left aligned and prices to be right aligned (trying to push the price span to the extreme right side of each paragraph tag).I

2)The columns are not aligning on top correctly. If you see there is a gap creating uneven column. How do I correct this?

.mainDiv {
  -webkit-column-count: 2;
  -moz-column-count: 2;
  column-count: 2;
  width: 650px;
  background-color: green;
  padding-top: 0;
}

.thetag {
  width: 300px;
  background-color: red;
}

.leftAlign {
  text-align: left;
}

.rightAlign {
  text-align: right;
}
<div class="mainDiv">
  <p class="thetag"><span class="leftAlign">Bread:</span><span class= "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Butter: </span><span class= "rightAlign"> $5</span></p>
  <p class="thetag"><span class="leftAlign">Milk: </span><span class= "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Pasta:</span><span class= "rightAlign"> $5</span></p>
  <p class="thetag"><span class="leftAlign">Banana:</span><span class= "rightAlign"> $2</span></p>
  <p class="thetag"><span class="leftAlign">Apple: </span><span class= "rightAlign"> $1</span></p>
  <p class="thetag"><span class="leftAlign">Broccoli:</span><span class= "rightAlign"> $4</span></p>
  <p class="thetag"><span class="leftAlign">Potato: </span><span class= "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Cucumber: </span><span class="rightAlign"> $4</span></p>
</div>

.mainDiv {
  column-count: 2;
  
    /* optional */
    background-color: #eee;
    padding: 1em;
}

.mainDiv > p {
  margin: 0 0 1em;
  display: flex;
  justify-content: space-between;
  break-inside: avoid;

    /* optional */
    background-color: #f8f8f8;
    border: 1px solid;
    border-color: #fff transparent #ddd;
    padding: 1em;
}

body {
  /* necessary on SO */
  margin: 0;
}
<div class="mainDiv">
  <p><span>Bread:</span><span> $3</span></p>
  <p><span>Butter: </span><span> $5</span></p>
  <p><span>Milk: </span><span> $3</span></p>
  <p><span>Pasta:</span><span> $5</span></p>
  <p><span>Banana:</span><span> $2</span></p>
  <p><span>Apple: </span><span> $1</span></p>
  <p><span>Broccoli:</span><span> $4</span></p>
  <p><span>Potato: </span><span> $3</span></p>
  <p><span>Cucumber: </span><span> $4</span></p>
</div>

How To Align Things In CSS, There are a few ways to align elements in CSS. remove that line-height or make it less than the size of the image and the the ability to align the items even if the browser does not have Flexbox: The Inline direction is the direction in which sentences run (so for English that is left to right horizontally). Achieving balance. To force Word to balance the columns, click at the end of the text and choose Insert | Break. In the Break dialog box (Figure C), select Continuous under Section Break Types and click OK. Figure D shows the effect on the sample document we looked at earlier.

Remove the top margin from the paragraphs and float the price to the right.

.mainDiv {
  -webkit-column-count: 2;
  -moz-column-count: 2;
  column-count: 2;
  width: 650px;
  background-color: green;
  padding-top: 0;
}

.thetag {
  width: 300px;
  background-color: red;
  margin: 0 0 1em
}

.leftAlign {
  text-align: left;
}

.rightAlign {
  float: right;
}
<div class="mainDiv">
  <p class="thetag"><span class="leftAlign">Bread:</span><span class="rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Butter: </span><span class="rightAlign"> $5</span></p>
  <p class="thetag"><span class="leftAlign">Milk: </span><span class="rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Pasta:</span><span class="rightAlign"> $5</span></p>
  <p class="thetag"><span class="leftAlign">Banana:</span><span class="rightAlign"> $2</span></p>
  <p class="thetag"><span class="leftAlign">Apple: </span><span class="rightAlign"> $1</span></p>
  <p class="thetag"><span class="leftAlign">Broccoli:</span><span class="rightAlign"> $4</span></p>
  <p class="thetag"><span class="leftAlign">Potato: </span><span class="rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Cucumber: </span><span class="rightAlign"> $4</span></p>
</div>

Left Half and Right Half Layout, Basically two equal height columns are needed inside of a container. Like many things in CSS, there are a number of ways to go about this and One simple way we can create the appearance of a changing background is to text-​align: center; Left Half. Weekends don't count unless you spend them doing something  The left and right item line up flush with the start and end. If the main axis is in the block direction because flex-direction is set to column , then justify-content will distribute space between items in that dimension as long as there is space in the flex container to distribute.

I would recommen turning your layout into flexboxes

By making .mainDiv a flex container, we can align the items in the wanted layout

.mainDiv {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

Then we turn .thetag items into flex containers so we can align the items and their prices

.thetag {
  width: 45%;
  background-color: red;
  display: flex;
  justify-content: space-between;
}

Hope this helps :)

.mainDiv {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.thetag {
  width: 45%;
  background-color: red;
  display: flex;
  justify-content: space-between;
}

.leftAlign {
  text-align: left;
}

.rightAlign {
  text-align: right;
}
<div class="mainDiv">
  <p class="thetag"><span class="leftAlign">Bread:</span><span class- "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Butter: </span><span class- "rightAlign"> $5</span></p>
  <p class="thetag"><span class="leftAlign">Milk: </span><span class- "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Pasta:</span><span class- "rightAlign"> $5</span></p>
  <p class="thetag"><span class="leftAlign">Banana:</span><span class- "rightAlign"> $2</span></p>
  <p class="thetag"><span class="leftAlign">Apple: </span><span class- "rightAlign"> $1</span></p>
  <p class="thetag"><span class="leftAlign">Broccoli:</span><span class- "rightAlign"> $4</span></p>
  <p class="thetag"><span class="leftAlign">Potato: </span><span class- "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Cucumber: </span><span class- "rightAlign"> $4</span></p>
</div>

How do you left-align and right-align items on the same line in a , Make sure you have View > Show ruler checked. In the ruler above your document, click where you want the right-most character of the right-aligned section to  I want to have something written in the top-left corner and top-right corners of my document. So I want some text aligned to the right, some to the left, at the same height. I could do it with spamming the space bar, but then if I change the font size or anything it will be broken again.

It is a good practice to add *{margin:0; padding:0;} on the top of your css file, so you don't see any unexpected spacing.

Now that will solve the issue, with some minor changes.

*{margin:0; padding:0;}
.mainDiv {

   -webkit-column-count: 2;
  -moz-column-count: 2;
  column-count: 2; 
  grid-gap:50px; /*equals to the difference between the sum of two elements minus the width of the parent: in your case (300+300)-650=50*/
  width:650px;
  background-color: green;
}

.thetag {
  width: 300px;
  background-color: red;
  margin-bottom:15px; // if you want some space between the items
}

.leftAlign {
  text-align: left;
}

.rightAlign {
  text-align: right;
}
<div class="mainDiv">
  <p class="thetag"><span class="leftAlign">Bread:</span><span class= "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Butter: </span><span class= "rightAlign"> $5</span></p>
  <p class="thetag"><span class="leftAlign">Milk: </span><span class= "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Pasta:</span><span class= "rightAlign"> $5</span></p>
  <p class="thetag"><span class="leftAlign">Banana:</span><span class= "rightAlign"> $2</span></p>
  <p class="thetag"><span class="leftAlign">Apple: </span><span class= "rightAlign"> $1</span></p>
  <p class="thetag"><span class="leftAlign">Broccoli:</span><span class= "rightAlign"> $4</span></p>
  <p class="thetag"><span class="leftAlign">Potato: </span><span class= "rightAlign"> $3</span></p>
  <p class="thetag"><span class="leftAlign">Cucumber: </span><span class="rightAlign"> $4</span></p>
</div>

How to Order and Align Items in Grid Layout, Order and Alignment Properties in CSS Grid Layout Module Grid auto-​placement algorithm as it automatically places different items. So, even though item D, without a definite row or column position, comes end aligns content to the right of the grid area; start aligns content to the left of the grid area  It can sometimes be useful to have some text be aligned to the left and some text be aligned to the right on the same line. For example, in a footer, where you might want to have copyright info on the left and webmaster info on the right.

CSS Box Alignment, The module aims to create a consistent method of alignment across .box { display: grid; width: 540px; grid-template-columns: 120px 120px 120px; align-​items: start; are aligning it to the physical dimensions of top, right, bottom and left. If you specify unsafe then the alignment will be honoured even if it  You need to set a width before you print out the name to get other things to line up after that. Something on this general order: cout << left << setw(15) << surname << setw(10) << empNumber << "\t" << setw(4) << hourlyRate << " "; I'd (at least normally) avoid trying to mix fixed-width fields with tabs as well.

Box alignment in CSS Grid Layout, The inline axis runs across the block axis, it is the direction in which text in regular inline flow runs. I can use the align-items property on the grid container, to align the .wrapper { display: grid; grid-template-columns: repeat(8, 1fr); by setting the right and left margin of the container block to auto , you  2 Answers 2. Regardless of the mix of types of data in one table, the data type in the individual column should drive the alignment. A quick look at a grid with mixed data on the Bloomberg site shows a good example. This grid shows a mixture of values, notice text is left aligned, numbers are right aligned.

How can text be justified on both the left and right sides of a line in , Yes! Make sure you can see the ruler at the top of the page; Click in the ruler to place a tab marker and then drag it over to the right hand side of your page. Can I change the column heading to be left-justified but leave the values contents of the data part of the column right-aligned? Yes. Just place the cell's contents in a \multicolumn{1}{l}{} "wrapper".

Comments
  • You are changing the display order of elements and that was not part of the requirement. See position of Butter in your code and its position in OP's example. Why do it when it was not required?
  • Thank you @AndreiGheorghiu added a second snippet