Displaying images that fill the entire screen in two separate columns

I'm new to web design and attempted to create a full-screen page with two images, but the outcome was less than ideal. Here's what I'm aiming for: A webpage where one image covers 50% of the horizontal browser window space, while the second image occupies the remaining portion on the right side. Both images should be responsive and maintain 100% height at all times, with cropping occurring on the left and right edges as the window is resized. This is similar to the layout seen here:

Is this a challenging task? I tried following online tutorials, but my images ended up stretched instead of cropped. Could it be that I need to create two columns and insert the images within them? Any guidance would be greatly appreciated.

Below is the current code snippet I've been working with:

.photo{
    size: 100%;
    position: relative;
    overflow: hidden;
}

.photo img{
    max-width: 50%;
    height: 100%;
}

Answer №1

The website you provided demonstrated a similar concept:

http://jsfiddle.net/xnLn6s5o/

HTML

<div id="container">
    <div id="left" class="halfwidthcontainer">
        <div id="left-image" class="image"></div>
    </div>
    <div id="right" class="halfwidthcontainer">
        <div id="right-image" class="image"></div>
    </div>
</div>

CSS

html, body, #container, #left, #right, #left-image, #right-image {
    height:100%;
}

.halfwidthcontainer {
    float: left;
    width: 50%;
}

.image {
    background-size: container;
    background-repeat: no-repeat;
    background-position: 50% 50%;

}

#left-image {
    background-color: red;
    background-image: url('');
}

#right-image {
    background-color: blue;
    background-image: url('');
}

The basic concept involves two containers placed side by side using the float property (refer to this answer for why float is used over inline-block).

The strategy then leverages the CSS background property to achieve desired overflow and positioning effects. More information on this can be found here.

To customize, ensure to specify the correct image URLs in the background-image properties of the #left-image and #right-image IDs.

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

JavaScript Code: Empty a text box when a different one is active

Looking for a solution to clear the content of one textbox when the user interacts with another in HTML and JavaScript. <input id="tb1" type="text" name="textbox1"> <input id="tb2" type="text" name="textbox2"> Seeking JavaScript code that wil ...

Problems with CSS animations on mobile devices in WordPress

On my website powered by Elementor Pro, I have implemented custom CSS to animate the Shape Divider with a "Brush Wave" style. Below is the code snippet: .elementor-shape-bottom .elementor-shape-top .elementor-shape body { overflow-x:hidden; } @keyframes ...

Conceal Class When Input Value is "X"

Is there a way to dynamically hide a specific seller (<div class="seller">) from a table using CSS and PHP based on a get parameter? Each seller has a unique ID represented by <input type="hidden" value="1" name="seller_id">. For example, if I ...

Encountering spacing problems among elements in the Dropdown Menu

I'm currently experiencing an issue with the Drop-Down Navigation menu that I created using HTML and CSS. When I tried to add padding between the list of UL elements, I noticed that the padding was inconsistent across the elements. For example, the st ...

The child elements are stacking vertically despite implementing inline-block

I have a container with 100% width. I am trying to position three divs inside it next to each other, all with the same height as the parent. Unfortunately, despite setting the display property to inline-block, they are not aligning properly and appear sta ...

Modify the background color of a list with jQuery

I have a list where I am adding data through Ajax and I want to change the background color of the selected list item. Here is my list: <div class="widget-content" > <ul class="news-items" id='jq_friendList'> ...

Assign a class to the checkbox of the first parent

I have a set of checkboxes generated using a for loop. I want the first checkbox to act as a parent, and all other checkboxes should act as children. When the parent checkbox is clicked, all child checkboxes should be checked. Although I have code to achi ...

Issues with Youtube Subscription Functionality

I implemented the code below to embed a YouTube subscribe button on my website: <script src="https://apis.google.com/js/platform.js"></script> <div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-layout="default" data-count="def ...

Issue with menu display on Internet Explorer

Having some trouble with IE. My menu displays fine in Firefox and Chrome, but IE is causing issues... It seems that IE isn't rendering the <li> tag properly, so my dropdown menu isn't functioning in IE. Can anyone assist me? Here's t ...

A step-by-step guide on modifying the box-shadow color using jquery

I have developed some JavaScript code that adjusts the box-shadow of buttons to be a darker version of their background color. This allows users to dynamically change the button background colors. The current code successfully changes the box shadow based ...

"Components in Vue remain consistent in their behavior regardless of the various calls made to

I am attempting to create a Vue component that displays an image, opens a modal with a second image, and then replaces the first image with a third one. The first and third images work as intended, but the image in the modal never updates. It keeps reusing ...

Avoiding the repetition of CSS animations during Gatsby page hydration

I am facing an issue in Gatsby where I have an element with an initial CSS animation. It works perfectly when the static site loads, but after hydration, it keeps repeating. Is there a way to prevent this from happening? Below is my styled components code ...

Adapt Non-Adjacent Content Sections For XL Screens in Sidebar Without Replicating Source Code Segments

I'm struggling to figure out how to achieve my desired layout. Details The solution presented by sheriffderek using CSS grid seems promising, but it causes issues with white space when adding content to the profile block on XL screens. Adjusting the ...

AngularJS: Utilizing bold text to enhance the separation of concerns between controllers and templates

In my AngularJS version 1 application with Ecmascript 6, I have a requirement to display a string where one part is in normal weight and the other part is bold. For instance, consider the following scenarios: Will start now Will start in 6 minutes Will ...

Having trouble setting up a bootstrap Carousel. It's giving me some issues

I'm encountering an issue with my project where the carousel is not transitioning between images as expected. Here's a snippet of the code causing trouble: <!DOCTYPE HTML> <html lang="en"> <head> <meta ...

Adjust the height of a div element and enable scrolling to fit the

There are numerous inquiries regarding this particular issue. I have exhausted nearly all possible solutions I could find, yet none of them delivered the desired outcome. This is the structure of my page: <div> <header id="status"> / ...

Guide to displaying text following a checkbox using JavaScript without the need for manual HTML edits

I am running into difficulties ... How can I generate a new node and insert it FOLLOWING the checkbox labeled "Special Order"? However, my attempt replaces the checkbox with the text. Unfortunately, I am unable to modify the HTML directly as it is generat ...

Apply a 2 pixel top border to an HTML table

Is there a way to add a double border at the headcell without using background images? Currently, I have a white color border top and want to add a grey color border on top of the white one. Is it possible to achieve something like #ccc and #fff for borde ...

Retrieve the ID of the clicked list item

Below is a list that I have: <ol class="sortable ui-sortable"> <li id="list_1608"><div>One</div></li> <li id="list_1609"><div>Two</div></li> <li id="list_1610"><div>Three</di ...

What is the best way to display the full image within the container?

The dimensions of the image are 6024x4024. I have tried hiding the overflow, but for some reason, I am unable to display the entire image within the container. Instead, it appears that the image is being zoomed in on. .section1{ background-image: ur ...