Boky Boky - 22 days ago 5
CSS Question

Middle div take up remaining width

I have next html structure :

<div class="offerButtons">
<button type="reset" class="btnReset"><span> No </span></button>
<input type="text" class="offerInput" />
<button type="submit" class="btnSubmit"><span> Yes </span></button>
</div>


And my css is as follows :

.offerButtons {
display: table;
width: 100%;
background-color: yellow;
}

.btnReset, .btnSubmit {
border: 1px solid red;
border-radius: 50%;
width: 30px;
height: 30px;
display: table-cell;
text-align: center;
vertical-align: middle;
}

.btnReset span, .btnSubmit span{
color: red;
}

.offerInput {
height: 31px;
margin: 0 5px;
display: table-cell;
}


btnReset and btnSubmit have a fixed width. What I want is that those two buttons have fixed width and that the inout field takes the rest of the width.

I want to get something like :

enter image description here

But now, with this code, I get :

enter image description here

Any idea?

Here is jsfiddle

Answer

You can use css3 flexbox as well. Following css will make it like you want:

.offerButtons {
  align-items: center;
  display: flex;
  width: 500px;
}
.offerInput {
  flex-grow: 1;
}

.offerButtons {
  align-items: center;
  display: flex;
  width: 500px;
  background-color: yellow;
}

.btnReset, .btnSubmit {
  border: 1px solid red;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  text-align: center;
}

.btnReset span, .btnSubmit span{
  color: red;
}

.offerInput {
  height: 31px;
  text-indent: 15;
  margin: 0 5px;
  flex-grow: 1;
}
<div class="offerButtons">
  <button type="reset" class="btnReset"><span> No </span></button>
  <input type="text" class="offerInput" />
  <button type="submit" class="btnSubmit"><span> Yes </span></button>
</div>

However if you are not comfortable with flexbox here is another method that will work in almost most of the browsers.

.offerButtons {
  background-color: yellow;
  position: relative;
  padding: 0 40px;
}

.btnReset, .btnSubmit {
  transform: translateY(-50%);
  position: absolute;
  border: 1px solid red;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  left: 3px;
  top: 50%;
}
.btnSubmit {
  left: auto;
  right: 3px;
}

.btnReset span, .btnSubmit span{
  color: red;
}

.offerInput {
  height: 31px;
  display: block;
  width: 100%;
}
<div class="offerButtons">
  <button type="reset" class="btnReset"><span> No </span></button>
  <input type="text" class="offerInput" />
  <button type="submit" class="btnSubmit"><span> Yes </span></button>
</div>