the scrollbars are appearing on the window instead of within my div container

I'm having trouble getting a scrollbar on my div element when the content is too wide. Instead, the scrollbar always appears on the window itself. I have tried adjusting the overflow settings but can't seem to find the right solution.

jsFiddle

HTML

<table class="wrapper" cellSpacing="0" cellPadding="0">
    <tr>
        <td class="header">
            <div>
                <p class="title">HEADER</p>
                <p class="subtitle">subheader</p>
            </div>
        </td>
    </tr>
    <tr>
        <td class="content">
            <div class="clearfix">
                <div class="col4">
                    <div>
                        <label class="fieldname">Field 1</label>
                        <span class="fieldcontrol"><input type="text" id="Text1" /></span>
                    </div>
                    <div>
                        <label class="fieldname">Field 2</label>
                        <span class="fieldcontrol"><input type="text" id="Text2" /></span>
                    </div>
                    <div>
                        <label class="fieldname">Field 3</label>
                        <span class="fieldcontrol"><input type="text" id="Text3" /></span>
                    </div>
                    <div>
                        <label class="fieldname">Field 4</label>
                        <span class="fieldcontrol"><input type="text" id="Text4" /></span>
                    </div>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td class="footer">
            <div class="clearfix">
                <div class="left">
                </div>
                <div class="right">
                    <button type="submit">Ok</button>
                    <button>Cancel</button>
                </div>
            </div>
        </td>
    </tr>
</table>

CSS

.content > div
{
    overflow: auto;
}

This setup includes a header, body, and footer using a table structure. In the body section, I want a div element to expand to the full width and height of the table cell. When I resize the window, I expect the header and footer to resize accordingly while the body displays a scrollbar if the content overflows.

Thank you!

Answer №1

Wouldn't it be more efficient to use only div elements for this layout? http://jsfiddle.net/tP79v/2/

Here is the HTML code:

<div class="header">Header</div>
<div class="main">
    <div class="toBig"></div>
</div>
<div class="footer"></div>

And here is the CSS code:

.body {
    overflow:hidden;
}

.header {
    position: absolute;
    top:0;
    left:0;
    width:100%;
    height:30px;
    background-color:lightblue;
}

.main {
    position: absolute;
    top:30px;
    bottom: 20px;
    width:100%;
    left: 0;
    background-color:red;
    overflow: auto;
}

.toBig {
    position:relative;
    width: 1000px;
    height: 200px;
    background-color:yellow;
    margin:20px;
}

.footer {
    position: absolute;
    bottom:0;
    left:0;
    height:20px;
    width:100%;
    background-color:green;
}

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

The Bootstrap Tooltip seems to be glued in place

Utilizing jQuery, I am dynamically generating a div that includes add and close buttons. Bootstrap tooltips are applied to these buttons for additional functionality. However, a problem arises where the tooltip for the first add button remains visible even ...

Establishing connections between HTML and CSS files

After writing my html and css code, I noticed that the files are not linking properly. Despite checking for errors, I couldn't find any issues within the codes. Here is a snippet of my html file: <!DOCTYPE html> <html lang="en" dir= ...

Icons will be displayed when hovered over

Is it possible to display icons on hover in a div and hide them otherwise using just CSS? Or do I need to use javascript for this function? Thanks in advance! Example: HTML: <div id="text_entry"> <p>Some text here</p> <span ...

Using brackets in a CSS background-image URL will cause it to malfunction and not display the

Try using the brackets editor tool available here. I attempted to add an image to a div with the class "portrait" by linking the style.css file from index.html, but it doesn't seem to be working. Other guides and tutorials have successfully utilized ...

Error Encountered: Bootstrap Dropdown Menu Malfunction in Master Page

I'm struggling to make my Bootstrap drop down menu function properly. Nothing happens when I click on the link, no dropdown appears. I've set up my nav bar in a master page and have spent hours trying to troubleshoot it without success... This i ...

