Adjust the size of a large column to fit into a smaller one using Bootstrap or vanilla CSS

I've experimented with various methods and it seems like achieving this without JS might not be possible - but before I throw in the towel, I wanted to reach out for help here.

I have a lengthy navigation div on the left side and a column of dynamic content beside it. My main objective is to make the height of the navigation match the content's height and overflow the excess space.

document.getElementById('add').addEventListener("click", function(e){
  e.target.insertAdjacentHTML('afterend', '<br>more dynamic content...');
});
.row {
  display: flex;
  align-items: flex-start;
}

.left {
  background: #ccc;
}

.right {
  background: #cc6;
}
<div class="row">
  <div class="left">Long Navigation<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br...
 
<hr>

<p>To add another layer of complexity, the entire setup is within a modal. So my second goal is to make it functional within a div that has its own overflow: auto property.</p>

<p><div>
<div>
<pre class="lang-js"><code>document.getElementById('add').addEventListener("click", function(e){
  e.target.insertAdjacentHTML('afterend', '<br>more dynamic content...');
});
.modal {
  display: flex;
  align-items: flex-start;

  max-height: 300px;
  overflow: auto;

  margin: 10px;
  border: 10px solid red;
  box-shadow: 0 0 15px grey;
}

.left {
  background: #ccc;
}

.right {
  background: #cc6;
}
<div class="modal">
  <div class="left">Long Navigation<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>Cookiemonster</div>
  <div class="right">Shorter Content...<br>...<br>
    <button id="add">+ add more content</button>
    <br>&lt;-- Navigation div should always end here</div>
</div>

I attempted using flexbox, positioning, and various combinations of height properties but had no luck. Any suggestions on how to accomplish this without relying on JavaScript?

And it must be compatible with IE11... :)

Answer №1

To achieve this, you can use absolute positioning for the navigation bar while ensuring the left div has a fixed width.

document.getElementById('add').addEventListener("click", function(e) {
  e.target.insertAdjacentHTML('afterend', '<br>more dynamic content...');
});
.modal {
  max-height: 300px;
  overflow: auto;
  margin: 10px;
  border: 10px solid red;
  box-shadow: 0 0 15px grey;
}

.modal-inner {   /* Add this inner div to prevent backgrounds from stopping at modal's max-height */
  display: flex;
}

.left {
  background: #ccc;
  position: relative;  /* Ensure relative positioning and specify a fixed width */
  width: 200px;
}

