varied background pattern repeating horizontally on both sides

Looking for help achieving a design where I have a centered header with an image split into red on the right and blue on the left. I want to do a background repeat-x with the red color extending to the right and the blue color extending to the left of the image.

Any advice on how to achieve this effect would be greatly appreciated!

** Update: Apologies for the confusion, I actually have 3 images. One needs to be centered, one should repeat-x to the right, and the other should repeat-x to the left.

Answer №1

If you require assistance with compatibility for older browsers, the first method is available

HTML

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <link rel="stylesheet" href="css/all.css"/>
    <title>STACKOVERFLOW</title>
</head>
<body>
<div class="wrapper">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab consequuntur, dolorum ex, fugit incidunt ipsa ipsam minus natus necessitatibus nisi odit officiis, perspiciatis recusandae repellendus sit totam vero voluptates. Illum temporibus vero voluptates! Accusamus atque consequatur debitis earum explicabo harum, impedit nesciunt quisquam temporibus ut! Accusamus adipisci at, aut cum dignissimos distinctio dolore ducimus eos eum, ex fuga fugiat impedit ipsam iusto magnam minima molestiae nemo nesciunt optio perspiciatis quisquam quos sapiente similique soluta sunt voluptatem, voluptates voluptatibus! A animi autem deserunt doloribus eos esse fugiat fugit ipsum labore magni maiores maxime mollitia nesciunt nostrum odio, pariatur quas quod rerum, tempore vero. Blanditiis eaque illo laudantium, natus porro quisquam repudiandae temporibus totam voluptas? Aliquid consectetur consequuntur corporis earum labore quae qui quod suscipit tenetur vel. Adipisci commodi culpa debitis doloribus dolorum nisi possimus quas quia rem repellendus, unde veritatis voluptas voluptates! Ab ad aperiam, autem delectus earum error incidunt maiores odit, omnis, quibusdam quos soluta tempore veritatis. Aperiam atque laudantium mollitia? Accusantium adipisci earum minima reprehenderit tempore! Autem, deleniti dicta ea illo maxime pariatur praesentium quam similique vel voluptate! A ab doloribus eligendi est eum inventore, iusto laboriosam minima natus nesciunt omnis porro possimus, reiciendis sint unde ut veritatis vitae, voluptatem? Ab ad amet at blanditiis corporis culpa cum cumque delectus dolorem ducimus eaque earum eius eligendi eveniet ex, facere fuga illo ipsam labore laboriosam, molestias necessitatibus numquam perspiciatis reprehenderit repudiandae suscipit, voluptatibus? Aspernatur dolor dolores earum eveniet fugiat illo ipsum magni nam nulla sapiente? Aliquam consectetur consequuntur deleniti dignissimos dolor eos est, fuga hic iste labore obcaecati perspiciatis quas recusandae sequi similique. Adipisci aliquam architecto aspernatur aut corporis deserunt dicta doloremque ducimus enim error esse exercitationem expedita facere fuga fugit hic id inventore ipsam magni maxime molestiae neque nesciunt nisi nulla odit, optio perspiciatis quisquam recusandae reprehenderit saepe sunt ut vel vitae? Delectus dolores eaque eum itaque libero molestiae, perferendis placeat quae quam quis quod sequi similique? Adipisci aperiam commodi consequuntur cumque distinctio ducimus eum ex fugiat illum ipsa iure iusto magni maxime molestias nam non, numquam pariatur placeat quaerat quasi qui quisquam ratione recusandae rem saepe sapiente sequi sint sunt vel veritatis? Accusantium aut beatae consectetur eaque fuga quia repellat repellendus. Dolores eligendi esse laudantium maiores minima possimus provident similique veritatis voluptatibus. Consequuntur delectus dolore dolorum eaque eveniet ex exercitationem expedita facilis harum illo inventore ipsum iste iure iusto libero magnam molestiae necessitatibus, nesciunt nisi nostrum numquam odio quae quia quidem reiciendis rem repudiandae sequi sit soluta ullam vel veniam voluptatem voluptatum. Alias, atque consequuntur deleniti deserunt dolorum enim esse harum hic ipsa iure maxime modi, nam nostrum optio provident quaerat quas quia tenetur totam voluptatum! Earum et nihil possimus quae? Aliquam delectus distinctio dolorum ex minus repellat sit ut. Alias at commodi dignissimos doloribus, illo illum maiores maxime molestiae numquam perspiciatis provident quibusdam, quis, totam voluptate voluptatum? Aspernatur cupiditate dolores perferendis repellendus sit. Aliquam aspernatur iure, labore maxime, natus omnis pariatur porro provident quis ratione voluptatem voluptatum. Dolorem explicabo harum minima molestias necessitatibus neque possimus quis ut.</p>
</div>
</body>
</html>

CSS

.wrapper {
    width: 100%;
    overflow: hidden;
    position: relative;
}
.wrapper:after {
    content:'';
    background: #f00;
    position: absolute;
    top: 0;
    left: 0; /*position of the first bg*/
    width: 50%;
    height: 100%;
    z-index:-1;
}
.wrapper:before {
    content:'';
    background: #000;
    position: absolute;
    top: 0;
    left: 50%; /*position where you need 2nd bg*/
    width: 50%;
    height: 100%;
    z-index:-1;
}

