Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to display container that is centered with content that is in the far left and far right of it

I would like to display the price of an object on my html website. This is what I would like it to look like:

  1. Dynamic
  2. The container is centered on the page with a max width of 400px
  3. The "price" string is on the far left while the actual price is on the right of the centered content

This is what my html looks like:

<div class="price-container">
        <div class="price">price:</div>
        <div class="price-number">{{ event.price }}.00</div>
</div>

This is what my css looks like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.price-container{
   font-family: Montserrat;
   text-transform: uppercase;
   color: white;
   font-weight: 700;
   font-size: 20px;
   width: 90%;
   max-width: 400px;
}

.price{
   float: left;
}

.price-number{
   float: right;
}

>Solution :

If you want to center it horizontally, you need to add margin:auto. I also cleared the floats for you.

.price-container{
   font-family: Montserrat;
   text-transform: uppercase;
   color: black;
   font-weight: 700;
   font-size: 20px;
   width: 90%;
   max-width: 400px;
   margin: auto;
   border: 1px solid red;
}

.price{
   float: left;
}

.price-number{
   float: right;
}
<div class="price-container">
        <div class="price">price:</div>
        <div class="price-number">{{ event.price }}.00</div>
        <div style="clear:both"></div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading