Set the DIV element to match the height of its container

I'm currently using this HTML code, and it's functioning correctly. However, I would like the height of the div to adjust dynamically based on the tab's content, rather than specifying a fixed height of 200px. Using a percentage value for the height doesn't seem to work in this case. Please note that the draggable feature is from a third-party source.

<b-tab title="TAB">
  <div class="table-wrapper-scroll-y custom-scrollbar">
    <table class="table table-sm table-bordered table-striped table-hover">
      <draggable :list="myLoop" :options="dragOptions" :element="'tbody'" class="rows">
        <tr class="cursor-ns-resize" v-for="(row, index) in myLoop" :key="index">
          <td>
            <b-form-checkbox type="checkbox" v-model="row.checked" />
          </td>
          <td>
            <span>{{ row.label }}</span>
          </td>
        </tr>
      </draggable>
    </table>
  </div>
</b-tab>

CSS

.custom-scrollbar {
  position: relative;
  height: 200px;
  overflow: auto;
}

.table-wrapper-scroll-y {
  display: block;
}

Answer №1

By setting the parent element (b-tab) to have flex properties, the child element div will automatically inherit the height without requiring an explicit height value for the div. It is important to ensure that the div has the flex-grow and flex-shrink properties set to 1 (or you can use the shorthand flex: 1 1).

I've applied colored borders to both elements to better demonstrate:

b-tab {
  border: 1px solid red;
  height: 200px;
  display: flex;
}

.custom-scrollbar {
  position: relative;
  overflow: auto;
  border: 1px solid blue;
  flex: 1 1;
}

.table-wrapper-scroll-y {
  display: block;
}
<b-tab title="TAB">
  <div class="table-wrapper-scroll-y custom-scrollbar">
    <table class="table table-sm table-bordered table-striped table-hover">
      <draggable :list="myLoop" :options="dragOptions" :element="'tbody'" class="rows">
        <tr class="cursor-ns-resize" v-for="(row, index) in myLoop" :key="index">
          <td>
            <b-form-checkbox type="checkbox" v-model="row.checked" />
          </td>
          <td>
            <span>{{ row.label }}</span>
          </td>
        </tr>
      </draggable>
    </table>
  </div>
</b-tab>

Answer №2

Consider including the following in your CSS:

*{
    margin:0;
    padding:0;
}

This code snippet will help reset the default margin and padding values that some browsers automatically apply.

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

Is there a way to showcase XML in a web browser while maintaining its whitespace and preserving its preformatted text?

In an attempt to simplify the process of formatting my reports, I am considering creating a basic XML language. This would resemble something like this: <?xml-stylesheet href="./report.css"?> <report> <title>A Tale of Two Cities</ ...

Align the button at the center of the carousel

While working on a personal HTML/CSS/Bootstrap 5 project as a self-taught learner, I have encountered some beginner doubts. My challenge is to ensure that the site remains responsive across various devices such as mobile and tablet. Specifically, I am stru ...

Show or conceal advertisement based on user role

I have developed a custom Web Control that acts as a container for a mobile banner, but I want to hide it from users who are admins. So far, I've attempted the following: <mob:MobileBanner runat="server" ID="MobileBanner" Visible='<%# Not ...

Listen for changes in the clientWidth of an element in Vue 3

Hey there, I'm currently working on a project where I need to track the clientWidth of a component when it gets resized. I'm trying to achieve this by using: const myEl = document.querySelector('#myID') and monitoring changes in myEl. ...

Using Vue.js: Load component only after user's button click

I need some help with my code setup. I want to make it so that the components "dataPart1' and "dataPart2" are not loaded by default, but only appear when a user presses a button to view the data. How can I achieve this functionality in Vue.js? var ap ...

Modifying CSS styles in JavaScript based on the user's browser restrictions

