Change long NavBar Bootstrap 4


Hello very good I am doing a website and I need to change the length of a navbar. By default the navbar occupies 100% of the screen in length but I want it to have a length of 900px I was trying to modify the bootstrap css for the navbars but not achieve anything. This is my HTML code. The CSS is the bootstrap does not personalize anything yet.

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
    <div class="navbar-nav">
      <a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="nav-item nav-link" href="#">Store</a>
      <a class="nav-item nav-link" href="#">About</a>

I hope you can help me. Thank you very much

asked by Joaquin Gonzalez 23.11.2018 в 21:59

1 answer


If you add the width 900px! important style it shrinks it and if you put it on margin: auto! important centers it

When you run the example click on see full screen so you see how it looks.

Change the class to @media so that it runs only when the page measures more than 900px wide, dsp changes to tablet / mobile menu

<!DOCTYPE html>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">
	<title>JS Bin</title>

	@media only screen and (min-width: 900px) {
			width: 900px !important; 
			margin: auto !important;

<link rel="stylesheet" href="" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<nav class="navbar navbar-expand-lg navClass navbar-dark bg-dark">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
  <li class="nav-item active">
    <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  <li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <div class="dropdown-divider"></div>
      <a class="dropdown-item" href="#">Something else here</a>
  <li class="nav-item">
    <a class="nav-link disabled" href="#">Disabled</a>
<form class="form-inline my-2 my-lg-0">
  <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
  <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>

  <script src="" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
answered by 23.11.2018 / 22:10