0

I made a search box with CSS grid that shrinks when you shrink the page. But, for some reason, it won't shrink as much as it I think it should be able to.

Here is how it looks fully extended:

enter image description here

Here is how it looks shrunken down:

enter image description here

How could I make the width of the search bar shrink down enough with the page so that the search button doesn't switch to the buttom?

Navbar.js

import React from 'react';
import { BsFillPersonFill } from 'react-icons/bs';
import { FiMail } from 'react-icons/fi';
import { FaPlus, FaSearch } from 'react-icons/fa';
import { AiTwotoneBell } from 'react-icons/ai';
import './navbar.css';
function Navbar() {
  return (
    <nav id="nav-bar">
      <div className="container">
        <h2 className="homeBtn">VIZZEY</h2>
        <div className="search">
          <input type="search" className="form-control" />
          <button className="searchBtn">o</button>
        </div>
        <ul className="ugh-buttons">
          <li className="btn">
            <button className="icon-btn">lol</button>
          </li>
          <li className="btn">
            <button className="icon-btn">lol</button>
          </li>
          <li className="btn">
            <button className="icon-btn">lol</button>
          </li>
          <li className="btn">
            <button className="icon-btn">lol</button>
          </li>
        </ul>
      </div>
    </nav>
  )
}
export default Navbar;

Navbar.css

* {
    margin: 0;
} 

ul {
    list-style: none; 
    display: flex;
} 

a {
    text-decoration: none; 
    color: #fff;
} 

.homeBtn {
    height: 55px; 
    text-align: center; 
    justify-content: center; 
    padding: auto; 

}

#nav-bar {
    background-color: #888888;
    overflow: hidden;
} 

.container {
    display: grid; 
    grid-template-columns: 1fr 6fr 1fr;
    align-items: center;
} 

ul li a {
    padding: 1.6rem;
    font-weight: bold;
}

.form-control {
    background-color: rgb(255, 255, 255); 
    border-color: rgb(133, 133, 133);  
    border-top-left-radius: 5px !important;
    border-bottom-left-radius: 5px !important; 
    height: 38px; 
    width: 90%;
    flex: auto;
    border: none; 
    padding-left: 10px;  
    justify-content: center;
}   

.homeBtn {
    background-color: #00ce7f;
} 

.search {
  padding-left: 10px; 
}
.btn { 
    padding-right: 10px; 
} 

.ugh-buttons {
margin-right: 10px;
}

.icon-btn {
    height: 40px; 
    width: 40px; 
    border-radius: 5px; 
    background-color: #00ce7f;
    color: white; 
    border: none; 
    padding-left: 5px;
}

button:active {
    outline: none !important;
    box-shadow: none !important; 
    background-color: rgb(111, 0, 255);
} 

button:active {
    outline: none !important;
    box-shadow: none !important; 
    background-color: rgb(111, 0, 255);
} 

button:focus {
    outline: none !important;
    box-shadow: none !important; 
}

button:hover {
    cursor: pointer;
} 

.searchBtn {
    color: #fff;
    background-color: #00ce7f;
    height: 38px; 
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px; 
    width: 40px;   
    border: none;  
    font-weight: bold;
}       

.buttons {
    color: #fff;
    background-color: #00ce7f;
    height: 38px; 
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px; 
    border-top-left-radius: 5px; 
    border-bottom-left-radius: 5px; 
   text-align: center;
    width: 40px;   
    border: none; 
    font-size: large; 
    font-weight: bold;
}
 
[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

input {
    outline: none;
}

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Cole
  • 35
  • 7
  • Hard to say exactly without a runnable example. But sometimes the `input` element has a `min-width` property set. – Emiel Zuurbier Feb 20 '21 at 22:46
  • 1
    @EmielZuurbier Is there a quick way I can make it a runnable example? Im a newby – Cole Feb 20 '21 at 22:48
  • Since it's a react app you could either use a [codesandbox](https://codesandbox.io/s/new) or create a [stack-snippet](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) to keep the code on the page. The latter has preference, but the former might be more familiar to set up. Otherwise, linking to a live example can be acceptable as well. – Emiel Zuurbier Feb 20 '21 at 23:39
  • Possibly a duplicate of this post: https://stackoverflow.com/q/42421361/3597276 – Michael Benjamin Feb 21 '21 at 17:14

1 Answers1

0

Try adding display: flex on the .search rule:

* {
  margin: 0;
}

ul {
  list-style: none;
  display: flex;
}

a {
  text-decoration: none;
  color: #fff;
}

.homeBtn {
  height: 55px;
  text-align: center;
  justify-content: center;
  padding: auto;

}

#nav-bar {
  background-color: #888888;
  overflow: hidden;
}

.container {
  display: grid;
  grid-template-columns: 1fr 6fr 1fr;
  align-items: center;
}

ul li a {
  padding: 1.6rem;
  font-weight: bold;
}

.form-control {
  background-color: rgb(255, 255, 255);
  border-color: rgb(133, 133, 133);
  border-top-left-radius: 5px !important;
  border-bottom-left-radius: 5px !important;
  height: 38px;
  width: 90%;
  flex: auto;
  border: none;
  padding-left: 10px;
  justify-content: center;
}

.homeBtn {
  background-color: #00ce7f;
}

.search {
  padding-left: 10px;
  display: flex;             /* added */
}

.btn {
  padding-right: 10px;
}

.ugh-buttons {
  margin-right: 10px;
}

.icon-btn {
  height: 40px;
  width: 40px;
  border-radius: 5px;
  background-color: #00ce7f;
  color: white;
  border: none;
  padding-left: 5px;
}

button:active {
  outline: none !important;
  box-shadow: none !important;
  background-color: rgb(111, 0, 255);
}

button:active {
  outline: none !important;
  box-shadow: none !important;
  background-color: rgb(111, 0, 255);
}

button:focus {
  outline: none !important;
  box-shadow: none !important;
}

button:hover {
  cursor: pointer;
}

.searchBtn {
  color: #fff;
  background-color: #00ce7f;
  height: 38px;
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
  width: 40px;
  border: none;
  font-weight: bold;
}

.buttons {
  color: #fff;
  background-color: #00ce7f;
  height: 38px;
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
  text-align: center;
  width: 40px;
  border: none;
  font-size: large;
  font-weight: bold;
}

[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

input {
  outline: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<nav id="nav-bar">
  <div class="container">
    <h2 class="homeBtn">VIZZEY</h2>
    <div class="search">
      <input type="search" class="form-control" />
      <button class="searchBtn">o</button>
    </div>
    <ul class="ugh-buttons">
      <li class="btn">
        <button class="icon-btn">lol</button>
      </li>
      <li class="btn">
        <button class="icon-btn">lol</button>
      </li>
      <li class="btn">
        <button class="icon-btn">lol</button>
      </li>
      <li class="btn">
        <button class="icon-btn">lol</button>
      </li>
    </ul>
  </div>
</nav>
CodeNinja
  • 616
  • 4
  • 18