Unable to stretch div despite having content within

I have encountered a problem with my containing div not growing with the content, despite trying various solutions such as using 'clear'. It seems that even when I apply 'clear' to different elements below, the parent div refuses to expand. Any assistance on this issue would be greatly appreciated.

View Image of problem:

For a live example please visit,

---------------CSS----------------

 .product {
   width:775px;
   margin:0;    
   padding:0;
   margin-top:75px;
   margin-left:-8px;

 }
 .product ol{
   margin:0px;
 }
 .product li{
   list-style:none;
   margin: 0 0 15px 0;
   padding:15px;    
   border:1px solid #ccc;
   height:100px;
   color:#000;
 }
 .product-column-left{
   float:left;
   width:100px;
   height:100px;
 }
 .product-column-right{
   float:left;
   width:120px;
   border-left:1px solid #ccc;
   height:100px;
   text-align:center;
 }
 .product-column-center{
   float:left;
   width:470px;
   min-height:100px;
   padding-right:15px;
   padding-left:15px;
   text-align:left;
   padding-bottom:30px;
   display:block;

 }
 .product h2{
   font-size:18px;  
   margin-bottom:5px;
   margin-top:0;
 }
 .product .text-underline{
   text-decoration:underline;   
 }
 .description-text{
   font-size:12px;
   color: #000;
 }
 .clear{
   clear:both;  
 }

--------------------------HTML--------------------------

<li style="list-style:none;">

<div style="width:750px;" >

     <div class="product-column-left">

        <img align="left" style="border:0;" src="images/hop-pellets.png" width="100" height="100" />

     </div>

  <div class="product-column-center"  >

        <h2><span class="hop-title-text-product">Columbus, Tomahawk and Zeus</span></h2>

        <div class="description-text" >Proprietary naming rights sometimes have identical or nearly identical strains being sold under multiple names. Columbus, Tomahawk and Zeus, or the CTZ hops, are the most famous example of this phenomenon. CTZ hops are known as super-alpha hops due to the extremely high percentage of alpha acids they contain, making them ideal bittering additions. Columbus hops can be found alongside Centennial hops in Stone Ruination IPA or in Saranac's Brown Ale.

Proprietary naming rights sometimes have identical or nearly identical strains being sold under multiple names. Columbus, Tomahawk and Zeus, or the CTZ hops, are the most famous example of this phenomenon. CTZ hops are known as super-alpha hops due to the extremely high percentage of alpha acids they contain, making them ideal bittering additions. Columbus hops can be found alongside Centennial hops in Stone Ruination IPA or in Saranac's Brown Ale.

         </div>

         <div class="product-column-right">

            <h2>$0.00</h2>

            <a href="index.php?cart=1&pid=49"><img style="margin-top:10px; border:0;" type="image"src="images/add-to-cart-button.png" width="90" height="25" /></a>

         </div>

    </div>

</li>

</ol>

</div>

Answer №1

Consider adding overflow hidden to the parent li

.product li { 
    .... 
    overflow: hidden;

    /*height: 100px;*/
  }

An issue with using overflow:hidden is that it may hide overflowing elements in your layout. To address this, you can use a clearfix class as shown below.

.clearfix:after {
   content: " "; /* Older browser do not support empty content */
   visibility: hidden;
   display: block;
   height: 0;
   clear: both;
}

To implement this, simply add the clearfix class to your container elements. Learn more about Clearfix here.

<li class="clearfix">
    <div style="float: left;">        
        <div class="content">Big content</div>    
    </div>
</li>

Check out the demo on JSFiddle here.

Answer №2

To resolve the issue, consider implementing a clearfix in your code:

.clear-fix{width: 100%; clear: both; height: 0px; line-height:0px;}

<div class='clear-fix'></div>

Answer №3

.clearfix{width: 100%; clear: both; height: 0px; line-height:0px;}

<div class='clearfix'></div>

To ensure that the div spans the content, remember to add the above div at the very end of your container div (probably after product-column-right) and just before your closing li tag.

Answer №4

The height of your product.li style is currently set to 100px, which means it will limit the size of the box. To fix this, you should remove that setting or change it to height:auto. Additionally, add an empty clear div right before the closing li tag and everything should display properly.

To update your CSS definition:

 .product li{
   list-style:none;
   margin: 0 0 15px 0;
   padding:15px;    
   border:1px solid #ccc;
   height:auto;
   color:#000;
 }

Make sure your HTML code looks like this:

<a href="index.php?cart=1&pid=49"><img style="margin-top:10px; border:0;" type="image" src="images/add-to-cart-button.png" width="90" height="25" /></a>

         </div>

    </div>
    <div style="clear:both"></div>
</li>

</ol>

</div>

Answer №5

After utilizing overflow: for an extended period and encountering some issues, I made the decision to revert back to this clear fix method. If you are experiencing any difficulties, be sure to give it a try.

http://css-tricks.com/snippets/css/clear-fix/

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

Updating Icons in HTML Using Local Storage and Implementing a Dark Mode Feature Using JavaScript

