Dynamic div that automatically adjusts its height ratio to fit its parent container

Imagine you have two divs (A) and (B). The parent div (A) has a height: auto and so does the child div (B). Is there a way, without using JavaScript, to make div (B) always occupy 90% of the height of div (A)? Any insights or suggestions would be greatly appreciated.

UPDATE I forgot to mention that I need the inner div to expand as more content is added. While the child expands, I want the parent div to also grow but maintain a consistent distance from the inner div.

Answer №1

It seems unlikely to achieve without the use of JavaScript

Assuming div (A) contains text and has a specific height, represented as x. If another div (B) is set to have a height of y, where y == x*0.9, then div (A) would no longer accommodate div (B) because its height should now be x+x*0.9. This presents a circular issue from my perspective.

Edit: To maintain 90% proportions using just CSS, assuming both div A and div B are parent elements to other divs rather than having a parent-child relationship (height:300px and widths are arbitrary in this example):

<!--
    a = 0.52631579, b = 0.47368421
    a + b = 1.0
    b/a = 0.9 (roughly)
-->
<div style="background:#f00; width:150px; height:300px;">
    <div id="divA" style="background:#0f0; width:100px; height:52.631579%"></div>
    <div id="divB" style="background:#00f; width:100px; height:47.368421%"></div>
</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

What could be the reason my IE6 Conditional stylesheet is not functioning properly?

It's as if my brain is going in circles. I'm attempting to utilize a conditional stylesheet specifically for IE6. You can see the test page here. This snippet of code was placed within the head tags: <!--[if IE 6]> <link rel="stylesheet ...

Utilizing CSS3 Animation for enhanced hover effects

I have a setup with two divs. One of the divs expands in height when I hover over it. What I'm trying to achieve is to display text with a fade-in effect somewhere on the screen when I hover over that specific div. Additionally, I want to show another ...

Modify the appearance of a card upon radio button selection

Can someone help me figure out how to change the background color of my card element when a radio button is selected? <div class="col-6 col-md-3 mt-4 text-center my-auto"> <label for="'.$abreviation.'"> ...

The border is not properly containing the element within

I've been struggling to create a menu with no luck. My goal is to add a border to all my li elements, but the border consistently appears only at the bottom. Is there a way to make the border wrap around the entire li element? Check out my code here: ...

Display HTML content from a JSON array with the help of ng-bind-html

I am looking to display HTML tags stored in a JSON object property within a modal window. Below is an example of the JSON object: { "fileUploadCategories": [ { "id": "Bread", "title": "GrandmaBread", "info": "Some info text.", "restService": "emp ...

Output MySQL information into an HTML form with radio buttons and an additional text field

Users are able to input product data into a MySQL database through my web form. They can choose between three main suppliers using radio buttons (Sigma-Aldrich, VWR, and Filter-Service), or select 'other' and specify a different supplier in a tex ...

Maintaining header and footer while calling a PHP form on the same page

I have a straightforward PHP form, named home.php, that submits to itself: <form action="home.php" method="post" enctype="multipart/form-data" id="AddImageForm"> The issue arises when home.php is accessed from the index.php file (located below). Up ...

Can you tell me why one of these Sass codes is throwing an invalid CSS error while the other is not?

My code: @for $j from 1 to 6 { .text-#($j) { font-size: 15px * $j; } } I'm facing an issue where my code doesn't run as expected. In an attempt to fix this, I modified it to use a 'through' keyword instead of 'to' in the loop ...

How can we generate a intricate polygonal figure using an image in CSS that can be utilized in the regions property?

I'm on a mission to transform black images into polygon shapes. The challenge at hand involves two key steps: Converting an image into a polygon Filling the polygon with text I'm currently stuck on the first step. Without any existing convert ...

Using CSS, eliminate the drop-down menu from the main navigation on Squarespace

While working on my Squarespace website, I've been impressed with how the FAQ page/questions are structured. However, a drawback is that it creates a clunky drop-down menu when hovering over the FAQ tab in the main navigation. You can see an example ...

Resizable divs with flexible padding

I've been struggling to find an efficient method for creating modular containers in my stylesheet without defining a set width. My goal is to have classes like width25, width33, width50, and width100 to adjust the container's width according to d ...

Choose or deselect images from a selection

I am currently working on a feature for an album creation tool where users can select photos from a pool of images and assign them to a specific folder. However, I'm facing difficulty in selecting individual photos and applying customized attributes t ...

What is the best way to transform this unfamiliar CSS element into JavaScript code?

I'm facing an issue where I want to animate a CSS image based on time constraints, but since it's in CSS, I'm unable to achieve the desired effect. The animation in question is not the sun itself, but rather a yellowish half-circle animation ...

Load Image Timing Discrepancy in Web Development (jQuery/PHP/HTML)

I am currently using jQuery to develop a basic slideshow feature. Within my home.php file, I have created a slideshow. Additionally, there is a menubar that allows users to navigate to different pages. Upon clicking on "Home" in the menu, the home.php con ...

Organize your table with CSS styling

Looking for a way to rearrange a table with 2 columns after every 2 rows so that the lines continue on the right side? Check out the example below: [1][2] [1][2][5][6] [3][4] => [3][4][7][8] [5][6] [7][8] Wondering if this can be achieved using o ...

Updating the subject line in Outlook emails

Can you change the subject of an email that someone receives in Outlook? I believe it might be possible. Perhaps similar to how user agents are used for browsers? I'm fairly new to emails and my online searches have not been helpful despite spending ...

What is the process for adding text before and after a Bootstrap progress bar?

I want to customize the bootstrap progress bar with text at the beginning and end, like this: 5 star ----------------------------------------------- 70% Here is my attempt to achieve this: <link rel="stylesheet" href="https ...

Tips for utilizing jQuery or AJAX to automatically update a div every 10 seconds

Seeking assistance from fellow developers. Working on a PHP web app utilizing the Yii MVC framework and its array of tools. Specifically, I am looking to dynamically refresh a div every 10 seconds. Currently, my Ajax function looks like this: <script t ...

Sliding Up Transition Effect for Footer with JQuery or CSS3

I am attempting to replicate a sleek slide up footer that caught my eye on The Internship Movie Site. I have created the wireframe layout, but I am struggling to figure out the correct CSS transition effect. Although I have experimented with the "top" and ...

Steps for implementing a select all feature with jQuery

I'm currently working on a jQuery function that is acting as a select-all option. Everything is functioning correctly except that when I deselect any of the child elements from select all, the option remains enabled. My goal is to enable or disable th ...