Center-aligned and responsive Bootstrap menu on the page

Could someone please spare a moment to assist me with a problem I am struggling to solve? I am in the process of developing a webpage for a local intermunicipal Football Association using Bootstrap, aiming for full mobile responsiveness.

The issue at hand is centered around aligning and ensuring that the menu/navbar (depicted in yellow) is both centered and equal in width to the header (displayed in blue). The desired outcome should resemble this: https://i.sstatic.net/sRxv8.jpg

However, my current display appears as follows: this: https://i.sstatic.net/XgLza.jpg

Specifically, the blue component needs to be 106px high while the yellow element should stand at 40px height.

In relation to the code snippet provided:

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  font-size: 16px;
  line-height: 1.42857143;
}

#glava {
  height: 106px;
  width: auto;
  background-color: #002d68;
  margin-top: 0px;
  margin-bottom: 0px;
  border: none;
  border-radius: 0px;
}

.navbar {
  margin-top: 0px;
  margin-bottom: 0px;
  border: none;
  border-radius: 0px;
  text-transform: uppercase;
  text-decoration: none;
}

.navbar-default {
  background-color: #ffff01;
  color: #002d68;
  height: 40px;
}

.glavni-meni {
  background-color: #ffff01;
}

.header-seznam {
  list-style-type: none;
  display: inline-flex;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<header id="glava">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-10 col-md-offset-2">
        <div class="col-md-3">
          <img src="img/logo-2.png" class="img-responsive" alt="logotip" style="margin-top:12px; height:80px;">
        </div>
        <div class="col-md-7">
          <ul class="header-seznam">
            <li><img src="img/naslov.jpg" class="img-responsive" alt="logotip"></li>
            <li><img src="img/telefon.jpg" class="img-responsive" alt="logotip"></li>
            <li><img src="img/mail.jpg" class="img-responsive" alt="logotip"></li>
            <li><img src="img/podatki.jpg" class="img-responsive" alt="logotip"></li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</header>
<div class="navbar navbar-default navbar-custom">
  <div class="container-fluid glavni-meni">
    <button class="navbar-toggle" data-toggle="collapse" data- target="#mynavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    <div class="collapse navbar-collapse" id="mynavbar">
      <ul class="nav navbar-nav">
        <li><a href="">Competitions</a></li>
        <li><a href="">Clubs</a></li>
        <li><a href="">National Teams</a></li>
        <li><a href="">Grassroots</a></li>
        <li><a href="">Club Support</a></li>
        <li><a href="">Forms and Regulations</a></li>
        <li><a href="">Coaches and Referees</a></li>
        <li><a href="">Delegates</a></li>
        <li><a href="">Miscellaneous</a></li>
        <li><a href="">Benefits</a></li>
      </ul>
    </div>
  </div>
</div>

P.S.: Please forgive any errors in my English; it's not my native language.

Answer №1

Here is a sample code snippet demonstrating how to center navbar items.

HTML:

<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Brand Logo</a>
    </div>

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="pull-left"><a href="#">Dashboard</a></li>
        <li class="active"><a href="#">Stories</a></li>
        <li><a href="#">Videos</a></li>
        <li><a href="#">Photos</a></li>
        <li class="social pull-right"><a href="#">Social Links</a></li>
      </ul>
    </div>
  </div>
</nav>

CSS:

.navbar-nav {
    width: 100%;
    text-align: center;
    > li {
      float: none;
      display: inline-block;
    }
  }

Answer №2

Give this a shot:

Your HTML code:

<header id="glava">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-10 col-md-offset-2">
        <div class="col-md-3">
          <img src="img/logo-2.png" class="img-responsive" alt="logo" style="margin-top:12px; height:80px;">
        </div>
        <div class="col-md-7">
          <ul class="header-list">
            <li><img src="img/title.jpg" class="img-responsive" alt="logo"></li>
            <li><img src="img/phone.jpg" class="img-responsive" alt="logo"></li>
            <li><img src="img/email.jpg" class="img-responsive" alt="logo"></li>
            <li><img src="img/data.jpg" class="img-responsive" alt="logo"></li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</header>
<div class="navbar navbar-default navbar-custom navbar-centered">
  <div class="container-fluid main-menu">
    <button class="navbar-toggle" data-toggle="collapse" data-target="#mynavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    <div class="collapse navbar-collapse" id="mynavbar">
      <ul class="nav navbar-nav">
        <li><a href="">Competitions</a></li>
        <li><a href="">Clubs</a></li>
        <li><a href="">National Teams</a></li>
        <li><a href="">Grassroots</a></li>
        <li><a href="">Club to Club</a></li>
        <li><a href="">Forms and Regulations</a></li>
        <li><a href="">Coaches and Referees</a></li>
        <li><a href="">Delegates</a></li>
        <li><a href="">Miscellaneous</a></li>
        <li><a href="">Benefits</a></li>
      </ul>
    </div>
  </div>
</div>

CSS styles:

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  font-size: 16px;
  line-height: 1.42857143;
}

#glava {
  height: 106px;
  width: auto;
  background-color: #002d68;
  margin-top: 0px;
  margin-bottom: 0px;
  border: none;
  border-radius: 0px;
}

.navbar {
  margin-top: 0px;
  margin-bottom: 0px;
  border: none;
  border-radius: 0px;
  text-transform: uppercase;
  text-decoration: none;
}

.navbar-default {
  background-color: #ffff01;
  color: #002d68;
  height: 40px;
}

.main-menu {
  background-color: #ffff01;
}

