Ensuring that the div remains confined within the Container

The code snippet provided below demonstrates that the lowest level of items is located outside the container.

I understand that this is due to the

position:absolute; transform:translate(-33%)
. However, this has been the only method I have found so far to center the elements beneath their parent.

Is there a way to include the three lowest elements inside the container and enable horizontal scrolling for the entire content?

body {
  background-color: #eaeaea;
  width: 2000px
}

/* Additional CSS classes omitted for brevity */

<div class="CB">

  <div class="CB_Menu">
    header
  </div>

  <div class="CB_Content">

    <div class="Products">
      <div>
        <div class="Product">
          <!-- Product Details -->
        </div>
        <!-- Additional HTML markup omitted for brevity -->
      </div>
    </div>
    <div class="Parts">
      <div>
        <div class="lineTop active">
          <div class="LineTop_Line"></div>
          <div class="LineTop_Line"></div>
        </div>
        <div>
          <div class="Part">
            <!-- Part Details -->
          </div>
          <!-- Additional HTML markup omitted for brevity -->
        </div>
        <div class="Part">
          <!-- Another set of Part Details -->
        </div>
        <!-- Additional Parts sections omitted for brevity -->
      </div>
    </div>
  </div>
</div>

Answer №1

Are you attempting to achieve the following? Modifications that need to be made:

  • Eliminate the fixed width of body (width: 2000px).
  • Remove the fixed width of CB class (width: 1200px).

You have the option to set the width to auto, or keep it as is for horizontal expansion as needed.

body {
  background-color: #eaeaea;
}

.CB {
  background-color: #c4cfd8;
  width: auto;
  margin: 0 auto;
  margin-top: 50px;
  user-select: none;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 200vh;
}

(CSS rules continue...)
<div class="CB">

  <div class="CB_Menu">
    header
  </div>

  (More HTML content...)
</div>

Answer №2

<style>
    body {
  background-color: #f1f1f1;
  width: 1500px
}

.CB {
  background-color: #bdc1c5;
  width: 1000px;
  margin: 0 auto;
  margin-top: 30px;
  user-select: none;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 150vh;
}
...

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

Select the even-numbered occurrences of a specific class in CSS using the nth-child()

I am encountering an issue with my table layout. The structure is similar to the following: <tbody> <tr class="row">...</tr> <tr class="row--expanded">...</tr> <tr class="row">...</ ...

The CSS descendant selector does not seem to be functioning properly with the focus state on iOS

In order to display content using the :focus state when the parent element has focus, I have used the following CSS code: .child { display: none; } .parent:focus .child { display: block; } It's important to note that the parent element has tabindex= ...

Adjust the dimensions of a div using hidden ghost content as the basis

Is there a way to size a <div> element based on ghost content instead of the actual visible content? For example, can we make the box with content "A" appear as if it contains "BCD"? .container { display: flex; width: 10em; } .item { flex-grow: 1; ...

Ensure that the checkbox remains constant and visible at all times when using Bootstrap

Introducing the latest checkbox design in Bootstrap4 : Check out the Bootstrap4 checkbox: <label class="c-input c-checkbox"> <input type="checkbox"> <span class="c-indicator"></span> Click here </label> The stan ...

Having the ability for two images to adjust in size, becoming smaller or larger, as the page is resized and displayed

On my webpage, I have two divs positioned side by side with images inside them. Everything looks perfect when viewed on my Macbook 13 inch screen, but as I resize the browser window, the photos start to spread apart and create a large gap between them. Is ...

What are alternative methods for creating a table layout without relying on traditional table elements?

Is there a way to eliminate tables from my code and achieve the same layout in the name of progress and learning? Here is an example of the table I currently have: <table cellspacing="0px"> <tr> <td> <img src= ...

Use the Calibri (Body) typeface for the text

I have a div and I'd like to show some text in Calibri (Body) font within it. Any ideas on how to achieve this? Here is the CSS code I've been provided with: .an_account_join_1 { float:left; width:100%; color:#000000; font-fami ...

Create a sleek transition for your Bootstrap 4 fixed Navbar by having it smoothly slide down and change to a

Throughout my experience with HTML/CSS, I have predominantly relied on themes that included this feature by default. However, as I now venture into building from scratch, I find myself struggling to recreate it. You'll notice that I have a stylish fi ...

button bouncing effect when scrolling vertically

Is there a way to create an element that bounces based on the user's scroll direction? For instance, if the user scrolls down, the button should bounce from bottom to top, and if scrolling up, the button should bounce from top to bottom. I have been ...

How can a div's height be adjusted based on the content of one sub div but not the other?

If I have a parent div with two child divs inside it, is it possible to set the parent div's height to auto, but only apply it to one of the child divs, while having the other child set to scroll for overflow-y? For example, you can see the issue her ...

Designing personalized sass components

Seeking advice on developing a custom CSS unit that can be utilized in Sass with Node.js. Is there a tutorial available for creating a Sass plugin specifically for this purpose? For instance, I am looking to establish a unit called "dpx" which functions as ...

What's the best way to add a suffix to a dynamic counter animation?

Having trouble adding a static suffix to the end of animated counters. I want to include a "+" sign in some of them without animation. I attempted to create a suffix class, but it doesn't append directly to the end value - it keeps showing up below t ...

yet another dilemma with CSS height set to 100%

UPDATE: I believe there was an excess of information. Let me simplify my question: How can I adjust the height of #middle to be 100% of the remaining space in the example below: <body> <div id="big"> <div id="header"></div ...

Verifying the timestamp of file submission in a form

My goal is to create an HTML form that allows users to send a file to my server, while also recording the exact time they initiated the file transfer. However, I'm facing an issue where only the time the file is received is being logged, rather than w ...

The complete height of the website is concealed by the mobile toolbar/menu

I encountered a perplexing issue regarding the responsive resizing of a website on mobile devices. The problem arises when the full height extends over the toolbar/menu, unless the user manually hides the toolbar. Is there a way to dynamically resize the ...

What is the best way to extract data from several SQL tables and display it in an HTML/PHP table?

In my database named result, I have two tables named res and sub. Here is an example of the contents in the res table: sno regno name sub1 sub2 sub3 sub4 sub5 1 1DU12CS100 student1 70 80 85 70 90 2 1DU12CS101 ...

Modify the color of drop-down menu links

Recently, I set up a drop-down menu containing links. Initially, when hovering over the names in the menu, they would change color and display the drop-down. I had successfully made all the names golden, with the hovering name turning black while display ...

Finding elements based on a specific parent structure in JavaScript: A step-by-step guide

I'm currently working on a script that needs to grab content only within a specific parent structure defined as div.main-element input+label+ul. Is there a way to achieve this using JavaScript or jQuery? If anyone could point me in the right directi ...

I am attempting to add a new row (div) for the invoice, but when I do so, the

Looking for a solution to repeat a row when clicking a button in order to utilize PHP for data manipulation? Check out the code snippet below: <!-- Table row --> <br><br> <div class="row"> <!--Product Table--> <div ...

Using Python Script to Develop a Web Page

I've created a Python notebook script that contains hardcoded text which I manipulate and present in a tabular format. I am interested in hosting this on my local web server so that others can access it from their computers as well. Any help or sugg ...