Split the page in half with a background image on one side and text on the other

Is there a way to split the page vertically, with a background image on one side and text on the other? I've been struggling to achieve this layout - the background image won't stay on the left while the text remains on the right. Can someone offer some guidance or solutions?

jsfiddle - https://jsfiddle.net/egLf2b9p/

#half-text-half-image {
        display : flex;
        align-items : center;
      }
      .half-width-img, .half-width-text {
        width: 50%;
      }
      .half-width-text {
        padding: 0 0px;
        text-align: justify;
      }
      .half-width-img {
        width:50%;
        min-height:100%;
        position:fixed;
        height:auto;
        background-repeat: no-repeat;
        background-size: cover;
      }
<div id="half-text-half-image">
      <div class="half-width-img" style="background-image: url('http://www.arfhamptons.org/wp-content/gallery/garden-tour-2016/IMG_2680.jpg');"></div>
      <div class="half-width-text">
        (Your text content goes here)
      </div>
    </div>

Answer №1

To achieve the desired layout, simply utilize one div element with left padding set to 50%, and include a background image with a size of 50%:

#half-text-half-image {
  padding: 0 0 0 50%;
  background-image: url('https://example.com/image.jpg');
  background-repeat: no-repeat;
  background-size: 50%;
}
<div id="half-text-half-image">
  Lorem ipsum dolor sit amet...
</div>

Answer №2

Here is the solution I came up with, utilizing a flexbox layout to divide the page:

.container {
  display: flex;
}
<div class="container">
  <div class="image">
    <img src="http://placehold.it/200">
  </div>
  <div class="text">Text</div>
</div>

Answer №3

Here is a solution that may fit your needs:

body { margin: 0; padding: 0; }
#half-text-half-image { position: relative; }
.half-width-img, .half-width-text { width: 50%; }
.half-width-text {
  position: relative;
  padding: 0 0px;
  text-align: justify;
  left: 50%;
}
.half-width-img {
  min-height:100%;
  position:fixed;
  height:auto;
  background-repeat: no-repeat;
  background-size: cover;
}

Answer №4

If you're looking to enhance your code, give this a try:

#half-text-half-image {
  display : flex;
}
.half-width-img, .half-width-text {
  width: 50%;
}
.half-width-text {
  padding: 0 0px;
  text-align: justify;
}
.half-width-img {
    min-height:100%;  
    height:auto;
    background-repeat: no-repeat;
    background-size: cover;
}
<div id="half-text-half-image">
<div class="half-width-img" style="background-image: url('http://www.arfhamptons.org/wp-content/gallery/garden-tour-2016/IMG_2680.jpg');"></div><div class="half-width-text">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,
</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

Align the ion content (or text or label) to the center vertically

I am striving to achieve a similar look as shown in the following images: However, I am currently at this stage: Please note that the first image showcases a bootstrap form, while the second image displays my design using ionic. Although I prefer not to ...

Application closed because of excessive CPU usage on iOS version 13.2

A recent issue has been discovered with my location tracking and geofencing app on iOS 13.2. The app, which used to run in the background for days or weeks on an iOS 12.2 device, now gets terminated after several hours due to excessive CPU usage. Date/Tim ...

Animating elements within Firefox can sometimes cause adjacent elements to shift positions

Currently, I am working on a single-page website that utilizes keyboard-controlled scrolling. To achieve the desired scroll effect, I have developed a JavaScript function that animates divs. Here is the JavaScript code: var current_page = "#first"; func ...

Tips for applying a class to two elements when a checkbox is clicked and avoiding duplicated URL strings

Issue with Checkbox Selection In my project, I have implemented two tabbed containers for grid and list view. Each container contains multiple elements called info boxes with checkbox inputs. Whenever a checkbox is checked, the background color of the res ...

I am having trouble properly positioning an icon next to its corresponding text within a menu item