My latest project involved creating a dark mode button along with a custom dark theme. The theme is stored in Local Storage to ensure consistency. However, I have encountered an issue where, upon page reload, the site remains in dark mode but the button ic ...

Is it possible to apply a gradient to a table row in Internet Explorer?

Whenever I hover over a specific table row in my table, I want the background to transition to a linear gradient. The CSS code is pretty simple: tbody.row-links tr:hover { background: ...standard multi-browser linear gradient code... color: #333C3 ...

Trouble with Leafletjs Routing Machine collapse button loading issue

In my project, I am using django 1.10.5, booststrap 4.0, and LeafletJs 1.0.3 along with the routing machine plugin and geocoder. However, I have encountered an issue where the collapse button of the control panel for the routing machine does not appear (it ...

Show a pair of pictures every X hours using Javascript

Trying to create a code that displays different pairs of images each day, but struggling to make it select them randomly. Instead, the code currently just goes through the array one by one. I'm not great with Javascript and haven't found a way to ...

"Enhancing User Interaction: The Dynamic Trio of Ajax, Php, and MySql in Comment

I have successfully developed a basic commenting system, featuring a form with two fields: name and comment. Upon submitting the values, it utilizes Ajax to dynamically add the comment to the existing page without refreshing the entire content. My next ob ...

Can someone explain why the color of a <select> element in Chrome is being influenced by the CSS property "font-family: inherit"? Here is an example

I've always been curious as to why the <select> element appears in different colors on various web pages. I've noticed that when the font-family:inherit css property affects the select element, it ends up looking blue! <!-- BLACK --> ...

Struggles with conflicting versions of Jquery within asp.net

Here is a snippet of my jQuery function: $(window).scroll(function () { if ($(window).scrollTop() > offset.top) { $("#sidebar").css("marginTop", $(window).scrollTop.length - offset.top); $("#sidebar").css({ o ...

What is the best way to access the value of an HTML tag in React?

Currently in the process of developing a feature for the price tab using React. These components are designed to allow users to add price classes to their shopping cart. One challenge I'm facing is how to retrieve the HTML string of an HTML tag. Here& ...

Animated image inside clickable element (HTML, CSS)

Is there a method to embed a gif within a button and have it activate on hover? ...

Elements that allow for asynchronous data submission without requiring a traditional submit button

Hey there, I could really use some help with this puzzle I'm trying to solve. Here's the situation: <ul> <li>Number: <span id="Number">123</span></li> </ul> I want to set up a connection between t ...

CSS styling for positioning a dropdown submenu

My website is experiencing issues with the CSS sub menus, specifically the last two sub menus are extending off the screen. https://i.sstatic.net/SKhuN.png I am looking for a solution to maintain the correct position of these sub menus. The code contains ...

How to Build a Custom Toolbar with Left and Right Aligned Elements using React.js and Material UI

Struggling with updating the toolbar on my website. Wanting the site name and logo on the left side, while login/sign-up buttons fixed to the right. Logo and title are in place, but can't get buttons to stay on right margin. Here's the code: func ...

The form does not support inserting all values through AJAX. We may need to implement a QUERY to handle this

Can someone help me find the issue in my code? I have checked the back end and can't seem to identify the logic error. The form submission shows as successful but does not insert the values into the database. I'm still learning how to use ajax, s ...

Words displayed on an image, perfectly aligned in the center

Check out this fiddle: http://jsfiddle.net/WdZeC/ <div class="text_align_center" style="text-align: center;"> <div style="position: relative;"> <img width="27" height="28" src="http://www.kavoir.com/img/text-over-image.jpg"> ...

The W3C validator verifies the cached iteration of the website

Click here The most recent error is on Line 420, Column 42: Found a stray start tag script. <script src="/skin/sayan_health/js/nc.js"></script> However, I managed to fix this error by placing the script tag inside the body tag. When I inspec ...

What is the best way to modify React state?

Can someone help me troubleshoot an issue with toggling React state after a button click? I want to be able to change "Work From Office" to "Work From Home" and vice versa, but it's only working once. Is there a way to achieve this using an if stateme ...

2-panel accordion interface

Hello there, I've encountered a problem that seems to be related to CSS. Here is the project I'm currently working on: My main focus is on the News accordion menu. The goal is to display a small image (50x50 with padding) next to a large headlin ...

Utilizing jQuery to incorporate two datepickers for two separate fields (field 1 and field 2 with the second date being one day ahead), similar

How are you feeling? I am currently working with two datepickers, each associated with its own field. My goal is for the user to automatically select (From) and have the second field (TO) display the following day, similar to how it works on booking.com. ...

How can you implement code that responds differently based on whether the user clicks the OK, cancel, or close button in a confirm dialog

What are three buttons in a confirm dialog box? How can JavaScript be used to perform different actions when the "ok" and "cancel" buttons are clicked, without performing any action when the dialog box is closed? ...

Position div elements randomly on the webpage when it first loads

I am trying to achieve a set of divs that will appear randomly on the page when it loads. Currently, I have the divs moving around the viewport in a random manner, but they all seem to load in the top left corner. This is the method I am currently using: ...