Проблема с отталкивающим элементом CSS

Как сделать так чтоб синий элемент который находится слева открывался направо а синий элемент который находится справа - открывался налево,при это чтоб они друг друга не скидывали вниз и не меняя ширину .container

#wrap {
  position: relative;
  display: inline;
  cursor: pointer;
}

#front, #back {
  position: relative;
  display: block;
  float: left;
  width: 150px;
  height: 200px;
}

#front {
  background: #ed1c24;
  z-index: 10;
}

#back {  
  background: #00a2e8;
  color: #fff;
  transform: translateX(-100%);
  transition: all 0.3s ease;
  z-index: 1;
}

#wrap:hover #back {
  transform: translateX(5px);
}

#wrap2 {
  position: relative;
  display: inline;
  cursor: pointer;
}

#front2, #back2 {
  position: relative;
  float: right;
  width: 150px;
  height: 200px;
}

#front2 {
  background: #ed1c24;
  z-index: 10;
}

#back2 {  
  background: #00a2e8;
  color: #fff;
  transform: translateX(100%);
  transition: all 0.3s ease;
  z-index: 1;
  position:relative;
}

#wrap2:hover #back2 {
  transform: translateX(5px);
}

.container{
  width: 480px;
  height: 200px;
  background:black;
}
 <div class="container">      
      <div id="wrap">
        <div id="front"></div>
        <div id="back"></div>
      </div>
    
     <div id="wrap2">
        <div id="front2"></div>
        <div id="back2"></div>
  </div> 
</div>


Ответы (2 шт):

Автор решения: Проста Miha

Вот прошу, надеюсь помог

body{
    margin: 0;
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .block{
    position: relative;
    width: 250px;
    height: 350px;
  }

  .left-block:hover .block-overlay-left{
    transform: translateX(100%);
  }

  .right-block:hover .block-overlay-right{
    transform: translateX(-100%);
  }

  .red-block{
    background-color: red;
  }

  .center-block{
    background-color: black;
    z-index: -2;
  }

  .block-overlay{
    transition: .5s;
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: royalblue;
    z-index: -1;
    text-align: center;
  }
<div class="block left-block red-block">
  <div class="block-overlay block-overlay-left">
    <p>Текст</p> 
  </div>
</div>
<div class="block center-block"></div>
<div class="block right-block red-block">
  <div class="block-overlay block-overlay-right">
    <p>Текст</p>  
  </div>
</div>

→ Ссылка
Автор решения: novvember

Попробуйте изначально расположить блоки через флексы, а не через флоат. А наложение делать через абсолютное позиционирование.

.container{
  width: 480px;
  height: 200px;
  
  background: black;
  
  display: flex;
  justify-content: space-between;
}

.wrap {
  position: relative;
  cursor: pointer;
  
  width: 150px;
  height: 200px;
}

.wrap-1:hover .back-1 {
  transform: translateX(100%);
}

.wrap-2:hover .back-2 {
  transform: translateX(-100%);
}

.front {
  position: relative;
  z-index: 1;
  
  width: 100%;
  height: 100%;
  
  background: #ed1c24;
}

.back {  
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  
  width: 100%;
  height: 100%;
  
  background: #00a2e8;

  transition: all 0.3s ease;
}
 <div class="container">      
      <div class="wrap wrap-1">
        <div class="front front-1"></div>
        <div class="back back-1"></div>
      </div>
    
     <div class="wrap wrap-2">
        <div class="front front-2"></div>
        <div class="back back-2"></div>
  </div> 
</div>

→ Ссылка