-1

I need a div with 70px. But if you inspect this element, it has 64px. In my app, the green div is a sidebar with js animation. I need to "push" the content (it has 100% of width).

.parent {
  display: flex;
  width: 100%;
  background: rgba(0,0,0,.2);
}
<div class="parent">  
  <div style="width:70px; background: green; height: 50px"></div>
  <div style="width: 100%; background: rgba(0,0,0,.4)">a</div>
</div>

how can i have 70px on green div?

Adrián
  • 175
  • 9

2 Answers2

2

Add flex-shrink: 0; to the element that shouldn't become smaller:

.parent {
  display: flex;
  width: 100%;
  background: rgba(0,0,0,.2);
}
<div class="parent">  
  <div style="width:70px; background: green; height: 50px; flex-shrink: 0;"></div>
  <div style="width: 100%; background: rgba(0,0,0,.4)">a</div>
</div>
Johannes
  • 64,305
  • 18
  • 73
  • 130
1

Remove the 100% width on the second div and replace with flex:1

.parent {
  display: flex;
  width: 100%;
  background: rgba(0,0,0,.2);
}
<div class="parent">  
  <div style="width:70px; background: green; height: 50px"></div>
  <div style="flex:1; background: rgba(0,0,0,.4)">a</div>
</div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161