Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making a webpage using both bootstrap and my own styles for css. When I try to change some of my styles, bootstrap seems to override some of them, such as removing line from nav bar or making the nav bar be full width.

This is my html:
HTML
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>Cuppela</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="css/index.css" type="text/css">

</head>
<body>
        <h1>Test</h1>
        <div id="main_nav">
        <div class="container-fluid" id="menu_container" style="max-width:100%;">
            <nav id="menu">
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Shop</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
            </nav>
        </div>
        </div>
</body>
</html>


This is my css:
CSS
h1{
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    text-align:center;
    font-size: 85px;
    color: black;
  }

body{
  margin: 0px;
}

#main_nav {
 background-color: #333;
}

nav ul {
  margin: 0;
  padding: 0;
  text-align: center;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
}

li {
  float: left;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover {
  background-color: #ff9900;
}


What I have tried:

I tried the workaround from I am currently using the solution from: Bootstrap 4: How to have a full width navbar with the content in a container (Like the SO Navbar)?[^] to make the nav into a full width.
Posted
Updated 19-Aug-21 21:42pm
v2

1 solution

I can't access the Cuppela page unfortunately, but I would suggest the problem lies in the choices of class being used. container-fluid is designed to fill 100% of the width of the container it's placed in, and you're wrapping the this with a div element with no width description. It means your <div id="main_nav"> isn't going to automatically fill the width of the screen, so your child container-fluid isn't going to either.

You can actually combine container and container-fluid to achieve what appears on StackOverflow. Simply have the container-fluid be the outer element (which will fill the screen width to 100%), and then have a child container inside it which will have the restricted width:
HTML
<div class="container-fluid bg-light">
  <nav class="container navbar">
    <a class="navbar-brand">
      Hello world
    </a>
    <ul class="navbar-nav ml-auto">
      <li class="nav-item">
        <a class="nav-link">Home</a>
      </li>
    </ul>
  </nav>
</div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900