Creating a split color background in CSS with a perfectly centered image on top

Is there a way to center and scale just one image on a webpage, rather than two? I want it to be in the middle of the screen or page and resize with the window.

Image example: https://i.sstatic.net/t0AQP.png

body {
  font-family: 'Titillium Web', sans-serif;
}
#top,
#bottom {
  background: url('http://uxrepo.com/static/icon-sets/zocial/svg/chrome.svg') no-repeat center center;
  background-size: cover;
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
}
#top {
  top: 0;
  background-color: #ff0000;
}
#bottom {
  bottom: 0;
  background-color: #fff38f;
}
.header-container {
  height: 130px;
  width: 100%;
  margin: 0 auto;
  position: absolute;
  top: 130px;
}
.header {
  text-align: center;
  line-height: 16px;
  font-size: 48px;
  font-weight: 400;
  color: #ffffff;
}
.footer-container {
  height: 130px;
  width: 99%;
  margin: 0 auto;
  position: absolute;
  bottom: 0;
}
.footer {
  text-align: center;
  line-height: 16px;
}
.img {
  position: absolute;
  width: 100%;
}
<body>

  <div id="top">
    <div class="header-container">
      <div class="header">
        SOME TITLE
      </div>
    </div>
  </div>

  <div id="bottom">

    <div class="footer-container">
      <div class="footer">
        some text
        <br>
        <br>some text
        <br>some text
        <br>some text
      </div>

    </div>
  </div>

</body>

Looking for a simple solution to achieve this layout. Any ideas?

Answer №1

Using CSS Gradient for Background

Here is my method, implementing a gradient background: JSFiddle Link

<div class="gradient-background">
    <img src="image-source"/>
</div>

.gradient-background{
    background: linear-gradient(to bottom,  #db6062 0%,#db6062 50%,#db6062 50%,#dae27a 50%,#dae27a 100%);
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}
.gradient-background img{
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: 200px;
    width: 200px;
    margin: auto;
}

Answer №2

Using SVG Inline

If you are utilizing an SVG, you can easily inline it.
By placing it inline as shown in the example below,
You have the flexibility to modify all colors within the SVG using CSS.

svg {
  height: 100vh;
}
#rect1 {
  fill: firebrick;
}
#rect2 {
  fill: #229;
}
<div>
  <svg viewBox="0 0 500 400">
    <rect id="rect1" x="0" y="0" width="1000" height="200" />
    <rect id="rect2" x="0" y="200" width="1000" height="200" />
    <g transform="translate(150,100) scale(0.2)">
      <path d="(SVG Path Data Here)" />
    </g>

  </svg>
</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

Arranging social media sharing icons on a website [Facebook, Twitter, Pinterest, and Google +]

Struggling with aligning the Facebook share button in my Shopify blog page template. It seems to be 5px lower than the other share buttons. Take a look at the issue https://i.sstatic.net/u0sFp.png The code for the Facebook share button is: <div style= ...

Header Text unexpectedly breaking out of Div in Mozilla Firefox, but not in Chrome or IE

Need some help with getting the h5 text to show up inside the div with id="text". Any advice would be appreciated! Thanks for taking the time to read this! <div id="footer"> <div id="instagram"> <div id="text"> &l ...

Preventing Context Menu from Appearing on Long Click in HTML5 Games

I'm attempting to utilize a similar technique as demonstrated in this stackoverflow post: How to disable the 'save image as' popup for smartphones for <input> However, I am encountering an issue where my button is not displaying at ...

Discovering the present width of an Angular element after it has been eliminated

Imagine you have a horizontal navigation bar coded as follows: HTML: <ul> <li ng-repeat="navItem in totalNavItems">{{name}}</li> </ul> CSS: ul, li { display: inline-block; } The data for the navigation items is fetched from thi ...

Launch an Android application directly from a web browser upon the webpage's loading

