I've been experimenting with negative margin and positive padding as an alternative to calc(), but a few challenges persist

Here is the code I have written:

My HTML Code:

<div id="container">
    <div id="left-content">Left Content</div>
    <div id="right-content">Right Content</div>
</div>

My CSS Code:

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
#container {
    width: 100%;
    height: 100%;
    margin-bottom: -50px;
    padding-bottom: 50px;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    background: red;
}
#container > #left-content {
    width: 100%;
    height: 100%;
    margin-right: -210px;
    padding-right: 210px;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    display: inline-block;
    background: yellow;
    /*overflow-y: scroll;*/
}
#container > #right-content {
    width: 200px;
    height: 100%;
    display: inline-block;
    /*float: right;*/
    background: green;
    /*overflow-y: scroll;*/
}

When you check this fiddle, you will notice that there are three comments(/* ... */) in the CSS code. One pertains to positioning #right-content, while the others are about scroll bars. In the result screen, you can see the long yellow side on the right of #right-content.

I attempted to remove this (the yellow side) by using float: right;(Uncommented float: right;), but it did not work as expected. Specifically, the #right-content box became invisible. What steps should I take to fix this issue?

Upon reverting to the original code(Uncommenting float: right;), and then uncommenting the overflow-y: scroll; to enable scroll bars, the scroll bars overlapped in the same space. My intention is to position the scrollbar of #left-content correctly to the right of #left-content. The puzzle remains unsolved. How can I resolve this dilemma?

To summarize...

Q1. How can I position #right-content flawlessly?

Q2. How can I perfectly locate the scroll bars of both #left-content and #right-content?

Thank you.

Answer №1

Finally, after about 3 months of searching, I stumbled upon the solution. Hahaha...

Interestingly enough, the answer was quite simple.

  1. Add a new #left-wrap HTML tag outside of #left.
  2. Incorporate new CSS for #left-wrap.
  3. Transfer all CSS from #left to #left-wrap, except for properties like background and overflow-y.
  4. Include width: 100%; height: 100%; in the #left CSS.
  5. Uncomment overflow-y: scroll; in both #left and #right, and add float: right; in #right.
  6. To avoid any disabled elements in #right, insert position: relative; z-index: 10;. (You can choose any sufficiently large number.)

You can check out the outcome in this JSFiddle link.

HTML:

<div id="box">
    <div id="left-wrap">
        <div id="left">
            Left<br />Left<br />...
        </div>
    </div>
    <div id="right">
        Right<br />Right<br />...
    </div>
</div>

CSS:

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
#box {
    width: 100%;
    height: 100%;
    ...
}
#box > #left-wrap {
    width: 100%;
    height: 100%;
    ...
}
#box > #left-wrap > #left {
    ...
}
#box > #right {
    ...
}

Thank you.

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 reconfigure an array for storing as pairs

I want to transform an array from array(1,2,3,4,5,6); to display in pairs like this: array(1,2) array(3,4) array(5,6) I know I can achieve this using foreach loop, but I'm wondering if there is a built-in PHP function that can do this automatical ...

Switching between displaying or hiding one of two backgrounds within a div using CSS and jQuery

