Overflowing content in a table within a div element

Issue: I am encountering a problem with resizing a table inside a div that contains input elements. When I adjust the browser window size or change to a lower resolution, the div element resizes and scales down, causing a horizontal scroll bar to appear. However, the table overflows its parent div in this situation. To see an example of this issue, please refer to the code snippet and fiddle provided below.

fiddle- http://jsfiddle.net/CrfaE/573

code-

<html>
<body>
 <div style="border: 1px solid orange; padding: 1px">
  <span>level1</span>
  <div style="border: 1px solid blue; padding: 1px">
     <span>level2</span>
    <div style="border: 1px solid green; padding: 1px">
        <span>level3</span>
        <table style="border: 1px solid red;">
            <tbody>
                <tr>
                    <td>1</td>

                    <td><input value="2017-01-01"></td>
                    <td><input value="abc"></td>
                    <td><input value="3"></td>
                    <td><select>
                            <option value="">Select</option>
                            <option>abc</option>
                            <option>def</option>
                            <option>ghi</option>
                    </select></td>
                    <td><input value="10"></td>
                    <td><input value=""></td>
                </tr>
            </tbody>
        </table>
    </div>
 </div>
 </div>
</body>
</html>

Required behavior : I would like all parent div elements to resize/expand when the browser's window size is adjusted so that the table does not overflow. The user should be able to see the page using horizontal scroll bars without the table overflowing outside the boundaries of the div/body.

Answer №1

Here are some helpful tips for you:

1) Make sure to include type="text" in your input elements.

2) Add the following CSS code:

input[type="text"] {
    width: 100%; // width relative to its parent (td Element).
}

table {
border: 2px solid red;
}
input[type="text"] {
width: 100%;
}
<html>
<head>
    <link rel="stylesheet" type="text/css" href="css/1.css">
</head>
<body>
 <div  style="border: 1px solid orange; padding: 1px">
  <span>level1</span>
  <div style="border: 1px solid blue; padding: 1px">
     <span>level2</span>
    <div style="border: 1px solid green; padding: 1px">
        <span>level3</span>
        <div class="respon">
        <table>
            <tbody>
                <tr>
                    <td>1</td>
                    <td><input value="2017-01-01" type="text"></td>
                    <td><input value="abc" type="text"></td>
                    <td><input value="3" type="text"></td>
                    <td><select>
                            <option value="">Select</option>
                            <option>abc</option>
                            <option>def</option>
                            <option>ghi</option>
                    </select></td>
                    <td><input value="10" type="text"></td>
                    <td><input value="" type="text"></td>
                </tr>
            </tbody>
        </table>
        </div>
    </div>
 </div>
 </div>
</body>
</html>

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

Unable to remove data once it exceeds 10 entries while using AJAX, jQuery, and JavaScript/PHP

I am having an issue where I can insert data into the first 10 rows and delete any of them successfully. However, when I try to insert data starting from the 11th row, I am unable to delete any rows past the 10th. UPDATE: The deletion function does not wo ...

Ensuring Quick Response Times When Incorporating Personalized Text Styles into Twitter Bootstrap

Currently, I am experimenting with incorporating my custom class titled "article-title" which is significantly larger than the default H1 font size in Twitter Bootstrap. Can someone provide guidance on the necessary steps to ensure responsiveness? My goal ...

Changing the image source when clicking on it and removing it can be done by using JavaScript

How can I add a class 'selected' to ".swiper-slide" when it is clicked? I also want to change the image src when svg-img1, 2, or 3 is clicked. However, I need the image to revert back to its default src when another swiper-slide is clicked. ...

The toggler in Bootstrap 5's Navbar menu is experiencing difficulties opening on mobile browsers

Just arrived here for the first time. Encountering an issue with my Bootstrap 5.1 Navbar menu. Background info: My website is hosted locally via Xampp with php pages for forms and cookies. Everything functions perfectly on desktop. Checked responsiveness o ...

