When a container is set with relative positioning and overflow is hidden, it will not inherit a defined height

In my CSS code, I am trying to achieve a layout where the navigation and website sections are absolutely positioned so they can slide back and forth when a menu button is pressed (similar to the Facebook app). My approach involves placing them within a container with an overflow: hidden property to hide and reveal the navigation bar as needed. However, I'm facing an issue where the container loses its automatic height due to the absolute positioning.

Is there a way to restore the automatic height functionality while still using overflow: hidden without including absolute positioning?

I have set up a Fiddle in which the container has a fixed height of 500px. My goal is to make the height adjust automatically. See the Fiddle here: http://jsfiddle.net/rB7EY/

div {
    box-sizing: border-box;
}

.container {
    overflow: hidden;
    width: 100%;
    max-width: 60em;
    padding: 0;
    margin: 0 auto;
    position: relative;
    background: grey;
    height: 500px;
}

.navigation {
    width: 15em;
    float: left;
    background: blue;
    position: absolute;
    left: -20px;
}

.website {
    width: 100%;
    float: left;
    position: absolute;
    left: 0px;
}

.container .website .top_bar {
    height: 4em;
    background: pink;
    padding: 1em;
    position: relative;
}

.container .website .top_bar .menu_button {
    width: 3.2em;
    height: 2.5em;
    background: red;
    border: 0px;
}

nav.menu {
    width: 15em;
    position: absolute;
    left: 1em;
    top: 3em;
    background: yellow;
}

Answer №1

It sounds like you're looking to automatically adjust the size of the container. One suggestion is to incorporate a min-height and max-height property into your styling.

Answer №2

To solve the issue, I implemented a div element between the container and the navigation bar on the website. I then assigned an absolute position to this new div. Additionally, I set the container's width to 100%.

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

Textarea generated on-the-fly without any assigned value

My goal is to enable users to edit the text within a paragraph on a website. I am attempting to replace the <p> tags with <textarea> tags using the .replaceWith() function. However, when I try to retrieve the value of the textarea, it comes bac ...

Tips for containing text inside a div element using HTML with Bootstrap styling

I'm having an issue where my text overflows the page at certain sizes. How can I prevent this from happening? Despite my efforts to find a solution through Google and various attempts, I have been unsuccessful. If you take a look at the screenshot I ...

Achieving vertical center alignment for the label and btn-group in Bootstrap

Is it possible to align other elements with the Bootstrap btn-group? <div class="btn-toolbar text-center"> <div class="pull-left"> <span class="glyphicon glyphicon-envelope " style="font-size:1.5em;"></span> < ...

Listen up, Javascript keyboard input recorder

I am aiming for the search bar to pop up when you type. The code below is functioning, but I am facing an issue where the search bar pops up even when typing in a different input field, such as the comment input. Is it feasible for the search bar not to ...

Styling for jQuery mobile panels disappears when used on multiple pages

Currently, I am working on developing a mobile application for PhoneGap using jQuery Mobile. The app consists of multiple pages within the same HTML document. I have configured it so that all pages share the same panel, but I am facing an issue with the st ...

What is the method for obtaining the image alt attribute using JavaScript?

I can't seem to retrieve the image alt tag using JavaScript. Is it even possible and if so, how should I go about it? Perhaps something like this: $caption.text( flkty.selectedElement ).attr('alt') (last line of JavaScript) But I'm st ...

Adjustable image scaling with dynamic maximum height

Instead of trying to explain the problem I need to solve, let me show you an example for better clarity (apologies to mobile users, this may not work...) You can observe the effect I am aiming for on VICE news () While resizing the browser, notice how th ...

Is it possible to leverage AngularJS string interpolation ({{}}) within the jQuery HTML function?

I am attempting to implement angularJs string interpolation within the Jquery html function $('#existingScoresForWeek').html("<p>{{1 + 1}}</p>"); Unfortunately, the code above is not displaying the Result as 2 <div data-ng-app=" ...

Unable to modify the formatting of this block within the forum (CSS)

I've been working on customizing a theme by changing the colors. While updating an IPB theme, I have successfully converted most of it from white to grey, except for one part. I've attached a Gyazo link with a sample post where the white color ...

Text displayed in two columns with a circular image positioned in the left column

https://i.sstatic.net/52mhN.jpgI am attempting to create a layout with two columns of text and a rounded image in the upper left corner of the left column. Here is what I have so far: <div class="photoside-left"> <img class="photo" src="http://v ...

What is the quickest and most effective method for toggling more than 10,000 checkboxes using Javascript/jQuery?

I am facing a challenge with a div that contains over 10000 checkboxes. Due to technical limitations, I have no choice but to work with this large number of checkboxes. This is not related to any academic task. <div class="well well-sm" style="min-hei ...

Is it possible to specify the input language for a textbox or textarea in a web form?

I am currently working on developing a website in Urdu language, with features similar to that of a blogging platform. To ensure that all posts are written only in Urdu, I am exploring different options. One idea I have is to use a Javascript code that ca ...

Having issues with a Retina iPhone interacting with a website built using responsive Twitter Bootstrap

I'm currently utilizing Twitter Bootstrap alongside responsive CSS for a web page that is optimized to run in a UIWebView. My goal is to ensure the consistency of the page's appearance across all iPhones, with an exception for images. These imag ...

Adjusting the layering of a nested element within a container div using

I am facing an issue with two buttons placed within a container div that is being overlapped by another container div. The bottom container overlaps the top one, rendering the buttons unclickable. I have been trying to find a solution to make the buttons ...

Updating Masonry Layout with Collapsible Feature using Bootstrap 4

Solution: Resolved the issue by replacing Cycle2 with a responsive slideshow script called Slick. Check out the code on jsfiddle. (function($) { var $carousel = $('.carousel'), $masonry = $('#cards'); $car ...

How to remove the scrollbar from the main div in a Bootstrap layout

Currently, I am in the process of creating a registration page using HTML, CSS, and Bootstrap5. I have a couple of questions: Within my code, there is a fixed height for the footer set at 55px. I am uncertain if this is considered good practice because ...

Transforming global CSS into CSS modules: A step-by-step guide

In my nextjs project, I am utilizing react-bootstrap and bootstrap which requires me to include the global css: // _app.js import 'bootstrap/dist/css/bootstrap.min.css'; The issue arises when loading a significant amount of unused css on every p ...

When the mandatory option is chosen, the scroll snap type acts similar to proximity by enforcing

My goal is to have the main hero section of the website take up the entire screen, and when the user scrolls down, they are immediately brought to the main content with the hero section no longer visible. However, I am experiencing an issue where if I do a ...

Embedding a video element results in an unexpected increase in height

When I insert an HTML5-Video element into a div, it results in the wrapper having a height larger than the video itself. The wrapper is 7px taller than the actual video source, without any min-height set. Check it out! (Scroll down to the Video) The vide ...

Is Jquery struggling to modify the visual enhancements?

Check out this link, I need the sidebar design to be similar to what is shown in the provided link. Furthermore, I am looking for a way to have a pointer that follows along with my selection on different labels such as home, charts, etc. Can anyone assis ...