Overlapping body content due to Bootstrap 4 navbar menu design

I've just kicked off a fresh website using bootstrap 4, but already facing hurdles right from the start. The navbar menu seems to be encroaching on some part of the body content, and I'm completely at sea.

Attached is a terrible draft where you can clearly notice the overlap caused by setting the navbar to 50% width intentionally.

The crux of the matter is I want the body content (including the image) to be vertically centered; that's my top priority. Additionally, I would like to understand why the navbar is overlapping in the first place.

Site.css:

html, body {
    height: 100%;
    padding-top: 50px;
    padding-bottom: 20px;
}

/* Apply padding to prevent content from reaching the edges */
.body-content {
    padding-left: 15px;
    padding-right: 15px;
}

/* Override default behavior whereby horizontal description lists truncate terms exceeding the left column width */
.dl-horizontal dt {
    white-space: normal;
}

/* Adjust the width for form input elements since they usually occupy 100% width by default */
input,
select,
textarea {
    max-width: 280px;
}

Layout.cshtml:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    <nav class="navbar navbar-expand-sm navbar-dark fixed-top bg-dark">
        <div class="container">
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"></button>
            <a class="navbar-brand" href="/">Application name</a>
            <div class="navbar-collapse collapse" id="navbarSupportedContent">
                <ul class="nav navbar-nav mr-auto">
                    <li class="nav-item"><a href="/" class="nav-link">Home</a></li>
                    <li class="nav-item"><a href="/Home/About" class="nav-link">About</a></li>
                    <li class="nav-item"><a href="/Home/Contact" class="nav-link">Contact</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right mr-auto">
                    <li class="nav-item"><a href="/Account/Register" id="registerLink" class="nav-link">Register</a></li>
                    <li class="nav-item"><a href="/Account/Login" id="loginLink" class="nav-link">Log in</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right mr-auto">
                    <li class="nav-item"><img src="~/Content/img/bandera_catalunya.png" alt="car_accident" class="nav-link" style="width: 50px;" /></li>
                    <li class="nav-item"><img src="~/Content/img/bandera_espana.png" alt="car_accident" class="nav-link" style="width: 50px;" /></li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container-fluid h-100 body-content" style="background-color:antiquewhite;">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

Index.html:

<div class="container" style="background-color: aqua">
    @*align-items-center innerHeight-100*@
    <div class="row">
        <div class="col-md-4">
            <div class="row">
                <div class="col-md-6">
                    @Html.LabelFor(model => model.Year)
                </div>
                <div class="col-md-6">
                    @Html.DropDownListFor(model => model.Year, new SelectList(Model.Years, "Value", "Text"), new { @class = "form-control year-dropdown", style = "font-size:120%;" })
                </div>
            </div>
            <div class="row p-2"></div>
            <div class="row">
                <div class="col-md-6">
                    Age at the time of accident
                </div>
                <div class="col-md-6">
                    @Html.DropDownListFor(model => model.Year, new SelectList(Model.Ages, "Value", "Text"), new { class = "form-control year-dropdown" })
                </div>
            </div>
        </div>
        <div class="col-md-8">
            <img src="~/Content/img/accident-1497298.jpg" alt="car_accident" class="img-fluid w-100" />
        </div>
    </div>
</div>

Your assistance in aligning the body content vertically and diagnosing the root cause of the overlap problem will be highly appreciated.

https://i.sstatic.net/1rVOt.png

Answer №1

The height of the navbar is set to 50px, but it appears that the presence of flag images on the right side is making it larger than intended.

To accommodate this, the body has a padding-top of 50px, causing the navbar to intrude into the body's space.

An effective solution would be to adjust the padding-top value in your body element accordingly.

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

Where could one possibly find the destination of the mysterious <circle>?

I want to implement a simple pulsating animation on a circle svg element. I attempted using a transform: scale(..,..) animation, but it seems to be shifting the entire circle within its container instead of just scaling the element itself. This is the cur ...

Can jQuery be used to change the functionality of a submit button, such as toggling between show, hide, and submit options?

I am having trouble toggling a button to either submit a form on click or reveal an input field, depending on whether the user clicks outside the input field to hide/collapse it. The issue arises when the user dismisses the input field and the submit butto ...

Alter div elements with jQuery based on the particular link that was selected

