Resizable jQuery DIV containing dynamic content with a child element set to 100% height and width

I am facing an issue with a DIV containing dynamic content and resize function.
You can see an example here -> http://jsfiddle.net/UsRuh/4/

The problem arises with the dynamic content.
Example -> http://jsfiddle.net/UsRuh/5/

The solution seems to be setting higher padding for the #main DIV.
Example -> http://jsfiddle.net/UsRuh/6/


Is there a way to resolve this issue using only CSS, without involving JavaScript?

CSS

#header {
    background-color:#faf; }

#main {
    position: absolute; top: 18px; left: 18px; width: 384px; height: 157px;
    padding:0px 0px 80px 0px;
    position: absolute;
    overflow:hidden;}

#scrollDiv {
    background-color:#ccaacc;
    height: 100%;
    overflow-y: scroll;
    overflow-x: hidden;
    padding-right: 25px;
    width: 100%; }

HTML

<div id="main">

    <div id="header">Head</div>

    <div style="background-color:#555;"> some dynamic content text text text text <br /> some dynamic content</div>

    <div id="scrollDiv"> some dynamic content width "invisible" scroll<br />text text text text text text text text text text text text text text text text text text text text text text text text text text text text .... ext text </div>

    <div style="background-color:#555;"> some dynamic content text text text text <br /> some dynamic content</div>

</div>


EDIT: If there are no other solutions available, please inform me.

Answer №1

Unfortunately, there are no CSS-only solutions that work across all browsers.

One workaround is to use extra wrappers and apply display: table + display: table-row, like demonstrated in this example: http://jsfiddle.net/kizu/UsRuh/28/

The main issue lies with Internet Explorer - versions 6 and 7 do not support the table values of the display property.

To address this problem with IE, you can either use expressions (which essentially require JS) or resort to using unsemantic tables instead of divs, ensuring compatibility everywhere.

In the past, table layout was often the go-to solution due to its versatility. However, moving forward, the flexible box model offers a more modern and CSS-centric approach. You can experiment with this technique here: http://jsfiddle.net/kizu/UsRuh/29/

This is where the flexible box model shines, aiming to provide a pure CSS solution for various layouts. Nonetheless, its support across different browsers is still a work in progress.

Answer №2

To ensure that a div with dynamic content below a scrollable div snaps to the bottom, use absolute positioning. Just make sure the parent div (#main) has either relative or absolute positioning.

Answer №3

I just made a small adjustment to the CSS, and you can view it here: http://jsfiddle.net/KuzTB/

In my latest update, I integrated a CSS3 pseudo-class: nth-child(n) and implemented it on the final inner 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

Utilizing CSS for modifying spacing within a span element

I am facing a challenge with displaying a full name (firstName lastName) on a webpage. Within my JSP file, the code snippet looks like this: <span> <c:if test="${someCondition1}"> <c:out value="${firstName}"> </c:if&g ...

When the Button is clicked, scroll the element to the top position

I want to include an "ADD COMMENT" button on my page. When clicked, a form will be displayed for users to add comments. I would like the form to automatically scroll to the top position of the page so that users do not have to manually scroll down to vie ...

Rotating and spinning images with HTML/CSS while also adding an ease-out effect

After experimenting with numerous CSS snippets, I found that none fulfill all my requirements. Here's what I'm aiming to achieve within the function myspin(x){}: 1.) Rotate image x degrees invisibly on click 2.) Then smoothly animate a spin o ...

Creating videos for banners

So I have a website at this URL: My goal is to achieve the following: I want the video to play in the banner and adjust the Iframe size based on the user's device resolution I want the video to autoplay I want the logo, text, & button to be dis ...

Incorporate h:outputText into your JavaScript code segment

After populating some information into a h:outputText, I am now looking to trigger a JavaScript function upon clicking a button that will retrieve the text from the outputText. The structure of the code is as follows: <p:tabView id="tabView"> & ...

