Align the logo in the center of the navbar with items placed on either side

Looking for a way to center my brand logo within my navbar with menu items positioned around it? Preferably without the use of javascript? I've tried different methods, including adjusting the Bootstrap navbar styling, but haven't found a perfect solution yet.

I attempted to center the brand by using CSS properties like:

.navbar-header {
float: left;
padding: 15px;
text-align: center;
width: 100%;
}

.navbar-brand {float: none;}

However, this only centers the brand without integrating it between the menu items as desired, instead stacking it on top of them.

I also explored the option of adding the logo directly to a menu item, which worked well on desktops but didn't look good on mobile devices due to its treatment as a regular menu item within the dropdown.

Examples of my attempts can be viewed here: http://www.bootply.com/114800 and http://www.bootply.com/114804.

Any suggestions on how to accomplish this design layout?

Answer №1

Success! I found a workaround that incorporates CSS to ensure functionality on mobile devices as well.

To begin, I inserted a menu item amidst the existing ones on my navigation bar:

<div class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li class="logo"><a href="#"><img src="img/logo.png"></a></li>
        <li><a href="#contact">Contact</a></li>
        <li><a href="#contact">Something</a></li>
      </ul>
</div><!--/.nav-collapse -->

Additionally, I retained the default brand logo in the bootstrap navbar while including the visible-xs class to ensure its appearance on smaller screens exclusively:

<a class="navbar-brand visible-xs" href="#"><img src="img/logo.png"></a>

Next, I crafted the following CSS rules to accommodate the changes. These adjustments hide the logo within the navigation bar and showcase the default branding instead:

@media (max-width: 768px) {
    .navbar-nav .logo {
        display:none;
    }
}

.navbar-nav .logo {
    opacity: 1;
    vertical-align: middle;
}

Answer №2

Below is an illustration of the CSS I employ for organizing 3 sections (with one section centered in the middle). If you opt for floating to achieve this layout, all elements must be floated so they are in relation to each other. I enclose these within a div with the class .blocky.

(UPDATE): I have included additional details to ensure proper centering. Technically, you could eliminate the right section class and just place the left and middle sections one after the other, but I previously used the right class to clear something. Feel free to experiment with it.

<div class="blocky">
     <div class="leftSection">
     </div>
     <div class="middleSection">
     </div>
     <div class="rightSection">
     </div>
</div>

Feel free to reach out if you require further clarification or if I can enhance the clarity of this explanation. By the way, the clears specified in the CSS are intended to prevent any unintended placement within this alignment. Additionally, the padding, margins, and width values can all be adjusted or even removed entirely in some cases.

.blocky
{
  overflow: auto;
  padding-right: 10px;
  margin-left: auto;
  margin-right: auto;
  float:none;
}
.leftSection
{
  float: left;
  width: 236px;
  padding-left: 10px;
  padding-right: 10px;
  margin-bottom:20px;
  margin-top: 5px;
  clear: left;
 }

.rightSection
{
  float: right;
  width: 236px;
  margin-bottom:20px;
  margin-top: 5px;
  clear:right;
}

.middleSection
{
  float: left;
  width: 236px;
  padding-right: 10px;
  margin-bottom:20px;
  margin-top: 5px;
}

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

Struggling to locate elements with Python selenium

Just starting out with Selenium and attempting to extract data from a particular website: . This site stores information on hotels across the United States. My main objective is to compile this data into a CSV file where each entry would have a 'State ...

In need of a solution for this peculiar problem with an html table and css. Let's

