-3

I have a div which have 2 child div, now what I want is enter image description here

  1. For the right child, it should display text at the most right side.
  2. For the left child, its content should be full in length until right content.

div is

<div class="FindInStoreLocation__store">
  <div class="FindInStoreLocation__store__name">
    <span class="Text-ds">Roosevelt Collection</span>
  </div>
  <div class="FindInStoreLocation__store__distance">
    <span class="Text-ds">1.2 miles</span>
  </div>
</div>

How can I write its Css with flex so that I can see content in one line like:

Roosevelt Collection.           1.2 miles

How I am getting it like enter image description here

Ashwani Panwar
  • 3,819
  • 3
  • 46
  • 66

2 Answers2

3

You can use justify-content: space-between; for the desired effect.

Read more about it here.

.FindInStoreLocation__store
{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  width: 100%;
  border: 1px solid black;
}
<div class="FindInStoreLocation__store">
  <div class="FindInStoreLocation__store__name">
    <span class="Text-ds">Roosevelt Collection</span>
  </div>
  <div class="FindInStoreLocation__store__distance">
    <span class="Text-ds">1.2 miles</span>
  </div>
</div>

EDIT:

I think what you want for mobile devices is to not break words between lines like:

Roosevelt           1.2
Collection        miles

but instead in one line itself.

What you need to do is use white-space property with value nowrap along with overflow: hidden.

.FindInStoreLocation__store
{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  width: 100%;
  border: 1px solid black;
  overflow: hidden;
  white-space: nowrap;
}
<div class="FindInStoreLocation__store">
  <div class="FindInStoreLocation__store__name">
    <span class="Text-ds">Roosevelt Collection</span>
  </div>
  <div class="FindInStoreLocation__store__distance">
    <span class="Text-ds">1.2 miles</span>
  </div>
</div>
kiner_shah
  • 3,939
  • 7
  • 23
  • 37
2

Add this CSS code:

.FindInStoreLocation__store{
    display: flex;
    justify-content: space-between;
    flex-direction: row;
}

Explanation:

Flex provides a layout that with other properties can help you create the layout you need. we set the flex-direction to row because we want both elements in a row and we set justify-content to space-between because it sets the maximum space that is available between the elements of the row.

  • Code without any explanation are rarely helpful. Stack Overflow is about learning, not providing snippets to blindly copy and paste. Please edit your question and explain how it answers the specific question being asked. See [How to Answer](https://stackoverflow.com/help/how-to-answer). – Sfili_81 Nov 22 '21 at 07:55
  • But still getting text `Roosevelt Collection` in two rows in mobile, I need in one row. – Ashwani Panwar Nov 22 '21 at 08:43
  • @AshwaniPanwar add this CSS: ```flex-direction: row``` It will put the elements in a row – Mohammad Afzali Nov 22 '21 at 09:06