Tips for designing a CSS Grid that features a maximum width for the main content and a minimum width for the sidebar

I'm attempting to design a two-column CSS grid with a main content area that has a maximum width of 800px and a sidebar that has a minimum width of 200px: https://codepen.io/dash/pen/gOmXqGr

The grid needs to be responsive:

  1. The yellow sidebar should be able to shrink but must maintain a minimum width of 200px.
  2. The orange main content, which includes an image, should have a maximum width of 800px and shrink if necessary.

My attempt using the minmax function isn't working. Any suggestions?

Code:

    html {font-family: Arial, sans-serif;}
    ul {margin: 0; list-style: none;}
    
    .theme-hero {
        display: grid;
        gap: 8px 32px;
        grid-template-columns: minmax(auto, 800px) minmax(200px, auto);
        grid-template-rows: auto;
            grid-template-areas: 
            "breadcrumb ."
            "theme-img sidebar";
        max-width: 1400px;
    }
    
    .theme-hero-breadcrumb {
        grid-area: breadcrumb;
        background: gray;
        text-align: center;
    }
    
    .theme-hero-showcase {
        grid-area: theme-img;
        background: orange;
        max-width: 800px;
    }
    
    .theme-hero-sidebar {
        grid-area: sidebar;
        background: yellow;
    }
    <div class=theme-hero>
        <div class=theme-hero-breadcrumb>breadcrumb</div>
        <div class=theme-hero-showcase><img src=https://via.placeholder.com/800x600 alt></div>
        <div class=theme-hero-sidebar>sidebar</div>
    </div>

Answer №1

It appears that the issue lies with the image preventing the div from resizing properly.

To address this, you can use the following CSS code to set the maximum width and height for the image, making it more responsive:

img{
      max-width: 100%;
      max-height: 100%;
}

html {font-family: Arial, sans-serif;}
ul {margin: 0; list-style: none;}

img{
        max-width: 100%;
        max-height: 100%;
}

.theme-hero {
    display: grid;
    gap: 8px 32px;
    grid-template-columns: minmax(auto, 800px) minmax(200px, auto);
    grid-template-rows: auto;
        grid-template-areas: 
        "breadcrumb ."
        "theme-img sidebar";
    max-width: 1400px;
}

.theme-hero-breadcrumb {
    grid-area: breadcrumb;
    background: gray;
  text-align: center;
}

.theme-hero-showcase {
    grid-area: theme-img;
    background: orange;
    max-width: 800px;
}

.theme-hero-sidebar {
    grid-area: sidebar;
    background: yellow;
}
<div class=theme-hero>
    <div class=theme-hero-breadcrumb>breadcrumb</div>
    <div class=theme-hero-showcase><img src=https://via.placeholder.com/800x600 alt></div>
    <div class=theme-hero-sidebar>sidebar</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

"Encountering a Challenge: Cannot Assign Array to ngFor Directive in Ionic App, Displaying

I have encountered an issue while fetching product categories using API. The problem lies in the fact that the categories are being retrieved as an object instead of an Array which is required for *ngFor to work in Ionic. Any assistance on how to define th ...

Creating an interactive bootstrap modal: a step-by-step guide

For instance, I have 3 different tags with unique target-data for each one. <a class="btn btn-outline-primary btn-sm" href="#" data-toggle="modal" data-target="#firstdata"> DATA 1 </a> <a class=&q ...

How can I create a design that blends half image and half color together with intricate cutting techniques?

Can someone give me tips on creating a design like this? I attempted to use bootstrap to create it, but I was unsuccessful due to my lack of knowledge on how to achieve this specific background. Any guidance on the proper way to design it would be greatly ...

Obtained a ZIP file via CodeSandbox that contains a Vue.JS webpage. However, the index.html file yielded an

I have created my first ever Vue.JS / Vue2Leaflet app. It runs perfectly fine on codesandbox.io. However, when I download the ZIP file and try to open the index.html file, it appears blank. Is there something specific that needs to be done to make it work, ...

How does Facebook access the new hashtags when they are clicked on?

