Tips for increasing the width of a div wrapper to accommodate the table within it

I'm currently using the dataTable library with external plugins, and I want the wrapper width to adjust automatically.

Even if the width of th elements exceeds the viewport width, I don't want the div width to exceed 100%.

How can I make the div wrapper expand to fit the table width?

Below is an example that demonstrates my issue:

<html>
<head>
    <title>test</title>
    <style>
    .wrapper {
        background-color: red;
        /* width: 8000px; -> don't look for this kind of solution */
        width: auto;
        display: table;
    }

    .table {
        display: table-cell;
    }

    .table th {
        background-color: yellow;
        border: 1px solid blue;
        width: 4000px; /* -> note that I can't use the min-width trick because this property is set by an external jQuery plugin */
    }
    </style>
</head>
<body>
    <div class="wrapper">
        <table class="table">
            <thead>
                <tr>
                    <th>Hello</th>
                    <th>World</th>
                </tr>
            </thead>
        </table>
    </div>
</body>
</html>

Answer №1

If you're looking for a solution, consider this:

.grid {
    /*max-width: 3000px;*/
    overflow: hidden;
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
}

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

Can you help me create a CSS Toggle similar to this design?

I am currently working on a website and I need to create a FAQs page with a specific layout. When a user clicks on a question (Q), the answer (A) should open smoothly using jQuery animation. Only one question should be visible at a time. If a user clicks ...

Is there a way to showcase CSS styling for elements that are "siblings" when hovering over an item without affecting the item being hovered on?

When hovering over one of the 5 text bits, I want to apply CSS to all bits except the one being hovered over. Can you achieve this using jQuery and the .siblings() attribute? Here is the HTML: <table width="1138" height="38" border="0" class="Home111 ...

Can the text color be customized to match the brightness level of the background area being covered?

Does anyone know of a plugin or method that can automatically change the color of text or swap predefined images/icons based on the average brightness of its parent element's background? If the background is dark, it should make the text white or swit ...

Why does #id not work in CSS but element##id does? Additionally, why doesn't general CSS affect element##id when it should?

Why isn't #hex{ } working properly across different browsers (I've tested in Edge, Chrome, and Opera but it's not working)? On the other hand, img#/#hex{} (which I discovered using Chrome Developer Tools) works perfectly everywhere. Below i ...

Bespoke animated angular material tabs

Having an issue with Angular Material tabs. I have managed to remove the "slide" effect, but I can't figure out how to modify or remove the black effect behind my tab. Can anyone offer some assistance? black effect 1 black effect 2 Here is a snippe ...

The issue of a centered image not displaying properly and the inability to adjust the font

I'm trying to get the image to display bigger and in the center, but no matter what I try it's not working. HTML: <div class="content-grid"> <img src="test.jpg" /> </div> CSS: .content-grid img{ display: block; margin: ...

Implementing css padding to text preceding images

My content includes text and images in a mix, and I wish to add CSS margin to elements that appear directly before and after the images. Unfortunately, the placement of these elements can vary and is beyond my control. The code snippet below demonstrates ...

Modifying the CSS class of an element does not produce the desired effect after altering its styles using JavaScript

html: <input id="myinput" class="cinput" type="image" src="http://www.foodwater.org.au/images/triple-spiral-3-small-button.jpg"/> <br><br><br><br> <button id="s">set to visible class</button> <button id="h"> ...

Issues with Bootstrap's "img-fluid" class functionality

I recently started the web development course by Colt Steele and ran into an issue while working on the "Museum of Candy project" (I made some modifications to it). The problem is that I am using a widescreen monitor, and when I expand my window, the image ...

What's causing all my carousel slides to stack on top of each other instead of presenting in a

Whenever I click 'run' or 'preview' in a browser, specifically using Chrome, all three slides are displayed stacked from 1 to 3 in a static view. They do not toggle through each slide as intended. This issue only occurs on Codeply, a p ...

Issue with hamburger icon in Bootstrap navbar following height adjustment of the navbar

Although my navbar was functioning properly with the hamburger menu expanding down as expected, I encountered an issue after adjusting the height of the navbar. The hamburger button still worked and expanded the menu, but it only displayed the first item o ...

Displaying a profile hover card allows users to easily discover and choose whether to follow or explore

I created a profile hover card on my website with a follow/unfollow button. However, I encountered an issue - the hover card disappears when I move away from my profile thumbnail. How can I fix this so that the hover card stays visible on mouseover and dis ...

What could be causing the absence of the box within the div element?

I am still learning the ropes of javascript, CSS, HTML and programming in general. Despite being a beginner, I have managed to grasp the basics of simple HTML and CSS. I had successfully created a nested div structure before, but suddenly the inner div is ...

Choose links that do not start with a particular pattern

I've been playing around with CSS and I've learned how to select links that start with a certain pattern, like a[href^="tutorials_"] { text-color: red; } But now I'm curious if there's a way to select links that don't start with ...

Transitioning the height of a webpage element from a fixed value to fit the content dynamically

I'm trying to create a div that smoothly transitions from a set height to a height based on its text content. This likely involves considering the window width, as narrower windows cause text wrapping and increase the required height. #object { w ...

Strangely behaving animated mobile navigation glitch

CodePen showcasing the mobile navigation Upon initial interaction with the mobile navigation, it operates as expected. However, a bug arises with subsequent interactions. The navigation either opens and closes instantly or the links appear in a jumbled or ...

Excessive Font Awesome Icons causing navigation bar to appear oversized

My Font Awesome icons are causing my navbar to expand in height. Despite resetting all margin and padding to 0, adjusting the margins and paddings of the icons has not helped. I even tried setting negative top and bottom margins/paddings. https://i.sstati ...

Variability in the positioning of list item markers depending on the child's display property

Looking at this code: <ul> <li> <div id="container"> <button>toggle display</button> <div>text</div> <div>text</div> </div> </li> ...

Conceal all components on a webpage with the exception of a designated div

I am looking to selectively hide elements on the page, revealing only the contents of div.k1. The page contains numerous elements. How can I achieve this using just CSS? <div>1-this will be hidden</div> <div class="k1"> 2-this div wi ...

Change the button icon to something new when you hover over it

Below is the liquid code I am working with: <a href="{{ section.settings.button_link }}" class="btn--rounded"> {% include 'icon-btn--rounded' %} <div class="link-label">{{ section.settings.button_ ...