Ways to set the minimum width of a div depending on its contents

As I work on my website, I encountered an issue with a div containing a table. The div expands to full width, but when I resize the screen, it shrinks causing the content to overlap.

I am looking for a solution where the minimum width of the div adjusts based on the content within the table. The main div has a class of "search". You can find the relevant code snippets in the following link:

.search {
  border: 2px solid #FDBF3B;
  background-color: #FFEBC1;
  padding: 10px;
  margin: 5px 0;
}

.search table {
  border: none;
}

.search .header {
  margin-bottom: 5px;
  border-bottom: 1px solid #FDBF3B;
  padding-bottom: 2px;
  color: #000F1F;
  font-weight: bold;
  overflow: hidden;
}

.search .buttons {
  margin-top: 5px;
  border-top: 1px solid #FDBF3B;
  padding-top: 8px;
  white-space: nowrap;
}

.inner {
  padding: 7px;
  min-height: 480px;
  z-index: 1;
  overflow: auto;
}
<DIV class=inner>
  <DIV class=search sizset="false" sizcache017720493147691946="40 33 1">
    <DIV class=header>Search Options </DIV>
    <TABLE sizset="false" sizcache017720493147691946="40 33 1">
      <TBODY sizset="false" sizcache017720493147691946="40 33 1">
        <TR>
          <TD></TD>
          <TD class=LABEL>
            <SPAN id=LBL_NAME>Name:</SPAN>
          </TD>
          <TD>
            <INPUT name=NAME style="BACKGROUND-COLOR: #ffffff" type=text size=15 maxLength=10 data-dpmaxz-eid="4">
          </TD>
        </TR>
        <TR>
          <TD></TD>
          <TD class=LABEL>
            <SPAN id=LBL_ADDRESS>Address:</SPAN>
          </TD>
          <TD>
            <INPUT name=ADDRESS style="BACKGROUND-COLOR: #ffffff" type=text size=40 maxLength=50 data-dpmaxz-eid="5"> </TD>
        </TR>
      </TBODY>
    </TABLE>
    <DIV class=buttons>
      <INPUT name=SEARCH class=BUTTON type=button value=Search>
      <INPUT name=SEARCH class=BUTTON type=button value=Clear>
      <INPUT name=CREATE class=BUTTON type=button value=Create> </DIV>
  </DIV>
</DIV>

Answer №1

To ensure proper display, set a minimum width for the parent div and handle overflow in the body. If the window width is reduced below the search div's width, a scrollbar will appear on the body.

    .body{
       overflow: scroll;
    }
    .search {
       min-width:380px;
    }

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

Why was the 'Symbol' type introduced in ECMA-262-v6 and what purpose does it serve?

Can you explain the purpose of the 'Symbol' type in ECMA-262-v6? Is it used for fast path implementation for object keys? How does it work internally - does it hash with the assurance that the underlying data remains unchanged? ...

Ways to halt a script entirely once its tag has been eliminated

I have a script from a page tracker website that runs periodically. Occasionally I need to restart the script from the beginning. To do this, I typically remove the script tag from the DOM and then re-append it. However, because the script utilizes setInt ...

Does the jQuery function val() not clear new lines properly?

Am I missing something here? $('textarea').val('') It still keeps new line in the textarea if there were any. Any suggestions for a solution? ...

The stunning fade effect of Magnific Popup enhances the visual appeal of the inline gallery

I'm currently using magnific popup for an inline gallery, but I'm not seeing any effects. I would like to have a fade effect when opening/closing the popup. Can someone assist me with achieving this? https://jsfiddle.net/gbp31r8n/3/ [Check o ...

Can you locate the hiding spot of the express-session cookie?

After setting a very short cookie max-age (10 secs) in my express-session, I confirmed that it is working as expected: app.use(session({ secret: 'xxx', resave: false, saveUninitialized: true, cookie: { secure: true, maxAge: 10000 } })); ...

What is the proper way to add multiple divs using jquery?

