Achieving equal height and width for 2 divs through Bootstrap/CSS techniques

I'm attempting to ensure that these two divs within a table have the same height and width using the following code:

<div class="container">
    {{#if orders}}
    <div class="filter">
        <ul class="nav nav-pills tab ">
            <li class="nav-item">
                <a class="nav-link tablinks active" href="#">Products</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Cars</a>
            <li class="nav-item">
                <a class="nav-link" href="#">Servicing</a>
            </li>
        </ul>
    </div>
    <div class="table">
        <table class="table tab text-nowrap">
            <thead>
                <tr>

                    <th>Order ID</th>
                    <th>Customer ID</th>
                    <th>Product ID</th>
                    <th>Product Name</th>
                    <th>Quantity</th>
                    <th>Unit Price</th>
                    <th>Amount</th>
                    <th>Order Date</th>
                    <th>Delivery Status</th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
</table>
</div>
</div>

CSS Styles:

.nav-pills .nav-link.active {
  background-color: #8B0000;
  color: white;
}

.tab {
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: #f1f1f1;
  color: black;
}

.tab a {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
  font-size: 17px;
  color: #000000;
}

thead th {
  background-color: #8B0000;
  color: white;
}

Upon adding the "text-nowrap" class in the table, the table layout has changed. How can I adjust the "filter" div to match the width and height of the table header?

Here is how it currently looks: Link to Image

Thank you for your assistance!

Answer №1

After testing with Bootstrap 4.6.1, I encountered the same issue in version 5 as well. The problem arises when the browser width is reduced, causing the table width to exceed the Bootstrap container. Since HTML tables do not naturally wrap columns or shrink smaller than their content, the widths become mismatched. To address this issue, I have added a wrapper around the table that fits within the container and enables horizontal scrolling for the table. However, this solution may not align with your UI preferences. Various adjustments can be made, such as implementing scrolling, allowing table column names to wrap, or converting them into a dropdown menu.

Even when using flexbox instead of a table, there may come a point where the headings are too narrow to fit in a single line horizontally.

To adjust the height, you can modify the padding of .table td, .table th or .tab a, depending on which element you want to change.

.nav-pills .nav-link.active {
  background-color: #8B0000;
  color: white;
}

.tab {
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: #f1f1f1;
  color: black;
}

.tab a {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
  font-size: 17px;
  color: #000000;
}

thead th {
  background-color: #8B0000;
  color: white;
}

.table-wrapper {
  width: 100%;
  overflow-x: scroll;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b5b8b8a3a4a3a5b6a797e3f9e1f9e6">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="filter">
    <ul class="nav nav-pills tab ">
      <li class="nav-item">
        <a class="nav-link tablinks active" href="#">Products</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Cars</a>
      <li class="nav-item">
        <a class="nav-link" href="#">Servicing</a>
      </li>
    </ul>
  </div>
  <div class="table-wrapper">
    <div class="table">
      <table class="table tab text-nowrap">
        <thead>
          <tr>

            <th>Order ID</th>
            <th>Customer ID</th>
            <th>Product ID</th>
            <th>Product Name</th>
            <th>Quantity</th>
            <th>Unit Price</th>
            <th>Amount</th>
            <th>Order Date</th>
            <th>Delivery Status</th>
            <th></th>
            <th></th>
          </tr>
        </thead>
      </table>
    </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

Error: AsyncPipe received an invalid argument of type '[object Object]'. This has caused an error due to an invalid pipe argument

I'm currently working on developing a contact management system that includes CRUD operations using Angular 8 and Spring Boot. Every feature is functioning correctly except for the search functionality. My goal is to search for data based on a specifi ...

Ways to display dropdown links in a specific sequence?

Is there a way to display the drop-down links in a specific order? The current order is as follows: Link 1 Link 3 Link 2 Here is the HTML Code: <ul class="navbar-nav"> <li class="nav-item dropdown"> <a class=" ...

Updating the background image for a radio button

Is it possible to customize the background image within the active radio button from the default redmond to aristo? .ui-radiobutton-icon { background-image: url("/images/ui-icons_38667f_256x240.png.jsf"); } Can someone help with the correct syntax for t ...

Adjusting the color scheme of a Checkbox Button in Bootstrap 4

Seeking advice on locating overrides for certain css properties. Take a look at this illustration on https://getbootstrap.com/docs/4.1/components/buttons/#checkbox-and-radio-buttons. The contrast in color between the activated and deactivated states is n ...

What is the best way to find out the height of a row?

I'm curious to understand why setting a height value for the first flex-item in the example below results in an increase in the height of the first row. It would be helpful to determine how to calculate the height of a row, especially when the height ...

Angular directive button failing to trigger ng-click event

Recently, I started working with Angular and ran into an issue while trying to set up a custom directive. The purpose of this directive is to display a button upon hovering over it, which, when clicked, should trigger a function within the directive. The b ...

Tips for creating space between two fluid divs

I'm currently facing an issue with the spacing between two child divs inside a parent div. The web page needs to be responsive for different screen widths, but the vertical space between the left and right divs is not behaving as expected. I am using ...

The issue with implementing simple getElementsByClassName JavaScript in the footer of a WordPress site persists

I am facing an issue with a 1-liner JavaScript code in the footer where getElementsByClassName function doesn't seem to work for tweaking style attributes. The text "Hello World" is displaying fine, so I suspect it might be a syntax error? Here' ...

A basic webpage created using ASP.NET featuring simple HTML text

Is it acceptable to manually code HTML, such as <p>, <ul>/<li>, <h3>, <h4>, <blockquote> tags, into a Content Page that already has an existing Master Page? The content is similar to a blog post. Are there better desig ...

Implementing a click function that toggles between adding and removing a class, keeping track of the number of clicks, and utilizing localStorage to prevent repeated clicking in the

Hi there! I'm currently working on a simple widget that features a clickable icon and a counter next to it. When the icon is clicked, it should toggle between an empty heart and a filled heart using addClass/removeClass. Additionally, each click incr ...

Is there a way to toggle the visibility of the angular material toolbar at regular intervals?

I'm currently experimenting with the CSS animation feature to display and conceal the angular material toolbar in this demonstration. Inside the application component, the hide attribute is toggled at intervals as shown below: hide:boolean = false ...

Tabbed form design using Twitter Bootstrap

Currently, I am working on a website using the Bootstrap framework. My goal is to create a single page that features a pop-up form with two or three tabs. Specifically, I envision these tabs as "The Markup," "The CSS," and "The JavaScript." While I have ma ...

Creating square elements using only HTML and CSS

This is just a longer text to demonstrate multiple lines being centered. ...

Enhancing BarGraph and Bars Size in Oracle ADF

We have created a web application using Oracle ADF. The application includes a page with a graph displayed below. Currently, we are looking to enlarge the bar graph by increasing its height, width, and size of the bars themselves. Difficulty 1: While we ...

Python Selenium - encountering issues with interactability of elements

Trying to complete the form on () is proving tricky for me. When I utilize Javascript, document.getElementsByName("userName")[0].value = "Hello", I am successful in entering text into a form. However, when I apply the same logic in Sel ...

How can I restrict the number of items displayed in each row within a navigation submenu flexbox?

My primary navigation menu has numerous child items, and I want to ensure they remain visually appealing and organized. To achieve this, I am aiming to limit each row of submenu items to only 4. After researching other solutions online, I attempted adding ...

How to vertically center a div within a parent div with a fixed position?

I am facing an issue where I have a div positioned on top of another fixed position div, and I am looking for a way to vertically align the first div. Below is the code snippet that I am currently working with: <div class="overlay"> <div id=" ...

Embedding PHP code within the value attribute of an HTML element is

Hey there! I'm looking to perform a database search and then display the results in a pre-populated HTML form for the user. I've pinpointed the issue in my code where PHP is not being recognized by the server. I'm currently using UwAMP. To ...

There seems to be an issue with the accurate calculation of the screen width while utilizing the scrollbar-gutter

Please take note: The scrollbar-gutter: stable; property is not compatible with Safari. Additionally, the issue seems to be specific to Chrome and works fine in Firefox. I have observed some unusual behavior when attempting to position elements fixed to t ...

Rotating an input 90 degrees within a div for unique positioning

I used JavaScript to make an input range vertical, like so: var range_pitch = document.createElement("input"); range_pitch.setAttribute("type", "range"); range_pitch.style.webkitTransform = "rotate(90deg)"; range_pitch.style.mozTransform = "rotate(90deg)" ...