I'm struggling with updating a nav bar that has different divs based on the link clicked. <script> $(document).ready(function (){ $("#content").load("content/index_content.php"); $('a').click(function(){ $ ...

Navigating Struts - The art of breaking free from encoded symbols in a text field

I'm having trouble displaying the trademark symbol in a default text within a Struts text field. Despite trying various methods, the symbol does not appear and only outputs the code instead. Can someone please provide guidance on how to properly displ ...

My website crashed after attempting to update WordPress

After upgrading my website to Wordpress 3.4, I encountered a major issue that caused significant damage to my site. It seems that half of my posts were not accessible and resulted in a 404 error. Additionally, pages 3 and 4 of my posts also showed a 404 er ...

Tips for locking the position of a table header and allowing only the table body to scroll

I have designed a table with tbody consisting of 2 tr elements. One tr is used for hiding/showing data. I am trying to keep the Table header fixed while only scrolling the table body. However, as I am using angular js ng-repeat on the tbody, I am encounte ...

execute a function following a change in window size

I have multiple functions running on $(window).resize(). One of the functions involves a complex animation that uses many div elements. $window.resize(function() { // some functions doAnim(); } The issue I am encountering is that the resize() fun ...

What is the best method to conceal the tooltip using the html <a> title attribute?

Is there a way to prevent the tooltip from displaying when hovering over links, while still keeping the title attribute for SEO purposes? I have come across suggestions like using jQuery with $('...').removeAttr('title'), but will this ...

The lower border is unresponsive in the CSS/HTML code currently in use

Currently diving into the world of Web Development, I find myself tackling the CSS part. My latest challenge involves adding a bottom border to an element, but no matter what I try, the border just won't show up. I've scoured resources for soluti ...

How can I ensure that my HTML page remains live at all times?

I've been scouring the internet trying to find a solution to my problem: What I'm looking to do is create a method for keeping an HTML page on a live production site constantly updated. I have a SilverStripe Application that is part of a graphic ...

Angular reduces image width to zero

Looking to include an image in an Angular template, where the width attribute is equal to a variable width that sometimes holds the value null. In cases where width = null, I aim to have width = "" (or no width attribute at all). However, Angular assigns ...

Place a <div></div> element within a collapsible accordion container that conceals the content inside the <div>

My accordion is expanding, but the div inside it appears blank instead of displaying its content. Any suggestions on how to fix this? Thank you. How can I ensure that the div inside the accordion shows its content? Here is the code: http://jsfiddle.net/6 ...

Troubleshooting the issue with reactdom.render() functionality in CodeSandbox

Having issues with ReactDom in CodeSandbox for React. The HTML file includes: <body> <div id="root"></div> </body> <script src="scr/index.js"> The JavaScript file (named index) includes: ReactDOM.rende ...

Using jQuery to toggle the image of a button based on its id

I have a jQuery function that opens another section when clicking on a div with the class 'open', and changes the image of a button by switching its id for CSS. However, I now need to change the button's image back when it is clicked again. ...

Can you demonstrate how to assign a CSS class to a datalist?

I have run into an issue where I can't seem to control the styling of the items on my datalist. The external styling does not provide any vertical spacing between each item. Is there a way to add this spacing? <div id="cssmenu"> <ul> ...

Interactive input field designed for modifying, adding, and removing data in MySQL

I am working on a project where I have a simple form. However, I need to dynamically change the form action from insert to update within the same page. Additionally, I also want to display the values on the same page. Within my code, I have set up the up ...

When using Javascript's querySelector, often times it returns null

Here is the HTML code I am working with: <button class="pop-btn"> Pop </button> While I was able to style this button using CSS, I encountered a problem when trying to select it in Javascript: const Population_div_Button=document. ...

Launch the jQuery Fancybox on a separate webpage

I am facing an issue where I have a link in my index.html page and I need it to open a div located in another page named index2.html, but for some reason, it is not working. This is the code I currently have: Link in index.html <a href="#modal" id="o ...

Enhancing the appearance of a PHP HTML email

I scoured the web for an answer to this question and all I could find was to include the following: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; and ...

Navigate through the components of an array within HTML

I am a beginner in HTML and I need to customize a specific piece of code to suit my requirements. Here is the code snippet written in pseudo code: <app-myapp *ngIf="true" [exclude] = "[this.myUser.id]" ...