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

unable to see the new component in the display

Within my app component class, I am attempting to integrate a new component. I have added the selector of this new component to the main class template. `import {CountryCapitalComponent} from "./app.country"; @Component({ selector: 'app-roo ...

What is the best way to combine a custom CSS class and a bootstrap class to style an element in next.js?

In the following example, the CSS class is imported and then applied to the element: import customStyles from "./Home.module.css"; <div className={(customStyles.collection, "card")}> Although they work individually, when combined as shown above, t ...

Can one utilize HTML's .querySelector() method to target elements by xlink attribute within an SVG document?

Here is the scenario: <body> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <a xlink:href="url"></a> </svg> </body> Now, can you utilize the HTML DOM's .querySe ...

Styling code for a layout with two columns aligned to the left using

I am looking to create a layout where two pieces of text are displayed side by side in columns using CSS. The left-hand column will have variable length text, while the right-hand column will have fixed length text. The desired layout should show the two ...

Each time a nested collapse occurs, it triggers its parent collapse

I have come across some similar answers, but they all pertain to accordions, which I am not utilizing in this case. In my code, I have nested collapse items. You can view the code snippet here on CodePen $('#collapseOutter').on('show.bs. ...

Creating line breaks in Bootstrap input group formatting

My issue involves rows with checkboxes and labels, some of which are longer than others. When the browser is resized or viewed on a mobile device, the columns containing longer labels collapse to a second row while shorter labels stay beside their checkbox ...

Vuejs: Develop an intermediate component that utilizes one of the props and passes on all other content to the <button> element

Just getting started with Vue and struggling to articulate the problem, possibly a duplicate issue. We have a common pattern in our codebase where there is a button accompanied by a message depending on whether the button is disabled. Here's a simpli ...

Display or conceal nested divs within ng-repeat loop

I set up a div with sub divs to establish a nested grid system. There are three levels altogether: MainDiv - Always Visible SecondDiv - Display or conceal when MainDiv is clicked on ThirdDiv - Display or conceal when SecondDiv is clicked on <div c ...

What is the significance of the .jpg?t= in the URL?

This webcam image displays the code ?t=1512496926. What exactly does this code signify? Could it be related to time? Is it just a random string of characters? https://i.stack.imgur.com/ZAZMy.jpg ...

Issue with array merging/inserting feature not functioning as expected

Here are two arrays that I have: First Array: "workingHours": [ { "opening": "09:30", "closing": "13:30", "dayName": "sunday" }, { ...

Ensure that a group of checkboxes is mandatory

I currently have a series of checkboxes set up like so: <label>What is your preferred movie genre?</label> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="genre1" name="genre" ...

Showcasing a graphical representation with the help of Highcharts

I am currently exploring JavaScript and trying to familiarize myself with interactive charts using the HighCharts library. Unfortunately, I have been facing some challenges in getting the graph to print correctly. Despite attempting various examples, none ...

Is there a way to modify the location of the datepicker/calendar icon within my bootstrap form?

When using react-bootstrap with the <Form.Control type="date"> element, I noticed that the calendar icon or date picker is automatically positioned to the right side/end of the form field. However, I am interested in moving the calendar ico ...

Some elements are not visible when inspecting the source code

Hidden fields are essential in my jsp form. Interestingly, when I check the page source in a browser, only the first hidden field is displayed, not the second one. <input type="hidden" name="url" id="url" value="<%=url%>" /> <input type="hi ...

What steps should be followed to incorporate a horizontal scrollbar within the table's header?

I'm currently using Vue and Vuetify to create a unique layout that looks like this: https://i.stack.imgur.com/QBs3J.png The layout consists of a card with three rows: The first row displays the number of items and includes a search bar. The second ...

What methods can I employ with JavaScript to catalog data collected from an HTML form?

Currently, my form requires users to input a username that cannot start or end with a period (.). I have implemented some code but I believe there is an issue with the .value[0] parts. //Checking Username if (document.getElementById("uName&quo ...

Steps for removing the label associated with an input field in an HTML form

I attempted to use JQuery and JavaScript in order to modify the CSS of a label to make it greyed out, but unfortunately I have not been able to achieve this. The label is positioned next to a checkbox, and although I am able to disable the checkbox, I hav ...

Ways to utilize CSS for capturing user-inputted text in a text field

I have a question about incorporating user input text into CSS styling. Specifically, I am looking to create a color background option (#ffffff) where the designer can input their own color and have it displayed once saved in the body background style. Wh ...

Combining two CSS classes to create an "alias"

Currently, Iā€™m utilizing bootstrap for table styling. For instance: <table class="table table-striped main"> However, the table I want to style is dynamically generated by a separate tool that I have no control over, and it already has its own ta ...

Changing the background color of the canvas using Javascript

I want to create a rect on a canvas with a slightly transparent background, but I don't want the drawn rect to have any background. Here is an example of what I'm looking for: https://i.stack.imgur.com/axtcE.png The code I am using is as follo ...