The div positioned above the navbar is not displaying as intended

Issue with the position of a div above the navbar in the body (See Screenshot).

Original Code:

<div class="container-fluid" style="background-color:#F44336;color:#fff;height:200px;">
    <h1>Bootstrap Affix Example</h1>
    <h3>Fixed (sticky) navbar on scroll</h3>
    <p>Scroll this page to see how the navbar behaves with data-spy="affix".</p>
    <p>The navbar is attached to the top of the page after you have scrolled a specified amount of pixels.</p>
</div>

    <div class="navbar navbar-inverse" style="background-color:#026;" data-spy="affix" data-offset-top="197">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("ՏԵՍԱԿՆԵՐ", "Index", "Home")</li>
                    <li>@Html.ActionLink("ՕԳՏԱԿԱՐ ՆՅՈՒԹԵՐ", "About", "Home")</li>
                    <li>@Html.ActionLink("ԿԼԻՆԻԿԱՆԵՐ", "Contact", "Home")</li>
                    <li>@Html.ActionLink("ԲԺԻՇԿՆԵՐ", "Contact", "Home")</li>
                    <li>@Html.ActionLink("ՆՈՐՈՒԹՅՈՒՆՆԵՐ", "Contact", "Home")</li>
                    <li>@Html.ActionLink("ԲԼՈԳ", "Contact", "Home")</li>
                </ul>
            </div>
        </div>
    </div>


.affix {
        top: 0;[enter image description here][1]
        width: 100%;
        z-index: 9999 !important;
    }

        .affix + .container-fluid {
            padding-top: 70px;
        }

Attempted using JavaScript but unsuccessful. It seems Bootstrap constraints are restricting the solution.

Answer №1

Have you experimented with incorporating position:absolute or position:fixed into the styling of the .container-fluid element?

(https://developer.mozilla.org/en-US/docs/Web/CSS/position)

I am having difficulty reproducing your issue. It should function properly, as it closely resembles the example from w3schools.

Providing a concise working version of your code in a stack snippet, or using platforms like bootply or jsfiddle, may be beneficial.

Answer №2

Assuming you want the navbar positioned at the bottom of the page and the background color to fill the entire coded area, follow these steps...

  • Create a wrapper div (e.g., .bg) directly within the body tag
  • Set the width of the .bg class to 100% (w-100)
  • Ensure that the navbar is outside the .container class but inside the .bg wrapper class

Below is a simple bootstrap webpage example with a background color and a navbar at the bottom. Bootstrap classes are used for brevity instead of custom CSS styles.

If you want the entire webpage to have one color, add this CSS rule to the html tag:

background-color: #somecolor;

Best of luck!

<!DOCTYPE html>
<html lang="en">
    <head>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    </head>

    <body>
        <div class="bg bg-danger">
            <div class="container-fluid">
                <div class="row w-100">
                    <h4>Bootstrap Afix Example</h4>
                </div>
                <div class="row w-100 mt-5">
                    <button type="button" class="btn-primary">button :)</button>
                </div>
                
                </div>
                <nav class="navbar navbar-default sticky-top navbar-light mt-3 w-100 bg-secondary">
                    <ul class="nav mr-auto mt-1 mb-1">
                        <li class="nav-item">
                            <a href="INSERT_YOUR_LINK" class="nav-item text-warning">Home</a>
                        </li>
                        <li class="nav-item ml-3">
                            <a href="INSERT_YOUR_LINK" class="nav-item text-warning">About</a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    </body>
</html>

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

Can a border not be added to a <tr> in an HTML table using CSS for any specific reason?

