What is the best way to divide a web page screen into three equal horizontal sections?

My goal is to split the screen into three equal sections horizontally so that I can place different images in each section. However, despite my efforts, I am encountering issues with white space and unequal division.

This is my current setup:

HTML:


        <div class="split left">
            <div class="centered">
                <img src="img_avatar2.png" alt="Avatar woman">
            </div>
        </div>

        <div class="split center">
            <div class="centered">
                <img src="img_avatar.png" alt="Avatar man">
            </div>
        </div>

        <div class="split right">
            <div class="centered">
                <img src="golf_course.jpg" alt="Finished Terrain Golf Course">
            </div>
        </div>
    

CSS:


        /* Splitting the screen into thirds */
        .split {
            height: 100%;
            width: 33.3333%;
            position: fixed;
            z-index: 1;
            top: 0;
            overflow-x: hidden;
            padding-top: 20px;
        }

        /* Styling for the left section */
        .left {
            left: 0;
            background-color: #111;
        }

        /* Styling for the right section */
        .right {
            right: 0;
            background-color: red;
        }

        /* Styling for the center section */
        .center {
            right: auto;
            left: auto;
            background-color: wheat;
        }

        /* Centering the content both horizontally and vertically */
        .centered {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }

        /* Additional styling for images within the centered container */
        .centered img {
            width: 150px;
            border-radius: 50%;
        }
    

Image: https://i.sstatic.net/0LpTk.png

Answer №1

To create a layout with equal spacing using flexbox, you can follow this example:

.container {
  display: flex;
  justify-content: space-between;
}
.container div {
  width: 100%;
  padding: 5px;
  border: 1px solid black;
}
<div class="container">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

Answer №3

Initially, the property width: available is not recognized as a valid property. If you intend to utilize all the available space, it would be more appropriate to set the width to 100%. To address your specific problem, it is recommended to also apply height: 100% for both body and html elements. Refer to the following example:

body, html {
  width: 100%;
  height: 100%;
  margin: 0;
}
.container {
  width: 100%;
  height: 100%;
}
.leftpane {
    width: 33%;
    height: 100%;
    float: left;
    background-color: rosybrown;
    border-collapse: collapse;
}
.middlepane {
    width: 33%;
    height: 100%;
    float: left;
    background-color: royalblue;
    border-collapse: collapse;
}
.rightpane {
  width: 33%;
  height: 100%;
  position: relative;
  float: right;
  background-color: yellow;
  border-collapse: collapse;
}

<div class="container">
  <div class="leftpane">
    <h1>Test Page</h1></div>
  <div class="middlepane">Test Page</div>
  <div class="rightpane">
    <h1>Test Page</h1></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

Updating the navigation with a dynamic CSS class using jQuery

Hey there, I'm on the lookout for a simple and discreet method to dynamically add an "active" class to a navigation menu based on the current directory. Unfortunately, I am unable to modify the body tag with a custom class, ruling out a pure CSS solut ...

Issues creating bar graphs using HTML

I am currently working on creating a script that can display statistics from a database in the form of a bar chart. My idea is to have two colored bars stacked on top of each other, representing different values simultaneously - for example, the number of ...

Tips for customizing MUI PaperProps using styled components

I am trying to customize the width of the menu using styled components in MUI. Initially, I attempted the following: const StyledMenu = styled(Menu)` && { width: 100%; } `; However, this did not have any effect. After further research, I ...

Utilize JavaScript to seamlessly play a Spotify track within the Spotify client without disrupting your current

A little while back, I recall the simplicity of clicking play on a song within a website and having it instantly start playing on my computer without any additional steps. It was seamless and effortless. My goal for my website is to have music start playi ...

The dynamic duo: Selenium and HTML!

For the past few days, I've been using selenium to extract information from a private database of company data. Unfortunately, due to the password protection of the database, I can't share the entire python code or HTML code. Here is the specifi ...

