Design and styling with HTML5 and CSS

Having a small issue with my code as I venture back into coding after a long hiatus, resulting in me forgetting some basics. Currently, I am attempting to create a simple HTML layout.

Upon inspecting the page, I noticed that it appears slightly longer than expected, causing a slider to appear which I did not intend unless the content surpasses the expected length (wraps).

The goal is to keep the top fixed at all times, while allowing the footer to adjust based on the content's length or remain fixed at the bottom if the content is minimal.

Expected Outcome:

Current Outcome (without top):

with top :


HTML layout :

<!DOCTYPE html>
<html lang="en">

    <head>

        @include('layouts.includes.head')

        <link href="{{ asset('/css/style.css') }}" rel="stylesheet">

    </head>

    <body>

        <div id ="top">

        <div>

        <div id = "wrap">

        </div>

        <footer>

        </footer>

    </body>


</html>

CSS :

html,body 
{
  height: 100%;
  background-color:red;
}

#top {
  height: 50px;
  height: auto;
  margin: 0 auto -50px;
  background-color: yellow;
  width:auto;
}

#wrap {
  min-height: 100%;
  height: auto;
  margin: 0 auto -50px;
  background-color: blue;
  width:auto;
}

footer {
  height: 50px;
  background-color: black;
}

Answer №1

Ensure the footer stays at the bottom of the page and add a margin to the wrap element to prevent overlap with the footer.

#main-content {
  min-height: 100%;
  height: auto;
  margin: 0 auto 60px auto; 
  background-color: green;
  width: auto;
}

footer {
  height: 50px;
  background-color: gray;
  position: fixed;
  bottom: 0;
  left: 0; 
}

Answer №2

Here is an alternative approach: Check out the demo

body, html {
    height: 100%;
    background-color: lightgrey;
    position: relative;
}
#header {
    height: 50px;
    width: 100%;
    background-color: yellow;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}
#content {
    min-height: calc(100% - 50px);
    margin-top: 50px;
    background-color: lightblue;
}
footer {
    height: 50px;
    background-color: black;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
}

Answer №3

Experiment with this snippet here

  • The header and footer will remain fixed while the content can be scrolled.
  • If there is no content, the layout will adjust based on the window size and the scrolling feature will be disabled until necessary.

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

Using HTML5 input pattern to permit the use of a comma separator when entering thousands

I'm currently working on creating a regular expression for an HTML5 input form that allows the comma as a separator for thousands. Here are some examples of valid input: 20 3000 4,000 600000 7,000,000 8000000 The requirements for the input are: o ...

Tips for aligning the Bootstrap inline form in the center of the webpage

Is there a way to center align my form in such a way that the input box and button appear in the same row? I've tried the code below, but for some reason they don't display inline. Can anyone provide a code sample to help me achieve this? Your as ...

Exploring the Power of Nested *ngFor in Angular 2

I am struggling with passing indexes to a function where the first parameter (ii) is coming back as undefined. <div *ngFor="let tab of screen.data.tabs; let indexTab = i;"> <div *ngIf="tab.active"> <div *ngIf="tab.questions"&g ...

Can you explain the significance of xpath=1 in an HTML document?

I am confused about a line in my design code that reads xpath="1". Can someone explain what this means in the context of the following code snippet? <select class="search-category" id="ddlTemp" name="Template" x ...

Extracting text within quotation marks from HTML using Java and Selenium WebDriver

I encountered a piece of code that resembles the following: https://i.stack.imgur.com/gaX1J.png Although I am able to retrieve the link using the command System.out.print(link.getText()); it only returns the value "Saab". However, I also require the da ...

Stop Sublime Text from automatically calculating Less2Css

Within my workflow using Sublime Text and Less2Css for dealing with less files, I encountered an issue where specifying the max-height of a container as 100% - 20px resulted in minification reducing it to '80%'. Is there a way to work around this ...

Update the default arrow icon in the expand/collapse navigation bar

I need help changing the downward arrow in the code below to a fontawesome icon. I'm unsure about how to: 1. Remove the default arrow on the right of the parent node. 2. Use "+/-" symbols to represent the collapse state. It seems that the onclick c ...

The value of the innermost dropdown in the AngularJS Cascading dropdown is not being retrieved when it is selected

CSS <div ng-controller="DynamicCtrl"> <h1>Dynamic - Focused</h1> <p>This method works well when data is constantly changing</p> <div> Category: <select id="category" ng-model="items" ng-options="category ...

Preserve the values of checkboxes throughout the entire website by utilizing localStorage

Example A functionality in the example allows users to add images to a container by clicking on checkboxes. However, there is an issue where when a checkbox is checked on one page to store an image, and then another checkbox is checked on a different page ...

Having trouble loading the image source using JSON in Vue.js

var topArticle=new Vue({ el:'#toparticle', data:{topmostArticle:null}, created: function(){ fetch('topnews.json') .then(r=>r.json()) .then(res=>{this.topmostArticle=$.grep(res,functi ...

How can I make my JQuery datatable span the full width of the screen, regardless of the resolution?

In my Rails application, I am using JQuery Datatable with the following code: <%= content_tag :table, role: :my_datatable, id: 'my_datatable', style: 'height:500px; overflow-y: auto;&apo ...

Using ASP.NET Server Controls to Toggle Textbox Visibility Based on Dropdown Selection

What is the optimal method for displaying or hiding a textbox or an entire div section based on a user's selection from a dropdown menu? I am uncertain if this can be achieved with server controls, so would it require using standard client-side HTML c ...

Learn the process of eliminating special characters from input or textarea fields with AngularJs!

My attempts to integrate an AngularJS directive to remove special characters from input and textarea fields have been unsuccessful. Despite no errors being reported in the console, I am facing issues with the character count tooltip not displaying numbers ...

Unable to store form data in a JSON file

i need help with the json data file called groups.json { "groups" : [ { "pname" : "group1", "remarks" : "best" }, { "pname" : "group2", "remarks" : "not the best" } , { "pname" : "group3", ...

Utilizing Multiple Select Options and CSS Float Styling in Mozilla Firefox

I have been attempting to customize the CSS of a multiple select element. While I am satisfied with how it looks on Chrome, I am facing issues getting it to work correctly on Mozilla Firefox. $('option').mousedown(function(e) { ...

Incorporating HTML variables into a Django template without the need for escaping

I have encoded text in HTML format that looks like this: RT <a href="http://twitter.com/freuter">@freuter</a>... I would like to display this as formatted HTML, but I am unsure if there is a filter available to convert the encoded text back t ...

What is the process for obtaining X through the use of createElement('img')?

Is there a way to retrieve the X position from the left of the tag created using document.createElement('img'); var block00 = document.createElement("img"); block00.src = "images/sep1.png"; If so, how can it be done: if (block00.getBoundingCli ...

Creating a CSS template for organizing sidebar and footer divisions on a webpage

I am facing an issue with the layout of my website. I have a container that is positioned relatively and houses various divs for header, sidebar, main-content, and footer. The problem lies with the sidebar and footer components. The sidebar has been posit ...

Issue with exporting data from Datatables

I followed the instructions, and the Datatables export function worked perfectly in localhost, but when I tried it in Google Apps script, it didn't work. For more information about the issue, you can visit this link: DataTables TableTools buttons not ...

Is there a way to combine fixed and dynamic size elements within a flexbox container?

Currently, I am working on creating a layout that combines the automatic sizing feature of flexbox with fixed-size elements: <View style={{ height: 70, alignItems: "center" }}> <Text style={{ flex: 1, textAlign: "right", paddingRight: 10 }}&g ...