Is there a way to simplify this lengthy HTML code used for browser alerts? Here is an example: <div class="ie-message" style="display: block; "> <div class="alert error"> <h2> Sorry, your web-browser is outdated ...

HTML dynamic voting system

I'm new to coding in HTML and I have a specific challenge that I need help with. I want to display a value on my webpage that increases every time a user clicks a button. Below is the code I have written so far: <script type="text/javascript& ...

What is the best way to calculate the total of all files within a folder structure using JavaScript

Here is the array I'm working with: Array (7812) 0 {foldername: "", amount_of_files: 12, children: 86} 1 {foldername: "/pm", amount_of_files: 3, children: 7} 2 {foldername: "/pm/css", amount_of_files: 1, children: 0} 3 {f ...

React Modals: Only the modal component triggered by the first click will open, with no other modals opening

As a newcomer to StackOverflow, I apologize if my problem description is not clear. I am currently learning React and working on a course-search app as a project. The app filters courses based on user input from a JSON file and displays them in cards with ...

The script in (Nuxt.js/Vue.js) appears to only function once, becoming inactive after switching routes or refreshing the page

I'm currently in the process of transitioning my projects website to Vue.js with Nuxt.js integrated. I have been transferring all the files from the remote server to the local "static" folder. Everything seems to be functioning properly, except for t ...

Video showcasing issue with updating Ionic2 view

I am encountering an issue where my View is not updating as expected. When a player makes a move, the triggers work (I did a console log on every update of the current game [1]), but the View does not update regularly. To investigate this problem, I added ...

Create a new visual masterpiece using Canvas by repurposing an

I am currently working on the following code snippet; export default async function draw(elRef : RefObject<HTMLCanvasElement>, tileData : TileProps) { const canvas = elRef.current!; const ctx = canvas.getContext('2d')!; ctx.clearRect( ...

What is the best way to retrieve an element that has been altered in its state?

I encountered a scenario where I want an image to have a border when clicked, and if clicked again, the border should be removed. However, the border should also be removed if another image is clicked instead. I believe there are a couple of approaches to ...

Pressing the "Enter" key will submit the contents of

Hello, I have recently created a new chat box and everything seems to be working fine. However, I am facing an issue with submitting a message when I press enter (to go to the function Kucaj()). Can anyone provide assistance with this problem? I tried ad ...

How can I adjust the appearance of an HTML tag within an Angular component?

I have created an Angular component with the following definition: import { Component, Input, Output, EventEmitter } from '@angular/core'; @Component({ selector: 'rdc-dynamic-icon-button', templateUrl: './dynamic-icon-button. ...

Ajax is able to send a string representation of a list rather than just the raw list itself

Utilizing jQuery to collect all the data entered on the webpage, then utilizing ajax to transmit this information to my django view. Here is the code responsible for that: var button = $("#serialise"); var JSON_content = $('#JSON_Contents') $( ...

Tips for obtaining a specific sorting order based on a wildcard property name

Here's the structure of my JSON object, and I need to sort it based on properties starting with sort_ { "sort_11832": "1", "productsId": [ "11832", "160", "180" ], "sort_160": "0", "sort_180": " ...

CORS - Preflight request response fails access control verification

I've been attempting to send a GET request to a server with the same domain as my local host, but I keep encountering the following error: The preflight request response fails the access control check: The requested resource does not have an ' ...

Is there a method in Angular to refresh or recompile a specific section or entire page that utilizes one-time bindings?

With numerous lists on our page containing potentially hundreds of items, we prioritize performance by implementing one-time bindings to update only when necessary and minimize the number of watchers. If we decide to utilize one-time bindings, is there a ...

Learn how to retrieve data by clicking on the previous and next buttons in FullCalendar using Vue.js

Seeking guidance on retrieving calendar data from the database for my Vue frontend, I have incorporated the fullcalendar API. Successfully able to retrieve data for the current week, however facing challenges when attempting to fetch data for the previous ...