How to position footer at the bottom of pages in asp.net MVC without displaying a scrollbar for shorter pages

Thanks to a useful tip I found on Stack Overflow, I was able to position the footer at the bottom of all my pages in ASP MVC. I created a custom stylesheet called "mystyles" where I defined classes for .wrapper, .footer, and .push. In the _layout file, within the body and html tags, I set style="height:100%" and used the wrapper, footer, and push classes as shown below. However, I am facing an issue where a scrollbar appears. How can I adjust the footer to display slightly higher so that the scrollbar does not show?

<!DOCTYPE html>

<html style="height:100%">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Styles.Render("~/Content/myStyles.css")


</head>
<body style="height:100%">
<div class="wrapper">
    <div class="navbar navbar-inverse navbar-fixed-top">
        <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>
                @Html.ActionLink("myapp", "Index", "Home", new { area = ""   }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("home", "Index", "Home")</li>
                </ul>
                @Html.Partial("_LoginPartial")
            </div>
        </div>
    </div>
    <div class="container-fluid body-content">
        @RenderBody()
    </div><!--End of container fluid-->
    <div class="push"></div>
</div><!--End of wrapper-->
<div class="footer">
     <hr class="my-hr" />
    <p>&copy; my footer statement</p>

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

Answer №1

As mentioned by @David-Lee, it's important to note that without CSS code, our options are limited. Instead of setting the body height to 100%, focus on properly adjusting the footer:

<div style="bottom:0;position: fixed; width:100%;">
  <hr style="width:100%;" />
    <footer>
      <p>&copy; @DateTime.Now.Year</p>
    </footer>
</div>

For a better solution, refer to this link: https://codepen.io/cbracco/pen/zekgx

Answer №2

It's difficult to provide a precise solution without reviewing all of your CSS.

Based on my intuition, the code snippet below may guide you towards the correct path:

.content {
  margin-top: -40px; /* should align with positive px value of padding-top */
  padding-top: 40px;
}

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

Tips for arranging 3 tables in the right place using CSS

I have 3 tables that I utilize. My goal is to: have one on the left side of the page place one in the center of the page position one on the right side All at the same height. The issue arises when the tables expand and using float causes them to ...

Enabling PowerShell to Download an Executable from a .NET Core MVC Web Application

My current setup involves a .net core MVC web app that relies on a .net framework console app. As the Core app is built, the console app also builds and produces the exe in the bin directory: https://i.sstatic.net/Bv1eM.png Everything is functioning well ...

Show the page links on the custom WordPress theme's home page

This is my first time creating a wordpress theme from scratch and I could use some assistance with tackling two specific challenges involving the WP_Query class and the navigation menu. My goal is to showcase the titles and featured images of pages on the ...

Tips on revealing concealed information when creating a printable format of an HTML document

I need to find a way to transform an HTML table into a PDF using JavaScript or jQuery. The challenge I'm facing is that the table contains hidden rows in the HTML, and I want these hidden rows to also appear in the generated PDF. Currently, when I co ...

Why does my jQuery IMG center script not work in Chrome and Safari, but it works perfectly in IE?

I am experiencing an issue with centering the thumbnails of products on my e-commerce website. Despite successful centering in IE, FF, and Opera, Chrome and Safari are not aligning the thumbnails properly – they remain at the top of the div instead of be ...

Tips for aligning text vertically in a column using CSS columns

Can text be vertically aligned in CSS columns? For example, aligning text to the top, center, or bottom within each column? I attempted to use vertical-align, but it doesn't seem to work on an unordered list or its items: html <div class="nav-ba ...

The slider image on my Bootstrap website is not properly displaying on mobile devices

Check out my bootstrap website which features a slider: here Although the slider image is displaying correctly on desktops, it's not fitting properly on mobile devices. I've tried adjusting the CSS with the following code: @media only screen ...

Can one use Flexbox inside another Flexbox?

I am attempting to create a layout that looks like this: +---------+---------------------+ |legend | | +---------+ | |csv_input| map | | | | | | ...

Column div being obscured by footer

My footer is causing overlap issues with the div above it on my mobile website. Here's a visual representation: Current view on my phone: https://i.stack.imgur.com/RpvWM.png Desired view: https://i.stack.imgur.com/KHVcm.png The code for the are ...

Issue with Bootstrap 4 collapse not functioning properly within a flex container

I'm encountering an issue with Bootstrap 4 collapse. Everything works as expected unless I add the "d-flex" class to my form tag. When I include the "d-flex" class, the form is initially displayed. Upon clicking #reservas_button, the form toggles fro ...

Tips for excluding two attributes when styling a CSS calendar selection

Let's say I have a table structured like this: <td class="search-unit-custom-control-calendar-day search-unit-custom-control-calendar-day--not-this-month"> <time class="search-unit-custom-control-calendar-day__number">--</time> ...

There is zero gutter in Bootstrap

Is it possible to use the bootstrap grid system without any gutters? I want to have 3 columns in one row like this: http://prntscr.com/6gpmhm. I have shared the markup for the CSS I am using, which is the default CSS of the framework. <section class ...

What is the best way to incorporate an options tabbed menu into a mega drop-down menu?

I came across a useful code snippet on The code snippet offers users a choice of 3 options with tabbed menus. Take a look at the website to see how this tabbed menu functions. Here is the code for this snippet <div class="row-fluid"> <div ...

Disable page scrolling while enabling scrolling for specific elements with overflow using JQM

Is there a way to stop the page from scrolling on a jQuery Mobile page while still allowing a specific element with overflow set to scroll to be scrolled by the user? The challenge is that the length of the page may vary slightly, exceeding 100% on differe ...

Place a pair of divs in the center next to one another

What is the best way to align two divs in the center beside each other with some padding in between that actually works? I attempted using display: inline, but it didn't have the desired effect. .my-container { position: rela ...

Deliver a PDF to the browser using .NET MVC 4

Read More @Html.ActionLink("Pre-Purchase Information", "GetForkopsInfo", "RaknaTeckna", null, new { target = "_blank" }) The GetForkopsInfo() method triggers the actionlink action and tm.PreSalesDocument represents the PDF object in bytes. [HttpPost] p ...

Table row with CSS flexbox wrapping

I have a unique set of items, each consisting of: A left side that expands horizontally to occupy the space where the item name is located. A right box at the end containing a few actions. My goal is to ensure that the box with actions on the right wraps ...

Tips for implementing the .nex() property from jQuery in CSS styling

When I add the class "playing", then I will apply custom CSS to the next li tag. Please review my code and see if you understand. Please take a look at my code. <ul> <li class="playing">li (sibling)</li> <li id="head">li ...

Switch between text box and label appearances based on focus

I am working with a template field in my gridview. This template field consists of a text box. I am looking to achieve the functionality where after the user finishes writing in the textbox and moves to the next one, the textbox that loses focus will trans ...

How to Customize Auto Complete Background Color of Selected Items in Bootstrap 4 Input Controls?

I'm currently struggling to figure out how to override the default white background color of a form control's autocomplete in Bootstrap. The white background doesn't align well with my dark theme. Whenever I enter something into an input fi ...