.absolute {
  /* Place a div with this class inside the left column */
  position: absolute;
  overflow: auto;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.right {
  background: #cc6;
  flex-grow: 1;  /* Use flex-grow property if you want this div to fill the remaining width */
}
<div class="modal">
  <div class="modal-inner">
    <div class="left">
      <div class="absolute">
        Long Navigation<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>Cookiemonster</div>
    </div>
    <div class="right">Shorter Content...<br>...<br>
      <button id="add">+ add more content</button>
      <br>...<br>...<br>...<br>&lt;-- Navigation div should always end here</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

Expanding the width of CSS dropdown menus according to their content

When attempting to create a dynamic dropdown menu, I encountered an issue where the values were skewed in Internet Explorer if they exceeded the width of the dropdown. To fix this problem, I added select:hover{width:auto;position:absolute}. However, now th ...

Resolving the Material-UI NextJS Button Styling Dilemma

I've encountered an issue with the styling of a few buttons in JS. When I apply a styling class using className, the formatting works fine on the initial render but loses its styling on subsequent refreshes. This problem is specific to two individual ...

Resize images smoothly without disrupting the anchor scrolling

I have created a website with the following design: (Caution: The site is built using AngularJS on a server that may not serve it correctly - please visit directly instead of using browser reload.) However, I am facing two conflicting requirements... ...

Tips on utilizing Blazorise's numeric edit group with grouping functionality

I recently attempted to utilize the numeric edit group separating attribute in Blazorise but encountered issues. According to the documentation, it should be possible to use this feature, however, my attempts were unsuccessful. I would greatly appreciate ...

The Bootstrap carousel is malfunctioning when viewed locally, however it operates smoothly when accessed through an

Working on a website for a school project using bootstrap has been smooth sailing so far. I downloaded bootstrap js and css files to use locally, ensuring that even without an internet connection, bootstrap would still function. However, things took a tur ...

Preventing Javascript Pop Up from automatically jumping to the top of the page

Upon clicking a button (refer to image below and take note of the scroll bar position), a div pop up is triggered through Javascript. View image: https://docs.google.com/file/d/0B1O3Ee_1Z5cRTko0anExazBBQkU/preview However, when the button is clicked, the ...

Break down the organization of CSS

While exploring a website, I came across this CSS code that sets the font family to "Open Sans," Helvetica, Arial, and sans-serif. However, I am having trouble understanding this structure. Any assistance would be greatly appreciated. Thank you in advanc ...

Troubles with horizontal list incompatibility in Internet Explorer 6 and 7

I am facing an issue with displaying an unordered list in IE6+7. The problem arises when styling the list items with specific width and height properties, causing IE to stack the items vertically instead of horizontally. Below is my code snippet: For live ...

Is there a way to display a different file, such as index.html, based on the screen width?

I'm facing an issue. I have completed a web page (with HTML, CSS, and JavaScript), but now I want to create a mobile version using different HTML files, another index.html file, and a separate CSS file. What changes do I need to make in the main page ...

The incorrect indentation issue occurs when the text wraps around

I am looking to automatically indent wrapped contents based on the first line. To achieve this, I implemented the following HTML and CSS code: li { padding-left: 10px; text-indent: 10px; } .Slides { width: 20em; //Display wrap-around } <div cla ...

Conceal the horizontal scrollbar when the navigation menu is minimized

Explaining this concept may be a bit challenging, so I have included a jsfiddle demo. The issue at hand involves a bootstrap nav menu that shifts to icons when not active and expands to include words when focused. When the menu is expanded, there are no sc ...

utilizing the caret symbol in css

I just learned a helpful tip: you can use the following CSS code to select all inputs with an id starting with 'start_of_name': input[id^=start_of_name] Is there a way to do the same for selecting the end or middle of the name? ...

Shifting elements within a modal using AngularJS and CSS: Swapping one div out for another

I am currently developing an application and I am considering using AngularJs for this purpose: <div class="main"> <div class="one">Content 1 goes here ...</div> <div class="two">Content 2 goes here ...</div> </div> Wi ...

Text does not wrap correctly when placed between elements with the property white-space: nowrap

When applying the white-space: nowrap property to all children of an element, an issue arises in Webkit (and blink) where white space doesn't break between elements as expected: View example on jsFiddle .pairs { width: 180px; overflow: hidde ...

Observing changes in the dimensions of flex children using MutationObserver

Considering the following structure of the Document Object Model... <div id="outer-container"> <div class="side-panel"><div width="200px"/></div> <div id="content"><!-- some content --></div> <div class=" ...

"Encountered difficulty in retrieving the width of an element upon refreshing the

I have come across a puzzling situation with my code that involves determining the width of a block element. Here is an excerpt from the code snippet: //get the largest block: if no block, apply to first block var previous = $('.block-grid .block-gr ...

Certain line borders are more robust compared to the rest

I have been working on a calendar application where I have designed boxes to display dates. However, I have encountered an issue where some of the line borders appear darker or thicker than others. Below is a snippet of my CSS and HTML code: <style> ...

highcharts-ng expands in flexbox without contracting

I've encountered an issue while trying to incorporate a highchart within a flexbox container. The chart expands along with the container without any problems, but it fails to contract when the container size decreases. My current setup involves angul ...

The alignment of the image is malfunctioning

I'm currently in the process of creating a personalized website for my niece, designed to be akin to a homepage just for her. While I have some experience with coding, I've hit a roadblock when it comes to positioning an image on the page. Someth ...

Why is it that the sequence of CSS imports isn't functioning correctly?

<link href="style1.css" rel="stylesheet" type="text/css"> <link href="style2.css" rel="stylesheet" type="text/css"> When setting the color in style1 to white: .box{ color:#fff; } In style2, the color is set to black. .box{ color:#00 ...