How can you restrict the height of a scrollable column to match the size of a responsive embed column in Bootstrap 4?

I currently have a bootstrap 4 layout featuring 3 columns, with the middle column containing two nested columns. One of these nested columns includes an embedded YouTube video with responsive sizing, while the other displays a scrollable list of text with a red background. I am seeking to set the height of the scrollable column to match exactly that of the embedded video, ensuring it remains resizable and responsive. If the device width is insufficient, the scrollable column should collapse beneath the video. Here is the code for reference: https://jsfiddle.net/h7f8r1ut/

I would appreciate any suggestions on achieving this without relying on JavaScript.

Despite researching similar queries, I was unable to locate a solution that aligns perfectly with my specific requirements.

.scroll {
  text-align: left;
  height: 40vh;
  overflow: hidden;
  overflow-y: scroll;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div id="app">
  <div class="container-fluid">
    <div class="row">

      <div class="col-md-2 bg-dark text-info">
        left sidebar
      </div>
      <div class="col-md-8 bg-secondary">
        <div class="container-fluid">
          <div class="row">

            <div class="col-md-10" id="video">
              <div class="embed-responsive embed-responsive-16by9">
                <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/zpOULjyy-n8?rel=0" allowfullscreen></iframe>
              </div>
            </div>
            <div class="col-md-2 scroll bg-danger">
              <p>1</p>
              <p>2</p>
              <p>3</p>
              <p>4</p>
              <p>5</p>
              <p>6</p>
              <p>7</p>
              <p>8</p>
              <p>9</p>
              <p>10</p>
              <p>11</p>
              <p>12</p>
              <p>13</p>
              <p>14</p>
              <p>15</p>
              <p>16</p>
              <p>17</p>
              <p>18</p>
              <p>19</p>
              <p>20</p>
              <p>21</p>
              <p>22</p>
              <p>23</p>
              <p>24</p>
              <p>25</p>
              <p>26</p>
              <p>27</p>
              <p>28</p>
              <p>29</p>
              <p>30</p>
              <p>31</p>
              <p>32</p>
              <p>33</p>
              <p>34</p>
              <p>35</p>
              <p>36</p>
              <p>37</p>
              <p>38</p>
              <p>39</p>
              <p>40</p>
              <p>41</p>
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-2 bg-dark text-info">
        right sidebar
      </div>
    </div>

  </div>
</div>

Answer №1

To create a scrollable content area, you should place it inside a parent element with position:absolute and then apply overflow:auto to the column. Bootstrap 4.3 and newer versions have specific utility classes for this purpose.

              <div class="container-fluid">
                  <div class="row">
                        <div class="col-md-10" id="video">
                            <div class="embed-responsive embed-responsive-16by9">
                                <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/zpOULjyy-n8?rel=0" allowfullscreen=""></iframe>
                            </div>
                        </div>
                        <div class="col-md-2 overflow-auto bg-danger">
                            <div class="position-absolute">
                                <p>1</p>
                                <p>2</p>
                                ....
                            </div>
                        </div>
                   </div>
              </div>

UPDATE:

If you want the scrolling feature only on larger screens (md and above), you can use a media query like this:

@media (min-width: 768px) {
    .position-md-absolute {
        position: absolute;
    }
}

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

Having trouble getting the CSS Hover state to function properly?

I am currently working with a code snippet that looks like this: <div style="position: absolute; margin-left: -22px; margin-top: -22px; left: 502px; top: 379px; z-index: 380; display: block;" class="maptimize_marker_0 f st">1<span class="pinlabel ...

Styling with CSS: Changing the Background Color of Text

Looking for a solution to apply line-height to text without affecting the background color? Check out the code snippet below and share your ideas if you have any. Thanks! .nb-semnox-impact-grid { display: block; font-size: 6 ...

Strange HTML antics

On my website, I encountered an issue when trying to register without entering any information into the required fields. The errors were correctly displayed in this screenshot: https://i.sstatic.net/wrxjt.png However, after inserting random characters in ...

Remove a div element with Javascript when a button is clicked

I am working on a project where I need to dynamically add and remove divs from a webpage. These divs contain inner divs, and while the functionality to add new divs is working fine for me, I'm facing some issues with removing them. The code snippet b ...

The alignment of a background image in CSS is different from using margin:0 auto, especially when dealing with scrollbars

Check out the following link to view the issue: http://jsfiddle.net/7zb6P/1/ In a scrolling div, both the yellow box and the background image are centered, however their centers appear slightly different. The discrepancy seems to be because the background ...

What could be causing Bootstrap to fail in my fresh Angular project?

Upon creating a fresh angular project, I proceeded to install bootstrap using npm. Once it was successfully installed in my node_modules folder, I added it to my angular.json file. "styles": [ "/node_modules/bootstrap/dist/css/ ...

Simulating the behavior of display blocks

HTML similar to the example below is working perfectly, however, there seems to be an issue with Sharepoint 2013's editor. When trying to edit the link text within a block that has 'display: block' or 'float', it becomes impossible ...

AngularJS displays the value from the dropdown menu in the input field

I am looking for a way to display the text "login" and "password" from $scope.logins when a user clicks on them in a dropdown menu. $scope.logins = [{ "login" : "log", "password" : "pass" }] Here is the HTML code: <div class="drop ...

Having trouble getting the Twitter Bootstrap navbar to display properly on mobile and iPad browsers

Is there a way to make the navigation bar float on mobile browsers when using the "navbar" and "navbar-fixed-top" classes? I've tried this on various devices like iPad (Safari, Chrome), Android (Firefox), and Windows Phone (IE), but it doesn't se ...

Achieving the Perfect Alignment: Displaying Text and Progress Bar Side by Side using Bootstrap 5

How can I align the text and progress bar on the same line using Bootstrap 5? <nav class="navbar bg-light fixed-bottom"> <div class="row m-0"> <div class="col-12 countdown"> <p class=&q ...

Difficulty positioning CSS, aligning flex-box grid with floating text

My attempt to include an aside section is causing alignment issues with the navigation menu and the aside itself. The problem seems to be related to using float:left for the 200x200 images. I want the layout to be well-positioned like the expected image. I ...

Calculating the Distance Between Elements within a Flex Container Using JavaScript

I am looking to calculate the margin left and right for children of a flex item <div class="sec images" style="display:flex;justify-content:space-between"> <img src="images/en_mb-mega-01.png" alt=""> ...

Enhancing a Vue component by including two dynamically computed class properties within a :class="{{}} {{}}" tag

As a newcomer to the Vue world, I have been experimenting with applying 2 computed properties to a :class attribute. Initially, I tried separating each property by a space like this: :class="{{prop1}} {{prop2}}", but upon reload, all content would disappea ...

How can I change the font size in PHP from each font size="" to font-size:?

Is there a way to use PHP to replace every instance of font size="somenumber" (with a different number each time) with font-size="somenumber"? I need to convert text that looks like this: Hello <font size="4">today</font> is my <font size= ...

I rely on the angular-responsive-carousel library for my project, but unfortunately, I am unable to customize the arrow and dots

When it comes to CSS, I utilize ng deep style in Angular 10 to make changes for browser CSS. However, I am facing an issue where the problem is not being resolved by my CSS code. Here is a snippet of my code: > ::ngdeep .carousel-arrow { > b ...

When hovering, the CSS border-bottom should extend

I am looking to create an animated border effect. When hovering over the link, I want the border-bottom to extend seamlessly from left to right. After much searching, I am still unsure what this effect is called. Below is the code I have: .a{ width ...

Stop the execution of javascript code based on the screen width

On my website, I have two menus located in different sections of the page. One menu is shown when the screen width is greater than 555px, while the other menu appears when the screen width is less than or equal to 555px. Although the menus are essentially ...

Is there a reason why using margin:auto doesn't work for vertically centering items?

I'm having trouble understanding how margin auto functions. In the scenario I'm dealing with, I have a parent div and a child div nested within it, both with specified widths and heights. I attempted to use margin auto in order to center the inne ...

Centering the header image on the screen creates a visually appealing focal point

Looking to design a header image for my website that always stays centered. I want the image to stand out and remain in the middle even when the browser window is resized. I found an example on this website that achieves this effortlessly. ...

assigning the browser's width to a variable within an scss file

Is there a way to dynamically set the browser's width as a variable? I am familiar with @media queries, but I need to calculate the browser's width for a specific purpose. I attempted using jQuery to achieve this, and it works well with a fixed ...