Create a div that can grow in size without the need to set a specific height for it

Here is an example of my HTML code:

<div id="wrapper" class='common'>
    <div id="left" class='common'>Menu I Menu II Menu III Menu IV</div>
    <div id="right" class='common'>hello world..hello world..hello world..
      hello world..hello world..hello world..hello world..hello world..hello world..
      hello world..hello world..hello world..hello world..hello world..hello world..
      hello world..hello world..hello world..hello world..hello world..hello world..
      hello world..hello world..hello world..hello world..hello world..hello world..
      hello world..hello world..
    </div>
</div>

This is the CSS for the above HTML:

#wrapper {
    overflow:hidden;
    padding:3px;
}
#right {
    float:right;
    width:70%;
}
#left {
    float:left;
    width:29%;
}
.common {
    border:solid 1px #000;
}

If you want to see a live demo, click here.

I am facing difficulty in making the div with id "left" expand based on the content of the div with id "right." Can anyone provide some hints or help me troubleshoot this issue?

Answer №1

To achieve this effect using only CSS, the best approach is to utilize the display:table* property to define #left and #right as sibling columns. By setting them as display:table-cell, they will automatically adjust to the same height. Just keep in mind that you'll need an additional wrapping div to create a structure like display:table > display:table-row > display: table-cell.

You can view a working example on jsfiddle here: http://jsfiddle.net/QDh59/

Answer №2

One effective solution is utilizing the height: property alongside absolute positioning.

See it in action here

Answer №4

Take a look at this helpful response

In my opinion, achieving independent expansion for 2 divs without a wrapper can be quite challenging, unlike what you may have seen in the provided links.

There are various techniques such as utilizing Faux Columns that can assist in achieving the desired outcome, alongside several other methods.

Some options include:

Faux Columns and CSS Table

Or using Jquery:

Equalize Heights of Divs

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

Guide to make a loading animation button through the use of HTML, CSS, and JavaScript

"Hello, I am currently in the process of working on a project and am interested in implementing a button with a loading animation that can be displayed during actions like form submission or content loading. I'm seeking some advice or code sample ...

Deactivate a specific button within a row on a Primeng table by clicking on it

I'm trying to modify my primeng table so that each row has a button, and when I click on a button, only that specific button should be disabled. However, in my current code, all buttons are getting disabled with a single click. Can someone please help ...

Creating a simple bootstrap code for developing plugins in Wordpress

After successfully coding in Brackets with the Theseus plugin on my local machine, I encountered a problem when attempting to transfer my code to a Wordpress installation. The transition from Brackets to Wordpress seems far more complicated than expected. ...

Endless cycle of invoking functions in Angular.js

Issue with the template : <div class="container"> <h1>Process Definitions</h1> <table class="table table-stripped" > <tr> <td><strong>Name</strong></td> <td><strong>Id</st ...

The Owl carousel animation fails to work in Chrome browser

I am currently customizing an HTML5 template that utilizes the Owl Carousel 1.3.2. My goal is to incorporate a smooth fade animation when transitioning between slider images. The code snippet below works perfectly in the Mozilla Browser, however, I'm ...

Tips for locating direct children of a non-root element using CSS selectors in Selenium

When working with a <table> element, I encountered the need to search for its descendants and direct descendants while avoiding wading through nested tables. The elements I seek lack reasonable IDs, so specific selectors are essential: <html> ...

Having trouble with the Bootstrap 5 modal in the initial template?

I'm encountering an issue with setting up a basic modal using the Bootstrap 5 starter template paired with the Bootstrap Bundle including Popper. Despite reviewing similar problems on other platforms, none of the solutions seem to resolve my specific ...

Styling a Form Submission with CSS

I am currently working on a website that contains the following PHP code: echo "<form action='choice.php' method='post'>"; echo "<input type='submit' name='choice' value='left' /> "; As I am i ...

The interaction between background-size: cover and background-position

I wanted to experiment with setting background-size: cover and testing out different background positions. Feel free to check out the live fiddle for a hands-on experience. HTML <div id="container"> </div> CSS #container { backgro ...

Verify the presence of both class and id before modifying the content of the h1 tag and automatically redirecting the page

I'm encountering some issues triggering my JS/JQ on an HTML5 page. Essentially, I want to verify the existence of the following ID and class: ID: page_blog CLASS: page current <section class="page current" id="page_blog" style="z-index: 99; lef ...

Accessing the value of a hidden field within an ng-repeat loop when binding to an HTML table

I am working on a project where I have an HTML table with data being bound from AngularJS. The structure looks something like this: <tr ng-repeat="item in List| filter: { MachineType: 'Physical' }"> <td>{{item.MachineType}}< ...

The session becomes obsolete when redirecting back to the previous page

When attempting to redirect using the http referrer after storing a value in Session in php, I noticed that the Session becomes null. Is there a method to maintain the session even when utilizing the http referrer? ...

Adjust the size at the location of the cursor

I am having trouble understanding how to implement zoom based on mouse position using this example here: (https://stackblitz.com/edit/js-fxnmkm?file=index.js) let node, scale = 1, posX = 0, posY = 0, node = document.querySelector('.f ...

After upgrading from Windows 7 to Windows 10, I noticed that the CSS, HTML, and Bootstrap elements seemed to have lost their impact

<!DOCTYPE html> <html> <head> <title>Registration</title> <link rel="stylesheet" type="text/css" href="styles.css"> <link rel="stylesheet" type="text/css" href="bootstrap.css"> <link href ...

Use the no-repeat feature to set the background image in an Asp:Chart

I have been working with the asp:Chart control and have found that its BackImage property functions well. However, I have encountered two issues while trying to set the background image. I am unable to successfully set the no-repeat property of the Bac ...

retrieving data from a php file using ajax for a post request

Utilizing ajax, I have invoked the page search.php: function search(){ var title=$("#search").val(); if(title!=""){ $.ajax({ type:"post", url:"sear ...

The ng-route feature seems to be malfunctioning and I am unable to identify the error, as no information is being displayed in the console

Here is the code in my boot.php file where I have set up the links <ul class="nav nav-pills nav-stacked"> <li role="presentation"><a href="#/valley">Valley</a></li> <li role="presentation"><a href="#/beach"> ...

When updating the HTML content, JavaScript is outputting the code as text instead of running it

I am encountering an issue with adding the body content of a JSON file, which contains HTML code, to my existing HTML. Instead of executing the code, it appears as text within paragraph or header elements. I have searched through various discussions but ha ...

What is the process for extracting HTML code from a website and converting it into a string for use in VB?

Storing the page source in the variable HTML is known to me. Dim Client As New WebClient URL = Console.Readline HTML = Client.DownloadString(New Uri(URL)) However, it has been observed that not all elements from a website are saved using this method. For ...

Expand and Collapse Button for Customizing Table Height Individually

I trust everything is going smoothly. A challenge I'm facing involves implementing a button to expand a specific row within a table. Currently, clicking the "show more/show less" button extends all rows when the goal is to do it for each individual ta ...