I'm a newcomer to the world of HTML5 + CSS3 and I'm having trouble with aligning menus, text, and icons within the menu. Here's the issue: Each line of the menu consists of an icon and a text description. The problem is that they are too clo ...

Ways to align div elements

I am currently in the process of developing my own custom animation player. Utilizing Three.js for object rendering has been successful so far. However, the challenge lies in incorporating control options at the bottom of the player interface (such as play ...

HTML: A peculiar table setup with an image displayed on the right side and text aligned to the left side. Strangely, the

Just starting out and seeking assistance <table style="border:none" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="border:none" valign="top" vertical-align:"top"; width="20%"> <div><img class= ...

An error occurs when attempting to echo empty values from an array due to the "undefined index" issue being

Answering this question seems quite straightforward. Let me outline what needs to be done. I possess an array $polarity_array The array holds values in the form of HTML tags that present images. However, there are some empty values in the array because ...

Tips on retrieving an object in a JavaScript function through an HTML event

The js function code is as follows: //Assigning the index of theater array to a variable $scope.setTheaterValue = function(name) { var index = $scope.path.map(function(s){return s.name}).indexOf(name); $scope.path = $scope.path[index]. ...

Is there a way for me to use an ajax xmlhttprequest to submit all the selected values from my radio buttons?

Here's the situation: I have four input forms [A-D] and I have selected options A and B. I want to transfer this information to another page, but I'm not sure how to do it. I've tried searching for tutorials on AJAX, but most of them focus ...

What is the best way to show a pop-up message to a visitor on my site for the first time

I am seeking a way to showcase a popup the first time a user lands on my website. At present, the popup appears only upon page refresh. Check out the demo below: var popupdisplayed = false; jQuery(function() { jQuery('[data-popup-close]').o ...

Identify the element with the active class name as the primary focus

Can anyone assist with this issue? Below is an example of the code I am working with: import React, { useRef, useEffect } from "react"; function App() { const inputRef = useRef(null); useEffect(() => { const testElement = document.qu ...

Assorted dimensions of square grid

Is it feasible to achieve the following using only HTML and CSS? The condition is that since the divs are automatically generated in a list, they should not be nested within another HTML element (such as adding a div for each line is restricted): Here is ...

Is it possible to generate an image from HTML using PHP?

Can anyone suggest a way to generate an image from pure HTML using PHP, possibly utilizing the GD library or other similar tools? I am looking to display icons from external sites and considering if creating an image would help improve load times. If not ...

'Dynamic' styling in Next.js using conditional CSS

I am exploring ways to style elements based on their parameters. I have been searching for terms like "conditional css react" and "implementing conditional styles in react with css". Here is a snippet of my code: e.g. <div class="ChatComponent_ ...

Arranging of the fetch_assoc

As a complete beginner in programming, I am excited to share that I have recently embarked on this journey and had only a few classes so far. Currently, I am working on developing a new website just for fun. It is intended for me and my colleagues at work ...

Sending a form cancellation submission within a nested function call

I need help preventing my form from submitting in case the confirmation message is cancelled. How can I achieve this within the each() loop? $('#myForm').submit(function() { var inputs = $(this).find('input:checked'); inputs.ea ...

Exploring Java Programming with HTMLEditorKit

Here is my source code: I am trying to change the font color using only CSS. This is how I am inserting HTML: <span class="tag1">I love <span class="tag2">apple</span></span><span class="tag2"> pie</span> When using ...

Styling with CSS: Utilizing the Float Left Property to Anchor Elements

Currently, I have implemented an anchor element that utilizes a CSS class to replace the text with an image. Despite its unusual nature, the end result is mostly satisfactory. .toolLink a { overflow:hidden; } .toolEdit { float:left; ba ...

Choose and output all the tables contained within the database

I've checked my code and I don't see any errors, but for some reason, no data is being displayed on my page. Can anyone offer some help or insight into what may be wrong with my code? Thank you in advance! <?php if(logged_in() === tru ...