Repairing the Bootstrap Header

I'm having trouble getting my navbar-right elements to align with my navbar-brand section. I need assistance with this. I want them to align, but here's how the element should look: https://i.sstatic.net/Fettu.jpg

header.html

<header>
        <div class="navbar navbar-default navbar-fixed-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse"
                            data-target=".navbar-collapse">
                        <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="#">
                        {{ Html::image('assets/images/logo.png') }}
                    </a>
                </div>
            </div>

            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li class="active"><a href="#">Home</a></li>
                    <li class=""><a href="#">About Us</a></li>
                </ul>
            </div>


        </div>
    </header>

style.css

.navbar-text > a {
    color: inherit;
    text-decoration: none;
}
body {
    padding-top: 70px;
    padding-bottom: 100px;
}

.navbar-default{
    background-color:#005b96;
    border-color:#005b96;
    font-family: 'Roboto', sans-serif;
    font-size: 15px;
    position:absolute;
    top: 25px;
    left:100px;
    right:100px;

}
.navbar-brand {
    width: 100px;
    height: 50px;
}

.navbar-default .navbar-brand > img {
    width: 130px;
    height:50px;
    position: absolute;
    top: 5px;
    padding-top:5px;
    padding-bottom: 5px;
    margin-left: auto;
}

.row{
     position:absolute;
    top: 25px;
    left:115px;
    right:115px;
}
.panel{
    margin-top:100px;
}

Answer №1

Check out this example. The problem lies in your code structure. You should enclose your .container around the following:

<div class="navbar-collapse collapse">
......
</div>

It should look like this:

<header>
  <div class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <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="#">
            {{ Html::image('assets/images/logo.png') }}
        </a>
      </div>

      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="#">Home</a></li>
          <li class=""><a href="#">About Us</a></li>
        </ul>
      </div>

    </div>
  </div>
</header>

Answer №2

Does this look like what you were hoping to achieve? http://example.com

If so, here is the method I used to attain it:

.navbar-collapse.collapse {
    position: absolute;
    right: 50px;
    top: 26px;
}

Additionally, I recommend placing this within a media query for a minimum width of 768 pixels.

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

Creating formatted code blocks within my HTML document

I'm currently working on achieving this layout in my HTML: https://i.stack.imgur.com/2LEQO.png Here is the JSFiddle link: https://jsfiddle.net/cr9vkc7f/4/ I attempted to add a border to the left of my code snippet as shown below: border-left: 1px ...

The automated Login Pop Up button appears on its own and does not immediately redirect to the login form

Hey guys, I'm struggling with modifying the jquery and html to ensure that when the login button is clicked, the login form pops up instead of displaying another login button. Another issue I am facing is that the login button seems to pop up automati ...

Is there a way to detect duplicate usernames in a form without actually submitting the form, and then automatically focus on the username field if a duplicate is

I need help with a user registration form that I am creating. I want the form to automatically search for an existing username as soon as the user starts typing in the username field. If the username already exists, I want the field to receive focus. In my ...

The alert feature seems to be malfunctioning. I attempted to use an external script file with the code "alert('hello world');" but it did not produce the desired alert

<html> <head> <meta charset="utf-8"> <script scr ="lecture01.js"></script> </head> <body> this is a simple html page </body> The alert function seems to be malfunctioning. I included "alert("hell ...

challenges surrounding the use of getElementByTagName

Within my webpage, I have implemented two select elements, both containing multiple options. However, I am facing an issue where I can only access the options from the first select box using getElementByTagName("options"), and unable to retrieve the option ...

Ways to confirm the existence of a specific attribute within a selection

In this HTML select element: <select id="select-filter-item" data-hasqtip="true" title="" aria-describedby="qtip-3"> <optgroup label="Servizi" type="services-group"> <option type="provider">Tutti i trattamenti</o ...

Automatically changing the color of the navigation bar text

I am experiencing an issue with the navigation bar on my webpage. Currently, it is styled with white text against a dark background color using the following CSS code snippet: a{ color: white; text-decoration:none; font-weight:bold; font-s ...

Choose an element at random

I am trying to figure out how to select all div elements with the same class of "dot" under a parent div in JavaScript. Here is an example structure: <div id="dots"> <div class="dot"> . </div> <div class="dot"> . </div> ...

Is there a way to use a Google Chrome command line switch to simulate the dimensions of a

Seeking information on the available Google Chrome command line switches for emulating device sizes. Specifically, I need to test a component that utilizes CSS @media queries for min-device-width/min-device-height. Previous attempts with --window-size an ...

What could be causing the misalignment of a button within a Bootstrap navbar?

I'm struggling with aligning the log out button correctly in the navigation bar with a dropdown. I have tried every structure suggested on the Bootstrap documentation page to no avail. Can anyone provide guidance on how to vertically align it properly ...

Display two lists of models categorized by time

I have two lists of model types that are initialized in the controller and values are inserted into them. These list objects are then assigned to ViewData so that I can iterate through them using a foreach loop. However, the issue is that the models of the ...

Adding a class to the submit button in a Yii form

I need to customize the form code by adding a class for the submit button and applying inline styles to all text fields. How can I achieve this? For example, in the view source it currently looks like this: I want to make it look like this: <div cla ...

What is the solution when md-autocomplete does not receive data from a service?

I am trying to create a md-autocomplete feature, but I am facing an issue where the options are not being displayed. Instead, I keep receiving an error message even when there are valid input options available. My service response is correct and my contr ...

Is it possible to use CSS transitions to animate an absolute positioned element?

I am having trouble getting a CSS transition to work for animating an element's position change. I have tried using the all properties in the transition declaration like in this example: http://jsfiddle.net/yFy5n/3/ However, my goal is to only apply ...

Visual Studio Code version 1.42 is now automatically converting <br> tags to <br /> when formatting code

This issue just started occurring. I'm not exactly sure what triggered it, but it could be related to my attempt to activate the Preitter extension. As a newcomer to Visual Studio Code, I am currently working on HTML5 documents. Strangely, whenever I ...

Achieve a stylish layout by displaying three cards per row using Vue.js and Bootstrap 4

I'm facing an issue with my code where I am trying to display Bootstrap cards in rows of three, but the layout is not rendering correctly. It starts with one card, then two, and eventually adds a new column, resulting in some empty spaces with offsets ...

Add a button feature to both upload and download a todo list within a JavaScript file, similar to a text file

I'm looking to enhance my simple todo list with a download and upload function. I want to be able to save the list in local storage and then upload or download it from a server code. Below is a link to my code: https://jsfiddle.net/zahrashokri/uqkn6t ...

activating the web element located using Selenium in Java

What is the best way to click on a webelement based on the data-key in the class _3d5d? Specifically, if a user inputs the value 2002, an error message should inform the user "no such year, please enter again" and allow for a re-entry of the value. If the ...

Styling effects in Internet Explorer: Using CSS shadows

filter: progid:DXImageTransform.Microsoft.Shadow(color='#b0b0b0', Direction=135, Strength=3); The CSS code above adds a shadow effect to the content, but the challenge arises when you want the same effect on both sides. Simply duplicating the li ...

Exploring the archive of content with AJAX back button tracking

Greetings, Before considering this question as a duplicate, I would like to mention that I have thoroughly searched for similar questions but none of them address my specific issue. Below is a simple example, and any assistance you can provide would be hig ...