I am facing an issue with the borders of a table row (tr) when applying CSS styling. The tr has a class called "underRow" which is supposed to add a border at the bottom. In my CSS, I have defined the following for the ".underRow" class: .underRow { ...

Automatically close the modal upon receiving a valid input

When it comes to my modal, I've figured out how to show validation errors. My challenge now is preventing the modal from closing when there's an error in my ajax function. On the flip side, I'm also unsure of how to automatically close the m ...

Styling a HTML div element with a header and footer, while also ensuring that the

My goal is to create a div that features a header with a unique background design. The content within the div should have a background consisting of a one-pixel repetition at y, or maybe something different? I also want a footer with its own distinctive ...

Issue with form not capturing information from dynamically generated fields

I'm working on creating a dynamic form for user input of on/off instructions in pairings. The HTML code defaults with one pair, and the user can add additional pairs using a button. However, upon form submission, Angular is only reading the values fro ...

Implementing both fancybox and a hover remove icon functionality on a single image

I came across a solution on this question here, outlining how to implement an overlay hover remove icon on thumbnails. I tried incorporating it into my page, along with fancybox, but unfortunately, I'm encountering issues getting both functionalities ...

Suboptimal recommendations for CSS selectors

I have a couple of questions regarding optimizing our outdated CSS for better performance. (1) I am concerned about the impact on browser rendering performance due to including printer-related CSS in a common.css file and applying the selectors to certain ...

Multiple dropdowns remain unpopulated despite Ajax efforts

In my backend development project, I am working on creating a dynamic dropdown menu for category, subcategory, and vendor selection using AJAX. However, I am facing an issue where selecting a category does not populate the corresponding subcategories, and ...

Tips for enabling a keypad to restrict input field character limit

Encountering an issue with an input field that has a maximum length of 6 characters. Typing normally seems to work fine, but when using a custom keypad, the limit is not enforced and it allows for more than 6 characters to be entered. HTML: <div cl ...

Replicating DIV element with input field

Once again, I find myself stuck in my attempt to duplicate a DIV and its form elements using jQuery. Button: <div class="addNew" id="addSkill">Add Skill <i class="icon-plus"></i></div> This is the Div and contents that I want to ...

Use $.ajax to display the menu by capturing an array of elements {0}

Whenever I click on one of the DIV elements, a menu pops out on the side displaying more information about the clicked element. I can determine which element I'm clicking on, but I'm struggling to pass that information from jQuery to the PHP pag ...

Modifying the default text within a select box using jQuery

Within a select box identified as 'edit-field-service-line-tid', there is default text displayed as '-Any-'. This particular select field has been generated by Drupal. I am looking to use jQuery to change the text '-Any-' to ...

Having trouble accessing properties in AngularJS

This is my code snippet: app.controller('userController', function UserController($scope, userFactory) { $scope.users = []; $scope.user = { items : [] }; $scope.editMode = false; $scope.addItem = function () { $scope.use ...

Prevent the line from crossing over the circle in CSS

How can I prevent the line from intersecting the circle? I want the line to be outside the circle. The background (in this case, of the li tag) will be transparent. #project-wrapper { width: 100%; /* Adjusting the position of the element on the pa ...

Semantic UI Footer allows you to easily create a stylish

Greetings! I'm new to the semantic-ui framework and I'm encountering an issue with the footer. My goal is to have the footer always stay at the bottom of the page without being fixed. Here's a snippet of my simple HTML code: <!DOCTYPE h ...

Nested div within another div, shifting position relative to scrolling (React)

My goal is to create a unique effect where an object falls from the sky as the user scrolls down the page. The concept involves having the object div remain stationary in the center of its parent container, positioned 50 pixels from the top. However, when ...

Support for these CSS properties of left: 0; and right: 0; are compatible with

Just wondering if it's okay to utilize the CSS code below to ensure the element adjusts to its parent's width. .element { position: absolute; left: 0; right: 0; background-color: #ccc; border-top: 1px solid #ddd; } We don&ap ...

Create a stylish bottom border exclusively for the text that has been wrapped

My goal is to create an underline that perfectly fits the width of the text on the bottom row, without extending beyond it. The desired effect is shown in Figure 1. Figure 1 Here is the HTML I am currently using: <h2><span class="inline-block"& ...

How to effectively handle submenus within a Bootstrap 4 mobile menu?

I am currently updating our website from Bootstrap 3.3.7 to Bootstrap 4. The header contains a navigation bar with dropdown items. https://i.sstatic.net/n2P6U.png <header> <nav class="navbar fixed-top navbar-expand-lg navbar-light bg-white bg- ...

Proper implementation of media viewport for images with backgrounds

Although I am not a front-end developer, I ventured into creating a simple one-page website with an image. To ensure faster loading on smaller screens, I made multiple versions of the image to minimize the amount of data being downloaded. The image is inte ...

Steps for preventing a button from being enabled until all mandatory fields are completed

Is it possible to have a button disabled until all required fields are filled out, with the button appearing grey in a disabled state and changing color when all fields are completed? I am facing an issue where clicking on the previous button is causing ...