Encountering an unusual issue with my table content .table { position:absolute; top:12px; left:3px; width:87px; height:74px; } .table tr { vertical-align:middle; } .table td { text-align:center; padding:1px;color:#000000; font-siz ...

Icon that can be clicked before

I'm struggling to figure out how to make the link icon in my code clickable so that users can click anywhere within the card to navigate to another page. I experimented with (" attr(href) ") but it resulted in adding the URL text next to the ...

Steps to eliminate the x icon from the text box that appears automatically in Internet Explorer

I'm currently working with a UI5 text box that includes a built-in option for clearing the text using a 'X' button. However, I've noticed that in Internet Explorer, an additional default cross mark is being added alongside the UI5 cros ...

Incorporating a header include on every page throughout my website

Is there a way to include headers and footers in your HTML web pages without having to duplicate code on every page? I understand that this can be done using PHP, but what if you are creating a website solely with HTML? If there is no solution to avoid r ...

Expand the contents inside a div without affecting the actual div

Is there a way to zoom out the contents of a div similar to how a browser zooms out a page? I'm working on an application that loads a page into a div. However, I want to load the content without scroll bars. This would require zooming out the conten ...

What is the best way to handle images overflowing a div

I am currently working on creating a carousel using React, where the content images are aligned horizontally. If I have 3 image tags within a div with a width of 1200px, how can I effectively control these images to ensure they fit within the container div ...

Engaging with the CSS content attribute

Below is a code snippet that inserts an image before the header tag. Is there a way to incorporate JavaScript or jQuery in order to execute certain actions when the inserted image is clicked? h1::before { content: url(smiley.gif); } The HTML code fo ...

What could be causing my Jquery fade effect to not function properly?

I'm new to incorporating Jquery into my website and I'm facing an issue with getting the first row of pictures to fade in (upwards) when scrolling. Despite my efforts, they are not behaving as expected. Any guidance on how to resolve this? HTML: ...

Turn off hover opacity effect for a specific image

Currently, I've implemented a hover opacity effect on my images using the following CSS: img { opacity: 1.0; filter: alpha(opacity=1.0); } img:hover { opacity: 0.6; filter: alpha(opacity=0.6); } However, I now have a specific image for whi ...

MaterialUI Box reigns supreme in the realm of background images

In my React component, I have a form that is structured like this: <Box display="flex" justifyContent="center" alignItems="center" style={{ minHeight: "100vh", backgroundColor: "gray", opacity: "0.8" }} > ... </Box> ...

Transforming the font landscape with Twitter Bootstrap 3's Glyphicons

I have an unordered list with icons styled using Twitter Bootstrap 3. The Carme font from Google Fonts is used for normal text, and works well in that context. However, when I add icons to the unordered list using BS3, the font-family of that particular ...

What is the best way to add multiple classes to an HTML element?

Can a single HTML container have more than one class assigned to it? For example, would the following code work: <article class="column wrapper"> ...

Issues arise when attempting to display Sphinx documentation containing SVG images on Internet Explorer 11

I have been working on building Sphinx documentation and incorporating a UML diagram generated as an SVG image using graphviz. The SVG file is embedded in the auto-generated HTML template from Sphinx. While the SVG displays perfectly fine on Chrome and Fi ...

Ensure that the content remains centered within absolutely positioned DIVs inside the parent container

Imagine a scenario where you have a container with a fixed width and centered. Inside this container are two DIVs that are position relative to the window, placed side by side. The content inside these DIVs should ideally be centered, aligned with the cont ...

Is the parameter retrieval method correct or erroneous?

I am looking to retrieve data by clicking a link. Here are the links available: <a class="note" id="' . $data["p_id"] . '" value="1" href="javascript:void(0)">+1</a> <a class="note" id="' . $data["p_id"] . '" value="-1" ...

What could be causing this Form to redirect to the incorrect file path?

I recently updated the login menu for my Admin panel. Initially, the login page was named login.php, but I decided to change it to index.php. Even though I made sure to update the action from login.php to index.php, when I click on the login button it st ...

Provide solely the specified content range

While working with Node.js, my goal is to develop a video server that can serve a specific portion of a larger media file. Thanks to this gist, I have successfully created a video server and integrated it with an HTML5 video player using: <video contr ...

Traverse div elements using jQuery and showcase the text within them

I've got a setup like the one below. I want to use jQuery to grab each link and display its href right below it. Instead of writing code for each div individually, I'm looking for a solution that works for all divs with the 'col' class, ...

Attempting to toggle the visibility of div elements based on radio button selections

I'm currently working on a script that will dynamically show and hide different div elements based on the radio button selection made by users. The jQuery library is loading correctly, as I have tested it with an alert message upon page load. Si ...