Ensure that the div expands to accommodate the content

I'm experiencing an issue where the content within a div with a blue border exceeds the boundaries of the div when it expands. How can I make sure that the div extends to contain all the content?

Here is a demonstration of the problem: When I expand the collapsible section, it overflows the nice blue border. Is there a way to extend the div to fit?

One potential solution I have considered is using display:table-cell, but this might interfere with other formatting.

.page {
    margin-top: 2%;
    height: 100px;
    min-height: 88%;
    box-shadow: 3px 3px 5px 6px #240ACF;
    margin-bottom: 70px;
    background-color: #fffbf9
}

.container {
    position: relative;
    float: right;
    width: 590px;
    height: inherit
}

.accordion .content {
    overflow-y: hidden;
    height: 0;
    transition: height 0.3s ease;
}

.accordion>input[type="checkbox"]:checked~.content {
    height: auto;
    overflow: visible;
}
<div class="page">
    <div class="container" >
        <section class="accordion">
            <input type="checkbox" name="collapse2" id="handle2">
            <h2 class="handle ">
                <label for="handle2">Click Here</label>
            </h2>
            <div class="content">
                <p>a<br>a<br>a<br>a...</p> /* Content continues here */
            </div>
        </section>
    </div>
</div>

Edit.: Simplified example provided.

Answer №1

To improve the layout, consider removing any explicit height definitions for the element with the class .page. Instead, focus on setting a minimum height and ensuring that content does not escape its container when using a floated element like float: right. There are several ways to achieve this, such as applying .page { display: table; } or .page { overflow: hidden; }.

Answer №2

.page {margin-top: 2%;box-shadow: 3px 3px 5px 6px #240ACF;margin-bottom: 70px;background-color: #fffbf9}.container {position: relative;width: 590px;height: inherit}.accordion .content {overflow-y: hidden;height: 0;transition: height 0.3s ease;}.accordion>input[type="checkbox"]:checked~.content {height: auto;overflow: visible;}

<div class="page">
<div class="container" >
    <section class="accordion">
        <input type="checkbox" name="collapse2" id="handle2">
        <h2 class="handle ">
            <label for="handle2">Click Here</label>
        </h2>
        <div class="content">
            <p>a<br>a (repeated multiple times to fill up space)</p>
        </div>
    </section>
</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

A fragmented rendering of a gallery featuring a CSS dropdown menu

Hey there! I'm a newbie coder seeking some assistance. Recently, I stumbled upon a tutorial online that taught me how to create a drop-down menu. However, whenever I hover over "Gallery" on my website, things go haywire and the layout gets all messed ...

The placeholder attribute for input types does not display consistently across all browsers

I am experiencing an issue with the placeholder text in my input field. <input type="text" name='linkLabel{{index}}' autocomplete="off" class="input-large tight-form-url last remove-cross" required="required" placeholder="{{'linkLabel&ap ...

"Utilize Angular's functionality to include labels for checkboxes generated using *ngFor directive

I am currently working with Angular 5 My goal is to generate multiple checkboxes using the code below and provide them with labels <input type="checkbox" *ngFor = "let v of options[0].options" [value]="1" [name] = "1"> Typically, when working with ...

"Can you guide me on how to display a React component in a

I have a function that loops through some promises and updates the state like this: }).then((future_data) => { this.setState({future_data: future_data}); console.log(this.state.future_data, 'tsf'); }); This outputs an array o ...

What is the process for retrieving the value of a text box using V-Model?

Link to the code snippet <td><input class="input" v-model="user.name" /></td> After accessing the provided link, I noticed a unique input textbox. Is there a way to extract specific text values like a,b,c from this te ...

Embed the aspx file within the background-image attribute similar to how an image source is

Within my asp.net application, there is an image tag linking to another aspx file in the src attribute, displaying a picture. <img src="/picture.aspx?Param=3" alt="picture"/> I need to convert the image tag into a div with a background-image proper ...

Executing an SQL delete query with a button click using a JavaScript function in PHP

I have created a setup with three essential files - index.html, database.php, and function.js. In database.php, there is a form generated containing a delete button that triggers the deletion SQL query when clicked. The primary objective is to present a ta ...

Non Rectangular Header with Bootstrap's Responsive Navbar

Currently, I'm in the process of developing a website and I've been pondering if it's feasible to design a bootstrap navbar with a uniquely shaped header as a background. I envision the header to resemble something like this: https://i.sst ...

Embedding CSS stylesheets in a Django template

I'm currently working on a large Django website and in the process of adding the HTML templates. Here is the file tree for the main part: C:. +---forums | | admin.py etc | | | +---migrations | | | ... | | | +---templa ...

Problem with structuring a Html5 web page

Recently, I created a web page using HTML5. Check out the code below: <header> <img src="img/logo.png" alt="logo"> <hr class="hr-style"> <h1>The Articles</h1> <nav> <ul> <li><a href="#" ...

Unable to save the user's identification in the session

I am in the process of retrieving the user ID of a logged-in user and storing it in the session. This way, when a user submits something, I can include their user ID in the submission to the database. My login page is quite rudimentary, so any guidance wou ...

CSS Switchable Style Feature

I am in need of some assistance with the navigation on my website. You can find the current code at this link: http://jsfiddle.net/Sharon_J/cf2bm0vs/ Currently, when you click on the 'Plus' sign, the submenus under that category are displayed bu ...

Implementing CSS styles with jQuery

Looking for a way to dynamically add CSS attributes to different form elements like text fields, text areas, checkboxes, and dropdowns? There's also a separate block that lists possible CSS properties such as font, font-style, width, and padding. What ...

Website Navigation Bar Template

Can someone assist me, please? I've been working on this project for a few hours now. As a beginner in html and css, I've been doing extensive research but haven't found a solution that works perfectly for my needs. The only thing that some ...

Issue with opening mobile app from deep link in HTML email

My HTML form contains a deeplink that is submitted through the SendGrid API on nodeJS. After sending the email, users can view it but are unable to click on the deeplink. <!DOCTYPE html> <html> <head> ...

Browsing a container with JavaScript

I am attempting to display one div at a time and scroll through them repeatedly. I found and modified a Fiddle that works as intended, but when I try to implement it on my own test page, the divs do not scroll as expected. Here is the Fiddle example: http ...

After incorporating some movement effects into my menu, suddenly none of the buttons were responding

While working on my website and trying to add a close menu button, I encountered an issue where all the menu buttons stopped functioning. Here is the HTML code snippet: <div id="openMenuButton"> <span style= "font-size:30px;cu ...

Two entities positioned on opposite extremes

Is there a way to design a div with two elements (text and image) positioned on opposite sides? The length of the text varies as it's a list of months for selection. Ideally, the text should appear on the left side of the div as a "p" element, while t ...

Group a set of x elements together within a div, and then group a distinct number of elements together after every x-grouping

Is there a way to achieve a looping structure like this? For instance: Group every 2 divs into a new div, then (after every 2nd grouping) group every 3 divs together <div id="container"> <div></div> <div></div> ... </div& ...

The <hr> tag is not displaying properly within the <option> element

I'm facing an issue with a selection element in my Vue project <div class="resultContainer"> <section> <option class="resultBtn" v-for="exchange in finalExchanges"> {{exchange}} <hr></option> </section> ...