2. Method

If Multiple Backgrounds are needed, please note that this feature is only supported from IE 9+

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

Creating generic types for a function that builds <options>

I have encountered a situation in my application where I need to loop through an array to construct a list of <option> tags. To streamline this process, I am attempting to create a universal function. function optionValues<T, K extends keyof T> ...

Execute two operations using jQuery and PHP

I recently created a form for users to fill out, with the data being sent to my email. However, I also wanted the email information to be posted to my MailChimp account using their API. Unfortunately, this feature is currently not functioning correctly. B ...

Issue with onClick event not triggering within echo statement when using AJAX

When inserting the following code snippet into the head section of a page: <script type="text/javascript"> function vote() { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject( ...

Variations in functionality within the Google Chrome browser

This is the content of my HTML document. <BODY> <button id="b1" onclick="load()">Play</button> <canvas id="c1" onclick="f_clicked(this.id,1)"> Your browser does not support the HTML5 canvas tag. </canvas> ...

Alter the loaded image based on the switch's current status

I am working with AngularJS material and I want to dynamically load an image based on the status of a switch. Here is the relevant HTML code: If the switch status sw_status.sw1 is true, then load the image truePic.jpg. If it is false, load the image false ...

Issues with click events in the navigation menu

How can I make my menu close when clicking on other parts of my website, instead of opening? I know that I should use a click event for this, but when I implemented a click event, my menu encountered 2 unwanted problems: 1- Whenever I clicked on a menu i ...

Troubleshooting issues with displaying anchor tags using Jquery

I am facing an issue where I am unable to make an anchor tag visible using the .show() method in JQuery or JavaScript. The Conn Window is visible by default, and I am able to hide and display the div, but the same does not apply to the anchor tag. Interest ...

Tips for inputting a password using Selenium webdriver when the password style is set to display:none

Currently, I am facing an issue with logging in to a page that has both a login and password field (betmarathon[d.o.t]com) using Selenium Webdriver. While Selenium is able to enter the login correctly, I am encountering difficulties when it comes to enteri ...

Tips on adjusting the height of divs in a simple layout

I'm trying to make two divs fill the page with a ratio of 70% and 30%. However, I don't want to set the size of the "html" or "body" elements. How can I achieve this without affecting the height of the text within the divs? Currently, it only dis ...

AngularJS making a HttpPost request resulting in a 500-Internal Server Error

I'm currently working on an application where I need to include a user in the database which requires a POST operation. However, every time I try to run the application, I encounter a 500-Internal Server Error for the POST API call. Here is a snippe ...

When you have a target element that is deeply nested, consider using a 50% height relative to

There is some confusion surrounding the issue below: <div class="container"> <div class="row"> <div class="group"> <a> <div class="col-lg-3 full-h"></div> </a> <a> < ...

The React popup window refuses to close on mobile devices

I am currently facing an issue with a site (a react app) deployed on GitHub pages. The site features cards that, when clicked on, should open a modal/dialog box. Ideally, clicking on the modal should close it. However, I have encountered a problem specific ...

The correct alignment of images is crucial for a website's overall aesthetics and functionality

My column displays images aligned in the center when viewed locally, but the alignment changes when hosted remotely. Here is the image when locally hosted: https://i.sstatic.net/I56Dg.png And here is the remote host image: https://i.sstatic.net/ePoAn.p ...

Creating a line that connects Point A to Point B using HTML, CSS, and JavaScript

Essentially, I am looking to create a line that connects point A (0vh|0vw) to point B (50vh|50vw). Initially, I considered using a div with a border and a 1px height that is rotated to achieve the desired effect. However, the issue arises when the size ...

Refreshing HTML tables with AJAX in Django

After going through all the posts here, I found that some are outdated and others don't quite match my issue. Apologies for bringing it up again. I have a basic HTML table with data in it. My goal is to update this data without refreshing the entire ...

Creating Functional Tabs Using CSS and JavaScript

I've been experimenting with this code snippet, trying to get it to work better. It's still a work in progress as I'm new to this and have only customized it for my phone so far. The issue can be seen by clicking on the Projects and Today ta ...

Potential Performance Issue with Material UI's withStyles Function

I've been given the task of optimizing the loading speed of a page in our react redux web app. When the page load action is triggered, there seems to be a slight freeze lasting about half a second. After checking the profiler, everything seems fine ...

Two Ajax Requests Simultaneously

I am currently faced with the challenge of handling two requests simultaneously. The first request involves executing a lengthy PHP script that takes 10 minutes to complete (I cannot modify it using JavaScript, so that's not an option). The second ...

JavaScript undefined error occurred during runtime

Greetings! I come from a background in VB6 and VB.Net, and I am currently delving into Bootstrap/MVC with C#. Please pardon my beginner queries as I journey through this new territory. I have searched on SO and watched YouTube tutorials, but I am still fin ...

The website showcases mobile responsiveness; however, it does not translate to mobile devices

Hello Stockoverflow Community, Recently, I encountered an issue with the responsiveness of my website: The design on desktop appears as: [deleted] However, the mobile version displays as: [deleted] I have already tried clearing my cache, both on Cloudf ...