A webpage featuring three columns of consistent width

Is it possible to create a page with 3 fixed-width columns using CSS?

For instance, imagine a page with a default width of 1024px, consisting of a header, div1, div2, and div3, each with a fixed width. The layout would resemble the left side of the image when Chrome is maximized.

If the user resizes Chrome to a width of 600px or smaller, since all the elements have fixed widths, div1 should be hidden and div2 should only be partially visible. Additionally, there should be a scrollbar at the bottom.

https://i.sstatic.net/e9HRM.jpg

Here is some code I've been working on. Can you provide guidance or possibly show me an example of how to achieve this?

HTML

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}

#app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    background-color: #e8eaf4;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.header{
    position: absolute;
    top: 0;
    left: 0;
    height: 60px;
    width: 100%;
    z-index: 25;
    background-color: #fff;
    border-bottom: 2px solid #daddf7;
}

.div1{
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    z-index: 10;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background-color: #fff;
    border-top: 2px solid #daddf7;
    -webkit-box-shadow: 2px 0px 4px 0px rgba(44,75,248,0.2);
    box-shadow: 2px 0px 4px 0px rgba(44,75,248,0.2);
}

.div2 {
    position: absolute;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

.div3{
    position: absolute;
    right: 0;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background-color: #fff;
}
<!DOCTYPE html>   
<html lang="en">   
<head>   
    <meta charset="UTF-8">   
    <title>Three Column Fixed Width Layout</title>    
</head>   
<body>   
    <div id="app">   
        <div class="header" style="width: 1024px; height: 60px;"></div>
        <div class="div1" style="width: 200px; height: 328px; top: 60px;"></div>
        <div class="div2" style="width: 700px; height: 328px; left: 180px; top: 60px;"></div>
        <div class="div3" style="width: 124px; height: 328px; top: 60px;"></div>
    </div>   
</body>   
</html>  

Answer №1

To create a grid of boxes, wrap child divs using the wapper class and set the main width to 1024px. Then, set the individual child widths accordingly by applying display: inline-block.

.wapper{
  width: 1024px;
}

.div1,.div2,.div3{
   background: #ccc;
   display: inline-block;
   height: 328px;
}

.div1 {
   width: 246px; 
} 

.div2 {
   width: 524px; 
}

.div3 {
   width: 246px; 
}
<div class="wapper">
  <div class="div1">1</div>
  <div class="div2">2</div>
  <div class="div3">3</div>      
</div>

Answer №2

Hopefully this solution proves to be useful for you.

Kindly test out the following CSS:

.wrapper{
  width:100%;
}
.div1,.div2,.div3{
     display: inline-block;
    vertical-align: top;
     border-top: 2px solid #daddf7;
    -webkit-box-shadow: 2px 0px 4px 0px rgba(44,75,248,0.2);
    box-shadow: 2px 0px 4px 0px rgba(44,75,248,0.2);
    background-color:#eee;
}
.div1{
  width:20%;
  height: 328px;
}
.div2{
 width:65%;
 height: 328px; 
}
.div3{
 width:12%;
 height: 328px;
}
 <div class="wrapper">
        <div class="div1"></div>
        <div class="div2" ></div>
        <div class="div3"></div>
        <div>

Answer №3

Utilizing Bootstrap for Responsive Design

When using col-4 col-xs-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 in Bootstrap, it results in the screen being divided into 4 equal portions on all device sizes.

.equal {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  flex: 1 0 auto;
}
<html>

<head>
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
</head>

<body>
  <div class="row equal" style="height: 100vh;">
    <div class="col-4 col-xs-4 col-sm-4 col-md-4 col-lg-4 col-xl-4" style="background-color: #e9d66b"></div>
    <div class="col-4 col-xs-4 col-sm-4 col-md-4 col-lg-4 col-xl-4" style="background-color: #ff9966"></div>
    <div class="col-4 col-xs-4 col-sm-4 col-md-4 col-lg-4 col-xl-4" style="background-color: #89cff0"></div>
  </div>
</body>

</html>

Link to jsFiddle Example

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

Searching for columns should be at the top of an angular datatable, not at the bottom

In my Angular 7 project, I am utilizing the library found at this link. I have followed the example provided, which can be seen here. Everything is working perfectly, except for the position of the search columns. I would like the search columns to appear ...

What is the best way to initiate a new animation from the current position?

Here is my custom box: <div class="customBox"></div> It features a unique animation: .customBox{ animation:right 5s; animation-fill-mode:forwards; padding:50px; width:0px; height:0px; display:block; background-color:bla ...

IMAGE CARDS WITH BOOTSTRAP 5

I created a bootstrap card with an image on the right side, but it doesn't fill the entire space. Below is the image of my bootstrap card: https://i.sstatic.net/k7xuT.png This is the code for my card: {% for book in thesis_details %} ...

Initiate the React application with the given external parameters

I have created a React app that is embedded within a webpage and needs to start with specific parameters obtained from the page. Currently, I am passing these parameters in the index.HTML file within a div element. The issue arises when these parameters ar ...

Tips for styling links in Nuxt/Vue based on specific conditions

Struggling with conditional styling in my Nuxt app. I want to change the background color of the active link based on the current page. Using .nuxt-link-exact-active works for styling the active link, but how can I customize it for each page? The links ar ...

Unique underlined text design (+using+ and - symbols-)

I'm looking to create a customized text decoration, as shown in the image below: https://i.stack.imgur.com/emjND.png It's easy to achieve a dashed line using CSS for decorations like this: color: red; border-bottom: 3px dashed; // You can adjus ...

Glitches of white light during loading screens on your Prestashop website

There's a strange occurrence on the website where it flashes white DURING (not just at the start) every time a page loads. Initially, the page seems to load smoothly and almost completely, but then there is a sudden flash before all elements are disp ...

Conceal navigation buttons on the first and last pages of the slider

I'm attempting to develop a slider that hides the "previous" button when it is on the first slide and hides the "next" button when it reaches the last slide. The slider will be created using a combination of PHP, forms, and JavaScript. Below is the H ...

Trouble with the mobile layout - styling with CSS

Having an issue with the mobile view CSS. Visit: Looking to shift the navigation button to the right and widen the logo without changing its height. Any assistance would be appreciated. Thank you, ...

Outputting Javascript code from a PHP variable can be achieved by utilizing the echo function

I've been diving into Cross Site Scripting and decided to test some vulnerable examples we were given in class. Currently, I'm experimenting with a form that stores its value in $_REQUEST['in'] of PHP upon submission. The stored value i ...

Joomla CSS styling malfunctioning

I've been exploring the creation of an in line menu using Joomla 1.6 and CSS. The issue arises when Joomla removes <span class="dmenu"> from the document before saving, despite having all cleanup options turned off. This led me to try a couple ...

Ways to emphasize the four edges of a table cell using border-collapse collapse

I am trying to emphasize the borders of cells with the class active. The challenge arises from the fact that the table's border-collapse property is set to collapse, causing the top and left borders of cells (except for the leftmost and top row cells ...

"An issue has been identified with the page-break-* feature not functioning properly on both Chrome and

Despite the abundance of questions on this topic, I have yet to find a viable solution. Here is my HTML code: <div class="row"> <div class="col-xs-12"> <div class="row print-break"> <div class="col-xs-8 col-xs-offset ...

Issue with div in simple HTML code

I've been facing challenges with this line of HTML as I keep encountering errors and cannot pinpoint the source. The error highlight appears at the end of the last div, but once removed, another error emerges at the end of the body tag. Check out the ...

Display data in a nested array format using *ngFor in a table population

I am looking for a table that can compare two popular products. My JSON model includes an array nested within another, structured like this: products: [ { name: 'Product Basic', price: 9.90, category: 1, features: [ ' ...

select a row within a table using HTML tags

I'm working on a basic website where I need to display data in a table generated from a SQL query. To make certain rows stand out, I want to change the background color to yellow for those specific rows. Here is the structure of my current table: & ...

Show the Content if the Element has the Class; otherwise, hide it

My understanding of JQuery is limited, so I apologize if my code is convoluted. I will do my best to explain my issue in detail. The product I am working with has two attributes: size (Größe wählen) and frame (Rahmen wählen). I need to add a DIV for ...

Styling elements based on a condition with CSS

Is there a way to confirm the truthiness of a TypeScript variable using CSS? I am attempting to determine if I am on a particular page so that I can adjust the height accordingly. Appreciate any help! ...

hiding html elements by using the display property set to none instead of physically removing

I am currently utilizing an if-else statement to display different HTML structures. As a result, the entire HTML is being rendered twice. Is there a way we can utilize 'display: none' instead? I attempted to use it in th ...

What causes *ngIf to display blank boxes and what is the solution to resolve this problem?

I am currently working on an HTML project where I need to display objects from an array using Angular. My goal is to only show the objects in the array that are not empty. While I have managed to hide the content of empty objects, the boxes holding this co ...