0

I've mocked up my problem using codepen, but each of the elements within are React components so I don't want to reduce them. I'm struggling to display my progress-container on an equal level, but to the left of the input-wrapper (input).

Codepen: https://codepen.io/simoncunningham/pen/mdwMgyL

<div class="progress-container"></div>
<div class="input-wrapper">
  <div class="input">I have my first input here</input>
</div>
.progress-container {
  height: 22px;
  width: 22px;
  margin-right: 16px;
  background-color: red;
  display: flex;
}

.input-wrapper {
  border: 1px solid #ced4da;
  border-radius: 2px;
  overflow-y: hidden;
  padding: 0.375rem 1.75rem 0.375rem 0.75rem;
}
cts
  • 908
  • 1
  • 9
  • 30

2 Answers2

4

You can wrap the 2 div's in another div with a class of wrapperDiv:

<div class="wrapperDiv">
  <div class="progress-container"></div>
  <div class="input-wrapper">
    <div class="input">I have my first input here</input>
  </div>
</div>

Then you can define the wrapperDiv class as follows which will make them side by side:

.wrapperDiv {
  display: flex;
  flex-direction: row;
  align-items: center;
}

These css properties represent flexbox layout, in case you want to read more about it.

Dušan
  • 269
  • 1
  • 11
Zoha Malik
  • 469
  • 1
  • 7
  • 19
1

I can propose two solutions either using the floating or display:flex, but in my opinion if you can use the Flex solution is better.

1- Floating

.progress-container {
  height: 22px;
  width: 22px;
  margin-right: 16px;
  background-color: red;
  display: flex;
  /*edit*/
  float:left;
}

.input-wrapper {
  border: 1px solid #ced4da;
  border-radius: 2px;
  overflow-y: hidden;
  padding: 0.375rem 1.75rem 0.375rem 0.75rem;r: red;
  display: flex;
  /*edit*/
  float:left;
  clear; both;
}
<div class="progress-container"></div>
<div class="input-wrapper">
  <div class="input">I have my first input here</input>
</div>

2- Flex: you have to add a div as parent to wrap your two div.

.progress-container {
  height: 22px;
  width: 22px;
  margin-right: 16px;
  background-color: red;
  display: flex;
}

.input-wrapper {
  border: 1px solid #ced4da;
  border-radius: 2px;
  overflow-y: hidden;
  padding: 0.375rem 1.75rem 0.375rem 0.75rem;
}

/*edit*/
.parent-div{
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
}
<div class="parent-div">
  <div class="progress-container"></div>
  <div class="input-wrapper">
    <div class="input">I have my first input here</input>
  </div>
</div>
Fahmi B.
  • 758
  • 2
  • 10
  • 23