background covering the entire span

Can a background spread between two other backgrounds, creating the illusion of three separate sections? For example, having a top background image, a middle section that can vary in length based on the div size, and a bottom background image.

It's similar to the concept shown in this image:

Answer №1

If you're looking to create a background with three different colors, you can use the linear-gradient property on the #container.

Here's an example of how you can achieve this effect:

body, html {
  height: 100%;
  margin: 0;
}
#container {
  height: 100%;
  background: linear-gradient(180deg, #9C84E2 10%, #9C84E2 20%, #00F37A 20%, #00F37A 80%, #00F37A 80%, #FF6081 80%);
}
<div id="container">Lorem ipsum dolor sit amet, consectetur adipiscing elit... (truncated for brevity)

Answer №2

To achieve a dynamic visual effect, start by generating three separate div containers and assigning distinct background styles to each one.

Answer №3

Is this what you had in mind?

HTML

<div class="container">
   <div class="header"></div>
   <div class="content"></div>
   <div class="footer"></div>
</div>

CSS

.header{
    width: 100%;
    height: 20%;
    background: blue;
}

.content{
    width: 100%;
    height: 60%;
    background: green;
}

.footer{
    width: 100%;
    height: 20%;
    background: red;
}

FIDDLE

Answer №4

If you want the content to cover everything, you can create the illusion of a full background using absolute divs. Take a look at this example (it will span the entire height, but feel free to adjust as needed):

html,
body {
  height: 100%;
}
#main {
  background: green;
  height: 100%;
}
#top {
  position: absolute;
  top: 0;
  width: 100%;
  height: 50px;
  background: cyan;
}
#bot {
  width: 100%;
  height: 50px;
  background: red;
  position: absolute;
  bottom: 0;
}
#content {
  position: relative;
}
<div id="main">
  <div id="top"></div>
  <div id="bot"></div>
  <div id="content">
    CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT
    HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT
    HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT
    HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE CONTENT HERE
  </div>
</div>

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

Having trouble unchecking the checkbox when the dropdown is set to 0

I am currently working on enhancing the functionality of my ordering form. When a checkbox is checked, the quantity dropdown value will change to 1. When a checkbox is unchecked, the quantity dropdown value will change to 0. If the quantity dropdown va ...

What is the best way to align a button at the bottom using Bootstrap 4?

My question is not as straightforward as the title suggests, but I couldn't think of a better one. Initial Configuration: I am using Bootstrap v4.0.0-alpha.2 and I removed this simple sidebar. I also added flex: true in my _library-variable-overrides ...

I am experiencing a 404 error when attempting to import a local JS file in Angular

After creating a new project with "ng new xxx", all you need to do is add one line of code in index.html: <!doctype html> <html lang="en> <head> <meta charset="utf-8> <title>Bbb</title> <base href="/&g ...

Tabindex malfunction in Bootstrap dropdown menu when nested within a form and pressing Enter key

Within my form, I have integrated a Bootstrap 3 dropdown menu situated between two text input fields. The dropdown's role="menu" attribute allows for navigation using the up/down arrow and Enter keys. However, after making a selection in the dropdown ...

Based on the values pulled from the column in the SQLite database table, how can I display various icons on my HTML page?

Below is the query command I have in Python to paginate and display all blog posts on my website: @core.route('/', methods=['GET', 'POST']) def index(): form = Blogsearch_form(request.form) page = request.args.get(& ...

Automatically adjust the size of input control text based on the screen dimensions

I am facing an issue with resizing the text inside an input control when the window is resized. The problem occurs between the width range of 1032px to 575px, where the text inside the input control does not display completely. However, below 575px width, ...

Html5 canvas not resizing to fit container

I'm currently working on creating a square canvas using CSS to ensure it is instantly sized when the page loads. To achieve this, I am wrapping the canvas in a div and applying the following styles: http://jsfiddle.net/evopgwzd/ body { backgrou ...

Tick off a checkbox in a HTML document using VB.net

Attempting to have my program select a checkbox on a webpage is resulting in an error message that reads "Object reference not set to an instance of an object." Here is the code snippet for the functionality: WebBrowser1.Document.GetElementById("chkAge ...

Setting an Element's attribute is only visible in the console

Just dipping my toes into the world of Web Development. While playing around with some JavaScript within HTML, I decided to try updating the content of an element. Upon running the code below, "Updated Content" appears in the console as intended. However, ...

Adaptable and scalable

Hello everyone, I could use some assistance in identifying where I may have made errors. Can you please help me with that? I am aiming to enhance the responsiveness of the following design for mobile devices. <section class="hero"> ...

Utilizing AJAX to dynamically populate an HTML list from a database and then saving the user's newly selected value back to the database

I'm working on dynamically populating a list from a database using AJAX and then updating the selected value back to the database with a servlet. What's the best approach for achieving this? Typically, I use the following code for dynamic update ...

``I'm experiencing an issue with the Bootstrap 4 accordion where it is only functioning properly for the

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapc ...

Adjustable div height: reduce until reaching a certain point and then begin expanding once more

Incorporating a hero section to display content is my current approach. The design adapts responsively utilizing the padding-bottom percentage strategy, along with an inner container that is absolutely positioned for central alignment of the content. The ...

Is it possible to stack navbar items in CSS?

I'm facing an issue with my navbar menu items overlapping on top of each other. https://i.sstatic.net/dEEpx.png What could be the reason behind this? Codepen Link: https://codepen.io/ogonzales/pen/mdeNNLB Code Snippet: <nav class="navbar navb ...

Unable to set height:auto for the background image

For more information, visit this link. I am looking to customize the comments area by giving it a solid color that dynamically adjusts its height based on the number of comments. The background color should expand if there are many comments and shrink if ...

Having trouble positioning the image at the center of the ion-slides

I'm currently working on designing a slide within an ion item. Everything seems to be functioning correctly, however, the image inside the slide is not appearing in the center. <ion-item style="height:45%; padding-left: 0;"> <ion-slides ce ...

What is the process for modifying the value of a concatenated string?

I have a scenario where I need to extract the date of a blog post from one page on a website and display it on another page within the same site. Initially, the date is shown as 2/22/18 on the first page. With the jQuery code provided below, I am able to ...

The selection form does not display a preview of the options

I recently discovered that the CSS I added is causing the preview of select options in my form to disappear. Despite searching online, I have been unable to find a solution to this issue. Here is the problematic CSS code: .form-control{ height: 50px; ...

Is it possible to emphasize a single character within the alternative text of an image element by underlining it

I have a client who requires a specific character in their name to be underlined. How can this be achieved using the alt attribute of an img element? <img alt="ab<u>c</u>def" /> <img alt="ab&lt;u&gt;c&lt;/u&gt;def" /&g ...

What is wrong with my notecards that they won't flip properly?

I am currently developing a text-to-flashcard program using HTML, CSS, and JS. One feature I'm working on is the ability to flip all flashcards at once with a single button click. Currently, the program only allows flipping from the back face to the f ...