.header-list {
  list-style-type: none;
  display: inline-flex;
}

@media (min-width: 768px) {
    .navbar-centered .navbar-nav {
        float: none;
        text-align: center;
    }
    .navbar-centered .navbar-nav > li {
        float: none;
    }
    .navbar-centered .nav > li {
        display: inline;
    }
    .navbar-centered .nav > li > a {
        display: inline-block;
    }
} 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamic template in a Vue.js component, such as an event handler for instance

If I create a component named "test" and add it to my HTML like this: <test :data="foo"></test> How can I make sure that the on-click attribute value changes into the property value 'data'? Vue.component('test', { props: ...

Erase text input field without relying on Jquery or directly manipulating the HTML element

My current project involves implementing a textbox that will display autocomplete options once the user starts typing. I want the textbox to clear itself when the user selects one of these autocomplete options after entering at least three characters. The ...

How to align the "bootstrap navbar li items" in the center across all page widths

I'm trying to center the li items "on the entire page width" in this basic bootstrap navbar that I've shared. I attempted using "justify-content-center" in the parent. It did center the navbar items, but not across the entire page width. The ite ...

What is the best way to vertically align elements in HTML, CSS, and Bootstrap?

https://i.sstatic.net/rhWmI.png Vertical alignment is required for all the bold fields. Below is the code snippet I attempted: If there is overflow in text (non-bold), it should display as ... I made attempts with CSS and bootstrap. ...

Navbar toggler button is toggling open but failing to close afterwards

Below is my code featuring a collapsible navbar. The toggler button successfully opens the menu, but it fails to close it: <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" dat ...

Change the content of a selectbox dynamically with the help of jQuery and AJAX

Currently, I am exploring the best approach for a specific challenge: I have various categories, subcategories, sub-subcategories, and so on, that I need to display in separate select boxes. For instance, initially, the options may look like this: <sel ...

Utilizing Cpanel to trigger the loading of PHP content upon button click

I have designed a custom template for a cpanel business website. I am looking to implement functionality where clicking the "Add product" button loads another PHP file into the gray area on the page. This gray area is represented by a div element. Is there ...

Using jQuery and Ajax to populate a dropdown menu with options

I'm currently working on an ajax call function that successfully fills a drop-down list with data from a specific URL. However, I am looking to modify the function so that it can receive variables in order to populate the drop-down list dynamically. ...

Unable to transfer a value from a CGI script back to an HTML form

When working with an HTML form that has a date field named cdt, I encountered the need to retain the date value when submitting data to an Oracle table through a CGI script. To achieve this, instead of using Javascript code like history.go(-1), I aimed to ...

What is the best way to display multiple quotes from my generator at once?

I'm seeking assistance with my quote generator. It functions correctly in JS Bin, generating the specified number of quotes when output to the console log. However, once integrated into an HTML page, it only generates one quote regardless of user inpu ...

Animate custom scrollbars with jQuery for a unique browsing experience

I am experimenting with creating a scrolling animation using mCustomScrollbar Currently, I have managed to obtain the current scrollTop and animate it to a specific height using the code below: $("#content").mCustomScrollbar({ scrollButtons:{ ...

Handling click events for parent and child elements in Angular 5

In Angular5, Below is the code I am working with: <div (click)="abc()"> some content <button (click)="xyz()">Click</button> </div> When I click on the button, both methods are being called. I want only a sin ...

Trigger the animation of a Div element when the cursor hovers over a different Div

I am interested in creating an animation where one div moves when the mouse hovers over another div elsewhere on the page. Here is an example... CSS #blue-box { position:absolute; margin-left:50px; margin-top:50px; height:100px; width:100px; background-c ...

Experiencing issues with uploading a basic .html website using FileZilla

Currently attempting to launch a very basic website using the free webspace provided by my college. The webspace includes a www and a data folder - www for the website and data for regular data purposes. I have created a simple .html file with JS & CSS tha ...

Tips for formatting text in a way that allows it to flow down a page smoothly as the

Working within a CSS Grid setup, I have an image on the left and a block of text on the right. As I reduce the page width, both the image and text resize accordingly to fit the page width. However, once the width goes below 475px, the layout breaks and the ...

Round the mathematics and present it within a <div> element

I am working on a mortgage calculator and I need the final loan rate to be displayed rounded to two decimals. Is there a way to achieve this? I'm new to JS and I've learned about using Math.round(value*100)/100, but I'm not sure how to impl ...

"Enhancing User Experience with Bootstrap's Smooth Transition Effects for fadeIn() and fade

As someone who is new to html and JavaScript, I have the following html code: <div class="row" > <button class="..." id="button"> ... </button> <div class="..." id="box"> ... </div> </di ...

What is the best way to transform this into an HTML readable code?

While browsing through a template, I came across this code and I'm unsure of how to get it functioning. I've tried removing the comments, but unfortunately it doesn't seem to be working as expected. li.dropdown.navbar-cart ...

How to insert an image into a div element in HTML5

I have a basic div element shown below: <div class="avatar"> <img src="http://quickshare.my3gb.com/download/testpic.jpg" /> </div> (The original image size is 216 * 216 pixels) and the CSS I am using is as follows: .avatar { float: r ...

How come my donut graphs are sitting outside the box while all other types of charts are properly aligned?

I am encountering an issue with my charts where all of them are positioned in the center of a div when drawn by the user, except for the donut charts. They seem to be placed outside of the top-left corner instead. Can anyone provide insights as to why this ...