Using a single div to display a sequence of background images one after the other

Picture this scenario: I have two images, one measuring 1px by 700px and the other 1px by 800px. Is there a way in CSS3 to set them as backgrounds for one div which will then have a total height of 1500px?

Can this be achieved with CSS3 alone?

div{
    background: url(first_image.jpg) repeat-x, url(second_image.jpg) repeat-x;
    /* ... */
}

I could combine these images in Photoshop, but I'm curious if there's a pure CSS3 solution.

Currently, I've created two separate divs each with its own background image, and they appear seamless when placed together. However, my issue arises when there's an element that needs to occupy the precise area where these two divs meet. Placing this element disrupts the layout. While I could use position: absolute to resolve this, I'd prefer to find an alternative approach.

Answer №1

By setting the height of the div to match both background images, you can utilize the bottom property to position the second background image below the first.

Illustration

div {
  background: url(http://www.placehold.it/5X100) repeat-x, 
  url(http://www.placehold.it/5X100/FF0000) bottom repeat-x;
  height: 200px;
}
<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

What is the best way to customize the CSS of the Skype contact me button?

I am struggling with customizing the Skype contact me button. The standard Skype button has a margin of 24px and vertical-align set to -30px. I have tried removing these styles but have had no success. Here is the code snippet I am working with: Skype ...

Why are you leaving a trail of timestamps in your .css files?

Within certain source codes, I have observed the following: <link rel="stylesheet" href="/css/style.css?201007071609" type="text/css" /> This prompts my question: What is the purpose behind appending 201007071609 to style.css in the code snippet ab ...

The table's style is not rendering properly with lengthy names

Seeking assistance with styling a table on my website. Please take a look at my website. If you search for "Rochester, mn" and scroll down, you'll notice that for long names like Tilson's Automotive and Goodyear, the text falls below the image in ...

Keep bootstrap content aligned to the left

I am working on creating a webpage using bulma/bootstrap and my goal is to have some text positioned on the left side of the screen. I want this text to be displayed in the red area and to stay fixed in place when I scroll down, similar to a side panel. ...

The Intriguing Riddle of HTML Semantic

I've been working on a puzzle presented in the link provided below: HTML Structure Challenge This mind-teaser consists of three questions: Modify the HTML code of the website to enhance its structure as follows: Replace the generic outer div eleme ...

Vue component always renders a new line

Whenever I include a <component> tag in my main application, it always renders on a new line. Is there a way to make it inline? I am trying to achieve something like this: <p>This is a component :<component></component></p> & ...

Troubleshooting: Issue with fixed positioning in React (Next.js) causing problems with modal window functionality

I'm currently working on implementing a modal window in React, but I've encountered an issue where setting position: fixed results in the modal window's position being relative to the page rather than the browser window. For privacy reasons, ...

Javascript code for toggling the visibility of a div element not functioning as expected

This problem is becoming quite frustrating as it appears to be straightforward but still doesn't work. Inside my document, I have <div id ="splashscreen" style="display:block"> <h3>title</h3> <p>text</p> &l ...

After migrating the Django website to a new instance, the CSS ceased to function properly

I recently made the switch from hosting my website on Redhat to Amazon Linux on EC2 due to the cost savings. After configuring the Apache server and Django settings, the website seemed to be functioning properly except for the layout of the HTML. The CSS w ...

Tips for inserting an image within two divs within the .row class (leveraging Bootstrap 4)

Take a look at my code snippet: <div class="row"style=""> <div class="panel panel-success col-sm-3" style="background-color: #d16b55; "> <div class="panel-body" style="height: 1000px; margin-left: 50px;overflow: hidden !important;"> ...

Conceal navigation options on smaller screens and enable drop-down menu functionality with Bootstrap 3

With the usage of Bootstrap 3, I have successfully hidden two menu items when the screen is resized. However, these items still appear in the drop down menu that appears on the top left (with three bars) when the screen size is reduced. Is there a way to k ...

Utilizing jQuery to pinpoint the exact position within a Flexbox container

I have a unique setup with multiple boxes arranged using Flexbox as the container and list tags as individual boxes inside. These boxes are responsive and change position as the width is resized. My goal is to use jQuery to detect which boxes are touching ...

The height of the iframe with the id 'iframe' is not functioning as expected

I am trying to set the iFrame's height to 80% and have an advertisement take up the remaining 20%. Code <!DOCTYPE html> <html lang="en"> <head> </head> <body> <iframe id="iframe" src="xxxxxx" style="border: ...

Is there a more efficient approach to applying a basic function to multiple elements within a DIV and having it activate only upon a click event using jQuery?

This solution works, but I am looking for a more professional approach in order to adhere to the principle of "don't repeat yourself." $("document").ready(function(){ $(".child").each(function(index){ $(this).click(func ...

The Bootstrap 3 Navbar displays a #EEEEEE color when a link is hovered over

I have not specified a hover color in the stylesheet for links to be #EEEEEE. I want the navbar hover effect to blend in with the navbar background, creating a seamless transition when hovered over. For reference, here is my current stylesheet code: Paste ...

Is there a way to create a fixed container aligned to the right and have the parent container handle scrolling?

My setup is as follows: Full width, 100px height header The header is always visible at the top. Full width, remaining height details The content of details can scroll vertically and horizontally. A fixed 200px width, full height container is right- ...

Excessive spacing issues arise while adjusting CSS height, leading to undesirable vertical scrolling

One of the features of my website is a post section where users can leave comments. These comments are displayed at the bottom of the post. To enhance user experience, I decided to create a modal for posts using HTML and CSS as shown below. However, I enc ...

Ensuring Consistent Placement of Elements Regardless of Screen Size with CSS

I'm currently working on an Ionic App and I need to position some buttons (stacked vertically) at the bottom-left corner of the device's screen. Here is the CSS I am using: .button { left = "1em"; z-index = "13"; overflow = "scroll"; ...

Display a selected portion of the background image

I'm currently facing an issue with one of the background images in my div element. The CSS I'm using is as follows: .myBox { background-image:url('....'); background-repeat:no-repeat; background-size:cover; } The background image d ...

Use jQuery to change the background color when clicked

Below is the HTML code with UL and LI elements: <UL> <LI><span id='select1'>Text</span></LI> <LI><span id='select2'>Text</span></LI> <LI><span id='select3'>Tex ...