How come a child element doesn't disappear when the parent element's height is reduced to zero?

Just starting out with HTML and CSS, so please be patient with me.

I have a header div that contains a nav div, which in turn contains a li div. I attempted to create a button that would hide the entire header. While I managed to hide the header, the nav and li divs remain visible.

Here are the CSS properties used:

#header {
  z-index: 100;
  left:0;
  top: 0px;
  height: 60px;
  transition: max-height 0.2s ease-out;
  width: 100%;
  position: fixed;
    nav {
       max-width: 650px;
       margin: 0 auto;
       padding: 0 10px;
       li {
          font-family: 'OpenSansLight', "Helvetica Neue", Helvetica, Arial, sans-serif;
          font-weight: normal;
          list-style: none;
          display: inline;
          color: white;
          line-height: 50px;
       }
    }
}

The code above is from a Jekyll scss file that generates corresponding css. The JavaScript function used is as follows:

var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    var content = this.nextElementSibling;
    console.log(content.innerHTML);
    if (content.style.height){
      content.style.height = null;
    } else {
      content.style.height = content.scrollHeight + "px";
    } 
  });
}

Thank you.

Answer №1

To hide both the parent and children divs, consider using the CSS display property with a value of 'none'. Implement it in this manner: display: 'none';

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

Clear the text in a textarea after submitting the form

I am facing an issue with a comment box (textarea) inside a dialog. After successfully saving the comment, I want to clear the content of the textarea and close the dialog box. Currently, the dialog box closes, but the content remains in the textarea. < ...

The CSS :lang() selector targets elements within documents that do not specify a particular language

Can elements that do not have a language set or inherited, meaning they are in an unspecified ("unknown") language, be targeted? Facts The language of an HTML document or element can be specified using the HTML lang attribute, for example: <html lang=& ...

Discover the root cause of why an element is being prioritized

Is it possible to determine what is causing the first html element (input, textarea) to gain focus? While loading a modal window, I am unable to locate the line of JavaScript that is setting focus() on this initial element. One workaround is to blur() it ...

Mapping the correct syntax to apply font styles from an object map to the map() function

React, JS, and Material UI Hey there, I have a question about my syntax within the style property of my map function. Am I missing something? Fonts.jsx export const fonts = [ { fontName: 'Abril', key: 'abril', fontFamily ...

My function is not working with jQuery's .append method

As a newcomer to javascript and jquery, I am experimenting with adding html through a javascript function. In an attempt to place the contents of variable "y" at a specific location, I am using a div tag with the id of "Contacts" and trying to append elem ...

React Subcomponent Encountering Issues with Updating Array Properties

My React web application is built using Typescript. I encountered an issue with a child Component that displays array Props incorrectly when the array is updated in the parent Component using setState. The child Component is declared within the parent Co ...

Customize the velocity of your jQuery Cycle plugin's horizontal slider

Currently, I am utilizing the jQuery Cycle plugin to design a basic slideshow. Here is the corresponding script: $(document).ready(function() { var slideshow = $('#slider').cycle({ fx: 'scrollHorz', speed: 500, timeout: ...

What is the best way to iterate through these arrays to retrieve just the orderTotal values?

How can I iterate through this array and calculate the total order amount within each Item object? (0) OrderTotal $100 (1) OrderTotal $220 var sum = 320; store the combined OrderTotal values in a variable I aim to obtain the total sum of all order tot ...

Fetch Comments through API

The task at hand is to display the commit comments and descriptions on the front end of a website. Here's where the repository can be found: https://github.com/shannonhochkins/SassyGrids My attempt so far involves using this code snippet: $.getJSON ...

Positioning the navigation menu in the center

I'm facing a bit of trouble trying to center a navigation bar on my Blogger site. Usually, this is a simple task, but for some reason, it's proving difficult this time around. Feel free to check out the website in question: Center Navigation I& ...

Determine your age by manually inputting your date of birth

Utilizing Ajax Calendar, I have successfully implemented a feature to calculate age based on the date selected in one textbox and display it in another. However, I am facing two challenges. First Issue:- I want the Age Textbox to be disabled so users cann ...

Exploring the use of dictionaries within Django templates

views.py: return render(request,'images.html',temp) Temp Data: {'cluster1': ['temp/vinoth/cluster1/demo-pic94.jpg', 'temp/vinoth/cluster1/id1.jpg'], 'cluster2': ['temp/vinoth/cluster2/demo-pic94.jp ...

Receiving a "Bad Request" error when trying to access a website

Every time I attempt to call a lengthy URL, I encounter a Bad Request issue. https://localhost:44320/RespostaEmail/96635/750396/[%7B%22IdItem%22:8,%22IdTipoReposta%22:80%7D,%7B%22IdItem%22:1,%22IdTipoReposta%22:80%7D,%7B%22IdItem%22:3,%22IdTipoReposta%22:8 ...

Is there a way to integrate a calendar feature within an Angular 2 application?

I am brand new to Angular 2 and have a question: I need to integrate a calendar into a page where users can add events. Something similar to the following example: I'm unsure if the angular material calendar project is designed for Angular 2 or for ...

Creating a unique filter that combines and filters data from two separate API calls for

In my current scenario, I am making two different API calls using Axios in my application. The first call fetches a complete JSON file that populates a table, while the second call retrieves only categories. This setup is due to the complexity of the app, ...

Demonstrating information using a HighCharts pie graph in a Visual Studio web application

Here is a snippet of code that supplies data for the chart within the View: series: [{ type: 'pie', name: 'Chart Title', data: @Html.Raw(Json.Encode(Model)) }] This piece of code can be foun ...

Is it possible for issues to arise when serving a web app using the "Globals" module in the Mean Stack?

Looking to transfer a variable (a constructed filename) from one file to another within an API can be quite challenging. One solution that comes to mind is utilizing globals, but with my current code structure, it seems like the only viable option. To addr ...

Ways to loop through an array in a JSON object

Exploring methods of iterating through an array in json: $(document).ready(function(){ $('#wardno').change(function(){ //this code will execute whenever there is a change in the select with id country $("#wardname > ...

Child element casting shadow over parent element

I am currently using box shadow for both the parent (.map) and child (.toggle-button): .map { position: fixed; top: 20px; right: 0; width: 280px; height: 280px; z-index: 9999; box-shadow: 0px 1px 6px 0px rgba(0,0,0,0.3); } .map ...

I am interested in displaying the PDF ajax response within a unique modal window

With the use of ajax, I am able to retrieve PDF base64 data as a response. In this particular scenario, instead of displaying the PDF in a new window, is it possible to display it within a modal popup? Any suggestions on how this can be achieved? $.ajax ...