Seeking guidance on implementing a two-background div setup where A is constantly displayed within the element and toggling B based on button control click. HTML <div class="container"></div> CSS .container{ url(B.png) 10px 10px no-repeat ...

Following the completion of the inspection, the next step

Check out my work at this link: Unfortunately, my code is too lengthy to include here, so please refer to the link above to see the issue I am facing. The problem I am encountering is that when I click the checkbox after adding an item to the list, the r ...

Tips for adjusting the size of Angular Material elements

In the midst of my work on an Angular application, I have been utilizing angular material components. However, as I delved into styling the application, I encountered difficulties in styling the angular material component, particularly in enlarging a dropd ...

Tips for stopping special characters from being copied and pasted into a number field

My goal is to ensure that only numbers can be copied and pasted into the 'number field'. By preventing the copy and paste of characters like 'e', '+', '-', and '.', I can ensure that the number field only c ...

Acquiring the `=` symbol within email HTML

Here is the HTML that I send from my ASP.NET application: <HTML> <BODY> <img src='http://10.1.1.42:8090/EmailLogo/8aaebe52-3758-485f-8c52-7782707a4c66.jpg' /> <br/> <div style='font-family:Arial, Tah ...

Change in color due to the change in temperature of the

I recently completed a jQuery weather project using data from Wunderground. I am trying to implement a feature where the color of the temperature changes automatically based on whether it is higher or lower, but I am unsure how to incorporate CSS within ...

prohibit magnifying glass from appearing on iOS 9 in a meteor cordova application

https://i.sstatic.net/jQOpS.jpg I have been experimenting with various solutions to get rid of the intrusive magnifying glass using CSS. Interestingly, on my iOS9 meteor cordova build, it still briefly appears and then disappears after a few milliseconds. ...

Pop-up window triggered upon loading the page automatically

I am having trouble getting a pop-up to display whenever an unregistered user tries to access a specific page. I followed an example, but I can't seem to make it work on my page. Any suggestions? Thanks! Image: My code snippet for that page (CSS is ...

What could be causing certain grid items to display in a disorderly manner?

Currently, I am working on a CSS grid layout that resembles the one showcased in this demo. The challenge I'm facing is related to the ordering of items within the grid. Specifically, every 6th and 7th item seem to be out of order and I would like the ...

clicking on links to different sections of the page does not automatically bring you to the top of

I am working on a design similar to this: http://jsfiddle.net/MTWu5/ The layout consists of a centered page with a sticky header. The header contains menu links that lead to anchors within the page. My issue arises when clicking on these links - I would l ...

Issues with the local or browser display of @font-face

I'm really struggling to get my @font-face to display correctly, whether I view it locally or in the browser preview. This is the CSS code I am using: @font-face { font-family: chopin-script.regular; src: local('chopin-script.regular'), ...

What is the best way to send an object to Vue Component?

How can I properly call a Vue Component with a data object? The todo-item tag works as expected, but the todo-item2 tag does not produce any output. I was expecting the same result. Here is the HTML code: <div id="app"> <todo-item v-bind:te ...

What is the best way to manage selected checkboxes in PHP?

Could you please assist me with a problem I am facing? I have a form where users can select checkboxes, but I'm struggling to display the selected checkbox item names in the result. Currently, my HTML site is using the value attribute to calculate the ...

The block is not responding to hovering as expected

I'm currently attempting to implement a hover effect for the entire anchor element, but unfortunately it's not functioning as expected. The drop-down menu disappears as soon as the mouse moves away from the text: Click here to view the test site ...

Running Content Scripts and CSS styles from Background Page in Chrome Extension - Manifest V3

I'm currently working on developing a chrome extension, and my goal is to have a small circle appear on the screen when the extension is active. I require CSS for this task, and my plan involves setting the background in the manifest file and triggeri ...

Utilizing HTML list elements in conjunction with a switch statement, and connecting the list directly to a database for

Hey there, I'm interested in learning how to access HTML elements and use them within switch statements. <div id="hori"> <ul> <li><a href="#">Aerospace</a></li> <li><a href="#">Automotive</a>< ...

Sending an ID from an array within a *ngFor loop to a different component in Angular: a step-by-step guide

I have a collection of items that I loop through using ngFor. My goal is to pass all its attributes to another component. I attempted to accomplish this with the following code: *ngFor='let item of postList [routerLink]="['/detailed-post&ap ...

The ul media queries have malfunctioned

In the .gallery section, there are 12 li elements that contain images. Originally, I used media queries to adjust the number of columns in the grid to 6, 4, 3, and 2 based on the browser width. However, when I tried to create a size ratio of 2:1 for all ...

Tips on concealing the visibility of a table row using PHP

My HTML table structure is quite simple: <style> .demo { width:100%; border:1px solid #C0C0C0; border-collapse:collapse; padding:5px; } .demo th { border:1px sol ...