The utilization of Server.Execute leads to inaccurate HTML rendering exclusively on IE9

Issue - I am encountering a problem with the rendering of a page in different versions of Internet Explorer. The page contains multiple nested div elements, and when calling server.execute within one of the child divs, the output is being displayed incons ...

Can we create a dynamic Context Menu?

I visited the following link: https://codepen.io/templarian/pen/VLKZLB After clicking on More Options, I need to display dynamically populated names like var Obj = [{name:"1st Item",taste:"sweet"},{name:"2nd item",taste:"spicy"}]; Instead of "Alert ...

Guide on How to Show Only the Initial Word of an H2 Header Using JavaScript or CSS

Is there a way to display only the first word from an h2 heading? For instance: In the website's source code, it would appear like this <h2> Stackoverflow is an Ideal Place</h2> But on the live website, it should be displayed like this ...

Is it possible to utilize PHP for creating mobile applications in order to submit HTML forms via email?

Currently exploring the creation of an HTML app with Cordova. I have experience creating forms for websites and using PHP to send form submissions via email. However, I am unsure if I can use PHP in my app for this purpose. Are there any resources or art ...

Can the placement of divs impact search engine optimization (SEO)?

My website is currently structured with div containers in the following order: Less important left side bar Less important right side bar The core center content at last I am concerned about the impact on SEO as the core content comes after the sidebars ...

Show SVG in its ViewBox dimensions

Currently, I am utilizing the img-Tag to showcase SVG images that have been uploaded by users onto my Amazon S3 storage. <img src="http://testbucket.s3.amazonaws.com/mysvg.svg" /> An issue arises once the image is displayed as it does not retain i ...

Is the parallax effect achieved by stacking one div on top of another div?

Here is a sample of my HTML code: <div id="a" class="panels">FIXED PANEL</div> <div id="b" class="panels">Scrolling-Panel 1</div> <div id="c" class="panels">Scrolling ...

What is the best way to retrieve the value of a custom attribute from a dropdown list using either JavaScript or jQuery?

I have a dropdown list on a web form and I need to have a 'hidden' variable for each item in the list that can be retrieved using the onchange event on the client side. To achieve this, after databinding the dropdownlist, I am setting a custom at ...

What methods can be used to supersede CSS styles?

Illustrated in the example below http://jsfiddle.net/xBRPg/ My objective is to establish a yellow backdrop for a specific row in my table. However, when I utilize the code snippet below <table class="table table-bordered table-striped"> The row&a ...

Scrolling automatically

I'm experimenting with creating a typing effect using JavaScript and the typed.js library, found here: My approach involves using a div as a container. However, I've encountered an issue - when the text reaches the height of the div, scroll bars ...

Retrieve information from an HTML input field that does not have an assigned ID or name

I am facing a challenge with an HTML table that contains multiple inputs which do not have any id or name attributes. I need to retrieve data from these inputs but struggling due to the lack of identifiers. Upon inspecting the DOM, I noticed that each inp ...

Retrieve the identifiers of various HTML elements and store them in an array

Within a div, there are multiple objects. I am trying to retrieve the IDs of all elements based on their class, knowing that the number of elements may vary. So far, my attempt has been: arr = $(".listitem #checkBox").hasClass('checkedItem').att ...

Instructions for launching an Android app from a website

Is it possible to invoke my app from HTML? For instance, I am able to successfully call a webpage from my app using this code. android code: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "myDomain.com"))); ...

Tips for adjusting column spacing in HighCharts

Looking for some advice on how to make a chart container scrollable and properly space the labels and bars within a parent container with fixed width and height. The goal is to ensure all labels are visible and bars are well spaced. Any suggestions or tips ...

How come my database is not receiving the data from the first name field?

I have encountered an issue with my comment form where the first name field data is not getting sent to the database along with the comments. I have already checked that the 'first_name' column exists in the database, but still facing this proble ...