The utilization of Display Flex resulting in the enlargement of the containing div

I am currently learning CSS and trying out some new things. I am looking to create a page with two side-by-side divs: one for the sidebar and the other for the main content. My goal is to have the sidebar take up 400px of width and allow the content part to fill the remaining space up to a screen size of 950px.

Within the content div, I want to include a scrollable section that can hold 20 items with dimensions of 250px in height and 200px in width.

After implementing this design, I noticed that the content div with the blue border overflows the entire page. Here is a snippet of the CSS and HTML code:

/* CSS Styles */
*{
    padding: 0;
    margin:0
}
.container {
    width:100vw;
    height: 100vh;
    background-color: black;
    padding:20px;
    box-sizing: border-box;
    display:flex; 
    overflow: hidden;
}

.sidebar {
    width: 400px !important;
    height:100%;
    border:1px solid red;
    box-sizing: border-box;
    flex-shrink: 0;

}

.content{
    height:100%; 
    border:1px solid blue;  
    width:calc(100%);
    flex-shrink: 3;
}

.holder{
height:40%;
width:100%;
border:1px solid yellow;
display:flex;
overflow: scroll;
}

.item{
    height:250px;
    width:200px;
    border:1px solid pink;
    flex-shrink: 0 ;
}
/* HTML Markup */
<div class="container">
    <div class="sidebar"></div>
    <div class="content">
        <div class="holder">
            <!-- This will hold around 15 to 20 items -->
            <div class="item"></div>
            <div class="item"></div>
             ...
            <div class="item"></div>
        </div>
    </div>
</div>

Answer №1

To ensure optimal usability, it is recommended to prioritize mobile-first design when building web pages. This involves styling the mobile version first and then incorporating:

@media screen and (min-width: 950px) {
`enter code here`
}

for screens wider than 950px.

Exercise caution when using the !important keyword as it could potentially disrupt your styles in the future.

In addition, consider adding box-sizing: border-box as a foundational style rule.

Below are the updated styles. Unnecessary styles have been commented out, and comments have been added for any new styles implemented:

 * {
        padding: 0;
        margin: 0;
        box-sizing: border-box; /* added */
      }
      .container {
            width:100vw;
            height: 100vh;
            background-color: black;
            padding:20px;
            /* box-sizing: border-box; */
            display:flex; 
            /* overflow: hidden; */
        }

        .sidebar {
            /* width: 400px !important; */
            min-width: 400px; /* added */
            height:100%;
            border:1px solid red;
            /* box-sizing: border-box; */
            /* flex-shrink: 0; */
        }

        .content{
            height:100%; 
            border:1px solid blue;  
            /* width:calc(100%); */
            /* flex-shrink: 3; */
            overflow: hidden; /* added */
        }

        .holder{
            /* height:40%; */
            width:100%;
            border:1px solid yellow;
            display:flex;
            /* overflow: scroll; */
            overflow-x: scroll;/* added */
            overflow-y: hidden;/* added */
        }

        .item{
            height:250px;
            width:200px;
            border:1px solid pink;
            flex-shrink: 0 ;
        }
<div class="container">
      <div class="sidebar"></div>

      <div class="content">
        <div class="holder">
          <!-- This will hold around 15 to 20 items -->
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
          <div class="item"></div>
        </div>
      </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

Ways to expand logo space within the header of the Twentysixteen Theme on WordPress

I am facing an issue with my logo being resized to a much smaller size of 200px even though it is originally over 2000px wide. In the style.css file, I found the following code: .custom-logo { max-width: 180px; } Despite changing the max-width value t ...

Creating a Dynamic Slideshow on Autopilot

My JavaScript skills are not perfect and I'm feeling a bit lost. I have this code for a slideshow, but I want to make it automatic while also allowing users to navigate between images freely. I'm struggling to figure out how to implement this fun ...

Creating a unique card component with React and custom Tailwind CSS styling

I am working on creating a project component using React: Despite my efforts, I have not been able to find the correct documentation for assistance. Additionally, I am facing challenges in utilizing next/image to ensure that it is the correct size. This ...

Customizing jQuery-UI's Select-Menu Widget with CSS