Is there a way to undo the transition when hovering out?

Is it possible to achieve a reverse transition animation on hover out using CSS? I want the "Menu" text to slide to the right blue line when I hover out, and after a delay of 400ms, slide back from the left grey line. Can this be done? .menu { displ ...

How to create a slideToggle effect for nested ul and li elements

Initially, everything was working fine until I put it through the W3C validator. After fixing the errors, now it's not functioning as expected. I have created a jsfiddle The setup involves nested ul elements being used as dropdowns, with headers tha ...

Is it possible that the font-family attribute is not passed down to the input fields within a

Do the html form input elements like text fields or select boxes automatically inherit the font-family property from the body? For instance: body { font-family: 'Lucida Casual', 'Comic Sans MS'; } The above font will not be applied t ...

Initiate an Ajax request solely for the elements currently visible on the screen

I am currently facing an issue that requires a solution. Within our template, there are multiple divs generated with the same classes. Each div contains a hidden input field with the ID of the linked target site. My task is to utilize this ID to make aja ...

Retrieve the site's title content using PHP

I created a code to scrape website content from platforms like Facebook and Google+. $html = file_get_contents_curl($url); if ($html) { //parsing begins here: $doc = new DOMDocument(); @$doc->loadHTML($html); $nodes = $doc ...

Transmit JSON Data via POST Method and Retrieve Using Node.js (Without the Use of Body Parser)

Can anyone help me with sending JSON data from HTML and receiving it in Node.js? I've been trying for hours and I'm getting frustrated. It seems like I'm close to a solution but no luck so far. In my VSCODE, the response is null (req.body = ...

What is the solution for incorporating multiple elements in knockout's applyBindingsToNode function?

I am currently using knockout applyBindingsToNode to dynamically add and remove elements in order to update my html. I need to cut the binding, which is why I am utilizing applyBindingsToNode. In an example I have provided, if you click on the button "Reb ...

Apache conf file configured with CSP not functioning properly when serving PHP files

While configuring the Apache CSP lockdown for a site, I encountered an unusual behavior when opening the same file as a PHP script compared to opening it as an HTML file. The HTML file looks like this: <html> <head> <meta http-equiv= ...

Looking for the optimal width ranges for media queries on laptops and cell phones?

Can anyone suggest the optimal width parameters to use in my code for different screen sizes, from tablets and laptops to cellphones, in order to create a responsive design? ...

My toggleclass function seems to be malfunctioning

I am encountering a strange issue with my jQuery script. It seems to work initially when I toggle between classes, but then requires an extra click every time I want to repeat the process. The classes switch as expected at first, but subsequent toggles req ...

What is the best way to generate an accordion populated with data from a MySQL query?

Everything is in order, I've got all the chapters and video series extracted without any issues: $id_course = 1; $stmt = $con->prepare("SELECT c.chapter, v.preview, v.title_video, ...

Determine the total by multiplying the value of a dropdown menu and a text input field using jQuery when the values are changed

I am new to jQuery and JavaScript. I have a textbox and a select box, and when I enter a value in the textbox and select a value from the select box, I want to display the multiplication of both values in another textbox. I have tried doing this with two t ...

How can you determine the class of an element that was clicked within an iframe?

Is it possible to retrieve the class of an element that is clicked within an iframe? Here is the HTML code: <input id="tag" type="text"> <iframe id="framer" src="SameDomainSamePort.html"></iframe> This is the JavaScript code: $(docum ...

How to load a URL into a div using jQuery and then update the div with new content?

I have a codeigniter view that I want to load into a div as an iframe using the following code: <script type='text/javascript'> $(document).ready(function (){ $('#divId').load('http://www.domain.oo/page.php?test=1); }); ...

Adjust the size of my navigation bar to match the dimensions of the browser

I'm currently facing an issue with my website's navigation menu on mobile devices. I've been attempting various solutions to make the navigator scale up appropriately with the browser, but so far nothing seems to be working. Below is the HT ...