I've been developing a website recently and I'm really impressed with the way a popup page appears when you click on a hashtag. I've been wanting to incorporate a similar feature for a while now, but I'm not sure how to do it. Could thi ...

Spinner loading - stays centered on screen even when scrolling up or down

<div id="Dvloading" style="float: left;"> <i id="loadingSpinner" class="icon-spinner icon-spin blue" style="margin-left: 50%; position:absolute ; margin-top: 25%; z-index: 1000; font-size: 800%;"></i> </div> This code displ ...

Trouble filling a List<WebElement> from a Table using Selenium Java

I am experiencing difficulty filling a List from a table: <div class="es"> <button class="btn btn-primary" [routerLink]="['add']">New User</button> </div> <div class="User_table" id="t02" > <div class="table ...

Extract the color of an individual character

There is a code snippet in JavaScript using p5.js that functions as a video filter: const density = ' .:░▒▓█' //const density = ' .tiITesgESG' //let geist; let video let asciiDiv let playing = false let ...

Padding on the left and right in Bootstrap

Here is the code snippet I'm working with: <div class="col-md-12 pt-5 let-top"> <h1>A</h1> </div> For small and extra small screens, I am looking to include padding on both the left and right sides. Can anyone help me wit ...

What is the best way to insert a tagline above a form?

I'm struggling to figure out where to place a tagline above my form. I want it to be neat and clean, but haven't been successful in finding the right spot. I attempted to insert an <h2> inside the form, but it doesn't look good at al ...

Creating uniform height for Definition Terms (DT) and Definition Descriptions (

Looking to creatively style a description list <dl> in a way that showcases two columns, even when there are multiple <dd>s following the <dt>. The challenge lies in wanting this design to be dynamic without resorting to floating the < ...

tips for obtaining necessary input fields

What is the best way to include mandatory input fields? appreciate it <input type="text" name="name"> ...

Maximizing the number of divs arranged horizontally in HTML while utilizing the full line width

My website consists of several fixed-width div elements that are styled to flow inline using the display type inline-block. This layout creates empty space at the end of the line where subsequent div elements cannot be accommodated and have to wrap to the ...

Troubles with CSS in MUI Component Integration

How can I successfully implement a vertical timeline using Material UI in React? I've set it up, but the CSS isn't functioning as expected. Is there an error in my implementation? List of Dependencies: "@emotion/react": "^11.11.1& ...

Vuejs responsive navbar with collapsible sidebar using Bootstrap or Bootstrap-Vue libraries

Vue.js is the framework I'm utilizing for my current project. In creating a dashboard section, I am seeking to implement a responsive design using either bootstrap, bootstrap-vue, or plain HTML and CSS. Below are the images of the desired dashboard -& ...

Develop expandable objects containing a set size of items using HTML and CSS

I need help creating a flexible content area using only HTML/CSS. The width of this area should be able to vary from 0 to 50% within its container, which can itself vary from 0 to 100% of the window size. I have two items that need to be positioned next ...

Steps for changing the background color string in mui?

I have a component where I am trying to dynamically change the color based on the user type. The issue arises when I use gradient colors, as the transition stops working. If I stick to simple colors like blue, red, or green, it works fine. Currently, the c ...

Only one submenu can be opened at a time & click to close

I am encountering an issue with my list and submenus. When I click on List 1, submenu 1 opens but if I then click on List 2, submenu 2 opens while submenu 1 remains open. However, when I click on List 2 again, instead of just closing submenu 2, it toggles ...

HTML5 Boilerplate and optimizing the critical rendering path by deferring scripts and styles

Previously, I constructed my website layouts using the HTML5 Boilerplate method: incorporating styles and Modernizr in the head section, jQuery (either from Google CDN or as a hosted file) along with scripts just before the closing body tag. This is an exa ...

Tips for concealing broken images in jQuery/JavaScript when generating dynamic content

Is there a way to hide the broken images in this dynamically generated HTML code using JavaScript? Unfortunately, I don't have access to the source code itself. I'm new to JQuery and could really use some assistance. Below is the snippet of the ...