I am facing some challenges with setting CSS properties for jQuery-UI widgets, especially the SelectMenu. Basic styling like margins does not seem to work, and I am struggling to assign different CSS styles to two separate SelectMenu widgets. Here is a sim ...

Is there a way to create a scroll down and scroll up button that is located outside of the scroll box

A game designer challenged me to create a custom scrollbar with unique up and down button styles, as well as a custom-looking scrollbar. I wanted to achieve this without using the native browser scrollbar on Windows in Google Chrome. https://i.sstatic.net ...

Unveil concealed information within a freshly enlarged container

As I organize my content into an FAQ format, I want users to be able to click on a link and expand the section to reveal a list of items that can also be expanded individually. My goal is to have certain list items expand automatically when the FAQ section ...

Styling Your PHP Output with Echo

Is there a way to create a compact text box with a scroll bar that can display recurring data generated by PHP activities on the server side? How can I format it in this way? ...

Is there a way to modify the CSS or add custom styling within an iframe form?

Currently I am working on the following page: , where an embedded javascript form called infusionsoft (iframe form) needs to be made responsive at the request of my client. I'm wondering if there is a way to override the css or inject custom styles i ...

How to style text alignment and create a toggle button using HTML and CSS

My attempt at creating a custom toggle button using an HTML input checkbox and custom CSS has resulted in a misalignment between the text and the toggle button itself. Despite my efforts to adjust margins, padding, and heights, I have been unable to resolv ...

Menus that mimic the style of Google Translate's select options

I'm looking to design an HTML select menu using CSS in a similar fashion to Google Translate's style on Google Translate. I've searched for tutorials online, but they all involve jQuery. Is there a way to achieve something similar using only ...

Upon page load, a dazzling SVG file will flicker before being adorned with CSS styles

I'm experiencing an issue with an SVG arrow icon on my webpage that flashes quickly across the entire screen upon page load before settling into its proper size and placement. I've tried using CSS to initially hide the icon and then reveal it aft ...

What is the best way to begin an ordered list from the number 2 instead of 1, while ensuring W3C validity and compatibility with

Is it possible to start an ordered list from 2 instead of 1? I need the solution to be compatible with all browsers, including IE6, and ensure that the HTML and CSS are valid. ...

Flexslider doesn't adjust the height of the viewport when displaying a shorter image in the slideshow

Is Flexslider not resizing its viewport height according to the current image on your site? The fixed height seems to be causing blank white space under shorter images. Are you inadvertently overriding Flexslider's responsive height function? Is there ...

What is the best way to blend a portion of an image into a div?

Having a bit of trouble with overlapping my image onto another div in my current project. When you take a look at what I've been working on, you'll see there's an image that says "That's me!" and it needs to overlap the left side div. I ...

offspring of offspring in jquery animation remains stationary

I'm experiencing an issue with a jquery animation on containers that are set to 100% width and height. Specifically, the children elements that have position absolute move with the container, but when a child of a child has two instances of position a ...

Collapse all "Read More" buttons simultaneously using Bootstrap

I am attempting to design a segment that contains multiple paragraphs that can be expanded or collapsed individually. How can I achieve this using only pure bootstrap css so that they do not all expand and collapse simultaneously? #summary { font-size: ...

Strategies for aligning a div element in the middle of the screen

Positioned in the center of the current viewport, above all other elements. Compatible across different browsers without relying on third-party plugins, etc. Can be achieved using CSS or JavaScript UPDATE: I attempted to use Javascript's Sys.UI.Dom ...

Include an additional phase within the MUI stepper and customize the styling

I am in need of modifying the code below to suit my requirements: Firstly, I would like to change the design from the current one to this: https://i.stack.imgur.com/3RhsH.png The new design will look like this: https://i.stack.imgur.com/sGLwH.png Addi ...

CSS can always surprise with its unexpected animations

Currently developing a static website with CSS animations: * { -webkit-transition: all 1s ease-in-out; -moz-transition: all 1s ease-in-out; -o-transition: all 1s ease-in-out; -ms-transition: all 1s ease-in-out; transition: all 1s ease- ...

Connect the front end files, including HTML, CSS, and JavaScript, to the Node.js backend

I'm a beginner in web development and recently completed an online course on node.js and express. However, the course didn't cover how to add HTML, CSS, and JS files when using Node. I attempted the following: var express = require('expres ...