CSS Code to Add Image Which Covers Half of Page Background

This post includes 2 solutions:

  1. The 1st solution provides CSS code you can use in your child themes style.css file to display a background image which covers 50% of any page.
  2. The 2nd solution provides CSS code which uses 2 images. One to cover the background of the left half and the other to cover the right half.

Both examples use the .home page class.

One Half Background

.home {
    background-image: url('images/image.png');
    background-repeat: no-repeat;
    background-size: 50% 100%;
}

Example of what the CSS above generates:

half page background

Left & Right Background Images

Use this code to display 2 different images. One which covers 50% of the page and the other which covers the other half of the page:

.home {
    background-image: url('images/left-half.png'), url('images/right-half.png');
    background-repeat: no-repeat, no-repeat;
    background-size: 50% 100%;
    background-position: left top, right top;
}

Example of what the CSS above generates:

left and right images

Both snippets assume you have uploaded your images to your child themes images folder and the image file names and extensions match whats in the CSS.

Related Tutorials


Comments

2 responses to “CSS Code to Add Image Which Covers Half of Page Background”

  1. Brad,

    Like to last post on add an image to cover half the background of a page. How can we use this so that it only is used on certain page templates? So for example not on landing page.

    Thanks
    Mike

    1. Brad Dalton Avatar
      Brad Dalton

      The CSS class in the above example only covers your home page.

      You can change the class to any custom class, page template class or body class which you can grab from the source code.
      [code]
      .page-template-page_landing-php
      [/code]
      Otherwise you can use PHP code to add the image and exclude templates.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.