My CSS style looks like this: button.gradient { background: -moz-linear-gradient(top, #00ff00 0%, #009900 50%, #00dd00); background: -webkit-gradient(linear, left top, left bottom, from(#00ff00), color-stop(0.50, #009900), to(#00dd00) ...

Lightbox2 is looking to reposition the caption to the right of the image

Can anyone help me understand how to move the caption, found in data-title, from underneath an image to the right of the image? I'm not very familiar with HTML/CSS, but it looks like the image is enclosed within a div called .lb-outerContainer, and t ...

How to extract object properties in v-select using Vue.js and Vuetify

My specific scenario. I received an array of objects from a backend API. I aim to display these objects in a v-select This snippet shows my current code. <v-select :items="categories" name="category" label="Select a cate ...

Understanding how to display a component within another component in Vue.js

I am faced with a scenario where I have a component that has the following template: <div v-for:"item in store" v-bind:key="item.type"> <a>{{item.type}}</a> </div> Additionally, I have another component named 'StoreCompone ...

How can I integrate custom PHP pages into Odoo Community 12?

I am looking for a way to integrate my custom PHP webpages with the login page of Odoo Community that is already set up and functioning on my server. I want specific users to be redirected to my custom pages after logging in. Any suggestions on how to ac ...

When using Nuxt JS and Jest, a warning message may appear stating "[Vue warn]: Invalid Component definition" when importing an SVG file

I am facing a unique issue only in my Jest unit test where an error occurs when I import an SVG into the component being tested: console.error node_modules/vue/dist/vue.common.dev.js:630 [Vue warn]: Invalid Component definition: found in -- ...

Jspsych: Centering and aligning 3 p tags to the left on the page

Feeling pretty stuck at the moment. Here's what I have visually right now: https://i.sstatic.net/FUzgM.png I added a caption in Comic Sans and an arrow using MS Paint. Each line with color swatches is wrapped in a p tag. The goal is to center thes ...

disable any other active toggle in a vue component

Exploring JavaScript and how to accomplish the following tasks Snapshot The issue I am facing is that if I click on a product, and then click on settings, both are open. However, I want only the currently clicked toggle to be open. For instance, if I cl ...

Minimize the amount of space used in GridLayout

My component has a Grid Layout with 1 column specified as auto, auto. I have placed 2 Items within this Grid, each taking up the full space of the column. However, due to the large size of the items, I have reduced them using transform: scale(0.7);. The i ...

Scale transformation - I am aiming for it to exceed the limits, yet it remains contained within

Currently, I am working on enhancing my carousel by implementing a zoom effect when hovering over the images. However, I have encountered an issue where the image gets hidden within the div container and doesn't overflow as expected. I tried adjusting ...

Adjust the width of the <li> element based on the quantity of its children

If the number of list items can be changed dynamically, how can I adjust the width of each item so that the total width is always 100%? Here is an example code snippet: <nav> <ul> <li>A</li> <li>B</li> &l ...

CSS3 variables causing issues

I want to streamline my CSS file by setting up generic variables that can be used throughout to ensure consistency and organization. For example: @shadow: 6px 6px 10px rgba(0,0,0,0.2); .shadow { box-shadow: @shadow inset; } However, when I try to a ...

The information is not being stored in Excel despite the fact that the Excel document has been generated with a header

I have been working on a project that involves fetching book details from the Google Books API and using generative AI to create descriptions for them. I have successfully created an Excel file, but I am facing an issue with saving data inside it. It' ...

My website, powered by Wordpress, is currently experiencing an issue with excessive whitespace being added to the bottom of the contact form 7 plugin. I am perplexed as to the cause of this issue and

Recently, I've come across an issue with my contact form 7 plugin, which has been integrated into the front-page.php file using the code below: <div id="contact" class="pad-section"> <div class="container"> <h1>Contact Us</ ...

Create a stylish slide-in menu using CSS, triggered by an onclick event. No JavaScript required!

I implemented a hamburger menu that slides in when clicked. However, I'm facing an issue where the slide-in menu disappears after a second. How can I make sure the menu stays visible? #navigationWrap { position: fixed; top: 0; ...