Place small images onto a background image using drag and drop

I'm a beginner with jQuery and I'm looking to implement image dragging functionality on my website. Specifically, I have a base image where I want to be able to drag and drop smaller images onto it. Can anyone recommend any plugins or provide gui ...

How can I customize the hover effect of the drop-down options <option> to have a "blue" background color?

I've been struggling to change the default blue background color of the drop-down options when hovering over them with the mouse. Despite trying various solutions from this forum, nothing seems to be working at the moment. (These solutions used to wor ...

I've been attempting to upload application/pdf files, but I'm having trouble. Can you provide me with instructions

'<?php $allowedExts = array("jpg", "jpeg", "gif", "png"); $extension = end(explode(".", $_FILES["file"]["name"])); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/ ...

How to eliminate excess white space on the right side in Bootstrap 4

Could someone please clarify why I am experiencing a white space on the right side when using Bootstrap 4? This is the primary code block for the page. <main id="intro" role="intro" class="inner text-center"> <h2>Lorem Ipsum</h2> ...

Utilizing modular structure for efficient jQuery AJAX request

Seeking guidance on optimizing multiple GET ajax calls, where each function contains repeated $.ajax({}) code lines. Is it feasible to create a single $.ajax({}) function and utilize it in all functions instead of duplicating the code? Perhaps something ...

Is there a way to deactivate a clickable div immediately after it has been clicked on?

I have been searching for a solution to this particular question on different platforms, including Stack Overflow. However, I am looking for an answer using pure JavaScript only, so please avoid jQuery solutions. In order to provide context, I have includ ...

Enhancing Option Element Height with Padding in Bootstrap 5

Is there a way to adjust the height or increase padding of the option element within a standard select box using Bootstrap 5? More information can be found at: https://getbootstrap.com/docs/5.0/forms/select/ Could you provide an example code to demonstrat ...

Is there a quicker alternative to jQuery's .load() method?

My JSP index page features a navigation header and notifications panel, with other JSP pages being loaded into a specified div using JQuery.load(). This method was utilized to prevent the duplication of navigation and notifications across all pages. Wou ...

I'm interested in creating a unique sidebar layout with Bootstrap 5 - how can

I'm struggling with creating a sidebar for my application and need guidance on using col to organize content into left, right, and center. Here is my navbar: <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <div class=&quo ...

Building custom components in Vue.js/NuxtJS can be a breeze when using a default design that can be easily customized through a JSON configuration

Currently, I am in the process of developing a NuxtJS website where the pages and components can either have a generic design by default or be customizable based on client specifications provided in the URL. The URL structure is as follows: http://localh ...

Switch up the CSS variable within an embedded iframe

I'm in a predicament with a specific issue. I am currently utilizing Angular to incorporate an Iframe. Let's imagine the angular app as A and the Iframe as B. B is being loaded within A. Within B, I have utilized CSS variables to define colors. I ...

Checkbox selected triggers the addition of a textbox

I have a requirement where I need to have two checkboxes (choice_0 and choice_1). The user should be able to select one or both, which will then add a textbox next to each checkbox. However, the issue arises when enabling one checkbox and then attempting t ...

What methods does Google use to display its search results on the search engine results page?

Upon first observation, I realized that the search results were not present in the HTML received from the server. To investigate further, I turned to Dev Tools and examined the additional files downloaded by my browser. I discovered that there was only on ...

What is the process for sending an array to the Post method using this.collection.create in Backbone?

I am currently incorporating backbone.js into my MVC application, and I have encountered a situation where I need to pass an array to the Post method in my Rest API. To achieve this, I am attempting to set an array property in my model and then call this.c ...

The Navigation Bar is positioned too distant towards the Right side

Update: The issue has been resolved. Thank you for the assistance. I'm facing a problem with my navigation bar on my website. I can't seem to get it to span the entire width of the page while staying centered. The navigation bar is sticky and fu ...