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

Tips for handling numerous buttons in ionic?

I'm currently working on an app that includes surveys. In this app, users are required to answer by selecting either the Yes or No button. The desired behavior is for the chosen button to turn blue once clicked, while the other button should maintain ...

Is there a way to horizontally align the content in my footer section?

I am currently exploring React Material UI for the first time. The table I am working with can be found here under the "Custom pagination actions" section. Within this section, there is footer content containing buttons for rows per page, next, previous, ...

The find element will yield an empty result when using XPath contains with Text() method

When checking for Gender and Date in the assertion, it returns false and the IWebElement displays an empty string. This anomaly only occurs with Gender and Date, while the rest provide accurate results. CODE IWebElement actualname = BrowserHelper.WebDri ...

The issue with displaying Fontawesome icons using @import in CSS-in-JS was not resolved

I recently changed how I was importing Fontawesome icons: src/App.css @import "@fortawesome/fontawesome-free/css/all.css";` After shifting the @import to CSS-in-Js using emotion: src/App.js // JS: const imports = css` @import "@fortawes ...

Customizing HTML Select Elements

Can the HTML Select attribute be customized to have a flatter appearance? Although I can set the border to be 1px solid, the dropdown part still appears 3D and unattractive. ...

Exploring the world of animation with Jquery and images

I'm delving into the world of jQuery to create some captivating animations. Currently, I've been tasked with an assignment involving images that expand, contract, change opacity, and eventually hide. Below is my code snippet: function play_pic1 ...

What is the process to change the URL?

Currently, I am deep into developing a large-scale web application for a company. The project has been ongoing for about four months now, and we have encountered a harmless yet annoying issue that we haven't had time to address. The problem lies in t ...

Border for status input like on Facebook

I tried to investigate with Firebug, but struggled to find a solution. How does Facebook wrap the border around the autosize input in the status section? I am particularly curious about the small triangle attached to the border. While using Firebug, I loca ...

Displaying nested arrays correctly

My latest endeavour involves constructing a data tree in Vue, utilizing components. Let's examine the provided data snippet: "data": [ { "id": 1, "name": "foo", "children": [ { "id": 2, "name": "bar", "children": [] } ...

What are the steps to add SVG effects to an image or div element?

Embarking on my first venture into using SVG graphics has left me feeling a bit bewildered. Despite extensive research, I have yet to stumble upon the answer to my current quandary. The objective at hand is to transform an image, assuming that the source ...

styled-components: the parent's styles take precedence over the child's styles

image export const LogOutButton = styled.button` display: inline-block; .... `; export default styled(ThemedApp)` .... button { .... display: flex; .... } `; Upon inspection, it is evident that the Logout button (with class gBuhXv) ...

Problem with transitions not working properly in Vue.js.The issue

Experiencing an issue with the Vue.js transition feature. Check out this link for reference. When the transition enters, it works smoothly, but when transitioning out, it's not functioning properly. File: genetic.vue <transition name="slide-f ...

What is the best way to show toast notifications for various selections in a dropdown menu?

I have a dropdown menu labeled "FavoriteFoods" that includes options such as "Pizza," "Sushi," "Burgers," and "Biryani." When one of these food choices is selected from the dropdown, I would like a toast pop-up to appear with the message "Great choice!" ...

Refresh a particular element using javascript

I'm new to Javascript and I am trying to refresh a specific element (a div) using only Javascript when that div is clicked. I came across the location.reload() function, but it reloads the entire page which doesn't fit my requirements. Upon clic ...

Retrieving text from a draggable div using jQuery

I have a draggable div that I can move over another element with the class .outerDiv which contains text content. Is there a way for me to retrieve the text from .outerDiv that overlaps with the draggable div? $(".outerDiv .isStore").draggable({ contain ...

Using CSS to automatically adjust the width of a child div based on its content, rather than stretching it to fill the entire

I'm currently facing an issue with my CSS. Apologies for the vague title, but I'll do my best to explain it here. My problem lies within a parent wrapper div that is centered on the page. Within this wrapper, there is another child div containing ...

Unable to pinpoint the source of the excess spacing within a form field

There appears to be some extra space in the text field of my form, extending beyond the container margin. Please refer to the image and JSFiddle http://jsfiddle.net/GRFX4/. Any thoughts on what might be causing this issue? Thank you. HTML: <div id="co ...

Retrieving table information using javascript

My goal is to retrieve information from the <td> elements within the following HTML table: <table class="datadisplaytable" summary="This table lists the scheduled meeting times and assigned instructors for this class.."> <caption class="cap ...

Aligning UL LI elements vertically for multi-line textORHow to vertically

I am dealing with a ul list that contains both single and multi-line li text. The issue is that the second line of the multi-line text starts at a different indentation than the first line. I need a simple solution to resolve this problem that works seaml ...

How to perfectly align squares in CSS Grid

I'm working on arranging four squares in a grid pattern, two on top and two on the bottom, with equal spacing between them. Currently, the squares shift based on the fr value in CSS grid, resulting in uneven spacing like this: I want to align all fou ...