Is there a way to automatically hide divs with the style "visibility:hidden" if they are not visible within the viewport?

Currently, I am working on developing a mobile web app. Unfortunately, Safari in iOS 5.1 or earlier has limited memory capabilities. In order to reduce memory usage while using css3 transitions, I have discovered that utilizing the css styles "display:none ...

Is it possible to use a shell script to replace the external CSS file link in an HTML file with the actual content of the CSS file

Seeking a solution for replacing external CSS and JS file links in an HTML document with the actual content of these files. The current structure of the HTML file is as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C ...

Choose a group of radio buttons inside a container when a button is clicked

I have a bunch of containers containing radio buttons. The goal is for the container of a selected radio button to appear different: input[type="radio"]:checked+.container { border: 5px solid red; } <div class="container"> <input class="btn ...

Creating unique CSS div designs based on the nth-child selector

I have created a website layout. https://i.stack.imgur.com/6FSEb.png I have included the file showing the design. The data in the boxes will come from a MySQL database. My query is, can it be done with just one query? Currently, I am running separate q ...

During the loading of the page, the React onChange handler is being triggered repeatedly

We are currently working on implementing an onChange handler for a custom component called Checkbox. The purpose of making this component custom is to effectively encapsulate the intermediate HTML attribute. Here is how we have set it up: <Checkbox i ...

Stop the border from curving along with the container's border radius

Currently, I am working on a tabs component that features a container with border radius. When a tab item is selected, it should display a bottom border. However, I'm facing an issue where the border curves along with the border radius instead of rem ...

The Bootstrap navbar collapse fails to expand in the appropriate location

Whenever I try to expand the navigation on mobile mode by clicking the button, it doesn't push the content downwards. Instead, it just opens a small menu next to the button. Did I make a mistake in my code? <div class = "container"> ...

Alt and title attributes for images are getting mixed up when there is a space in between

Every time I include a space in the alt tag of my image, it completely distorts the entire <img> line. For example, if my image title is Windows 10, specifically related to today's news. Let's assume my image tag reads Windows 10 officiall ...

Mistake made by the author while using the Google Structured Data Test

While reviewing my website, I encountered an error message stating: "Missing required hCard "author"" http://www.google.com/webmasters/tools/richsnippets?q=http%3A%2F%2Fwww.gamempire.it%2Fcastlestorm-ps-vita%2Frecensione%2F131419 Why is this happening? I ...

What is the reason behind the content of a div tag not hiding while the content of a p tag does

<html> <head> <title>How to make a div content disappear when clicked?</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <scrip ...

The show/hide jquery function is functioning perfectly on desktop devices, but issues arise on mobile devices where the divs overlap each other when using the show() method

I need a way to toggle input text boxes based on selection using a select box This is the HTML code snippet: <div class="row"> <div class="form-group"> <div class="col-sm-1 label2"> <label class="control-label ...

What is the best way to include and delete several images on a canvas?

Recently, I've started working with canvas in HTML5 and I'm tasked with creating a paint application. One of the features I need to implement is the ability to dynamically add selected images to the canvas as the mouse moves, and then have the fu ...

Easily accessible button and span located on the right side

One issue I'm facing is that the button and span are not aligned on the same line. Is there a way to resolve this? <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/c ...

Finding a particular sequence of characters and extracting information that comes after it

A while back, I created a website and now I'm looking to transfer the data into a database without manually copying and pasting the 400+ pages it has accumulated. This way, I can transform the site into a database-driven platform. Each page on my sit ...

Resize lowercase letters to fit the box model

Currently, I am in the process of enhancing the python word cloud library available here by adding an HTML export option alongside the existing image export feature. The main challenge I'm facing right now is related to how the underlying python imag ...

What are the steps to incorporating ng2-dnd with a background-image?

I am currently utilizing the ng2-dnd module to enable sorting of a list. While the functionality for sorting and dragging is working smoothly, there's one issue - users can only drag by clicking on the text within my element. My goal is to allow user ...