How to make a search box expand and overflow other content

42 Views Asked by At

I have this search box which is expanding when activated. However, I would like to make the search box overflow other content on the page.

The search box is inside a Bootstrap column - how can I make it expand break out of it?

.search-area {
  transition: all .3s ease-in;
  width: 3rem
}

.search-area:focus-within,
.search-area:hover {
  width: 100%;
}

.page-searchform {
  position: relative
}

.header-search {
  padding-right: 2rem;
  border: 0;
  background-color: #fff;
}

.header-search-btn {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
}


/* Presentation onæly */

.row {
  background: #f8f9fa;
  margin-top: 20px;
}

.col {
  padding: 10px;
  border: 1px solid #ccc;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">

<div class="container">
  <div class="row">
    <div class="col col-10">
      Column 1 - Make search input overflow me!
    </div>
    
    <div class="col d-flex justify-content-end align-self-center">
      <div class="search-area">
        <form class="page-searchform" action="" method="get">
          <label for="headerSearch" class="visually-hidden"></label>
          <input name="" id="headerSearch" class="header-search form-control" type="search" placeholder="Search...">
          
          <button class="btn header-search-btn" type="submit" id="headerSearchBtn">Go
          </button>
        </form>
      </div>
    </div>
  </div>
</div>

JsFiddle here.

1

There are 1 best solutions below

1
Squirrl On BEST ANSWER

Try using position:absolute and right:0?

.search-area:hover .header-search{
   transition: all .3s ease-in;
    width: 500px;
}

.header-search {
  padding-right: 2rem;
  border: 0;
  background-color: red;
  position:absolute;
  right:0;
  width: 100px;
}

https://jsfiddle.net/23c94ftw/16/