When a user visits www.example.com/myApp, I want my app to open automatically without any click required. I have attempted the following methods: window.onload = function () { window.location.replace("intent://something#Intent;scheme=myapp;packag ...

extracting an attribute from a class's search functionality

Let's consider the following HTML structure: <div id="container"> <div> <div class="main" data-id="thisID"> </div> </div> </div> If I want to retrieve the value inside the data-id attribute ...

Modify HTML table cell colors based on their values

Hey there, I'm currently working on a project where I need to dynamically change the colors of an HTML table based on values retrieved from a database. To give you a better idea, here is an image showcasing what I am trying to accomplish. https://i.ss ...

The issue of not being able to go fullscreen with a YouTube iframe nested within another iframe

I have a YouTube video embedded inside another iframe, but I am facing an issue where the fullscreen feature is not working even after enabling all the required attributes. If the video isn't displaying properly in the code snippet below, you can vie ...

Steps for executing the jQuery script are as follows:

A friend shared this code with me and it's working perfectly here http://jsfiddle.net/WVLE2/ I tried replicating it on an HTML page below, but unfortunately, it's not working. I'm still learning jQuery and would appreciate any help on how t ...

Steps to utilize a PHP include for displaying HTML content corresponding to the URL file name

I am currently working on a PHP script that utilizes PHP include to insert HTML content based on the filename from the URL. For instance, with the use of PHP include: - if the filename in the URL is dog.html, it will display dog within the HTML document. ...

Conquering Bootstrap 3's Image Gallery Customizations

I am currently working with Bootstrap 3 RC1 and struggling to set up the image gallery properly. Issue 1 - The ul is adding unnecessary padding-left or margin-left. What do I need to do to eliminate this? Issue 2 - Each li is extending across the contain ...

Incorporating navigation controls into a modal window

I have successfully created a sign-in modal, but now I'm looking to include buttons at the top. One button should redirect users to register/sign up, and the other button should lead them back to the sign-in modal, as shown in the image I've link ...

Using multiple selectors in JQuery and Javascript

I have a challenge where I need to execute different actions for specific divs. Here is the code snippet I currently have: $("#pending-cancel-1, #pending-cancel-2").click(function(){ Do something special for pending-cancel-1 and pending-cancel-2... }) ...

Swap the existing div with a fresh div using jQuery or JavaScript

Seeking a straightforward method to swap out a div with a different div, ensuring cross-browser compatibility with JavaScript or jQuery. Below is a code snippet to demonstrate. The goal is to replace "myDiv-B" with a new div: <div id="myDiv-C">{% in ...

Using Python to access files

I have developed a system that allows me to load image files from HTML. However, after selecting a file and loading it from the front end, I am in need of a Python API to read the selected image file. How can I establish a connection between Python and HTM ...

Utilize a fresh font style and replace the font family components in @mui/material with the new

Looking to bring in a fresh font family stored in a fonts directory and replace the existing mui base font family. import { responsiveFontSizes, createTheme } from '@mui/material'; import NEWFONTFAMILLY from '../fonts/something.otf' c ...

The Angular 7 template falls short of occupying the entire page

I am currently working on converting an HTML page into my Angular project. While it functions correctly in the HTML version, it does not fill up the entire page when transferred to Angular. You can view an example of this issue on StackBlitz at the followi ...

Utilize Datatables to apply filters dynamically

For displaying a list loaded via an AJAX call to the server, I utilized the datatables jQuery plugin. To integrate the search input inside my sidebar, I made use of the bFilter property to hide the filter. $(function () { var generatedCustomerTable = ...

The text for the Google chart is nowhere to be found

After creating a test project using the Google Chart example, I noticed that some text from the chart is missing after adding CSS. Here is the CSS code I used: html, body { font-size: 100%; height: 100%; width: 100%; } body { background: ...

Design a dynamic tile grid layout using CSS Grid that adapts to different

I've recently started exploring the world of CSS Grid and I'm interested in creating a responsive tile-like layout using it. I found an example that I really like here: Do you think using CSS Grid is a good approach for achieving this type of la ...