In what way can a sub div be prevented from taking into account the height of its sibling?

I'm pretty confident that the answer to this question is going to involve using a clear:both property. However, I'm struggling with where exactly to place it and how to fully grasp its functionality.

Within my nested div structure, I have a particular section (sectioncut) that needs to accommodate the height of its sibling ul (subnav). I've attempted enclosing the ul in its own div, but it seems like I still don't quite comprehend how positioning and clearing elements work together.

As this is my first time seeking help on Stackoverflow, any advice or feedback would be greatly appreciated =D

Link to JSFiddle

HTML

<div id="pagecut">
  <div id="pagebg">
    <div id="nav">
      <ul id="subnav">
      <li><a href="index.html">Home</a></li>
      <li><a href="about.html">About</a></li>
      </ul>
      <div id="sectioncut">
        This is a test. 
      </div>
    </div>
  </div>
</div>

CSS:

body,html { 
    border: 0px;
    margin: 0px;
    height: 100%;
    background-color: #2200FF;

}

#pagecut {
    width: 95%;
    height: 100%;
    margin-right: auto;
    margin-left: auto;
    margin-top: 0;
    margin-bottom: 0;
    background-color: #2200FF;
    outline-style: solid;
    outline-color:#FF0004;


}

#pagebg {
    width: 100%;
    height: 100%;   
    margin-left: auto;
    margin-right: auto;
    background:url(Img/bg1.png);
    background-size: 100% auto;
    background-repeat:no-repeat;
}


#nav {
    width: 98%;
    height: 100%;
    margin-right: auto;
    margin-left: auto;
    outline-style: solid;
    outline-color:#00FF00;
}

#subnav {
    margin: 0px;
    padding: 0px;
}

#subnav li {
    display:inline;
    background-color: #7DA5EB;
    border-color: #7DA5EB;
    color: #FFF;
    border-top-right-radius: 7px;
    border-top-left-radius: 7px;
    border-style: solid solid none;
    padding-right: 7px;
    padding-left: 7px;
    margin-left: 2px;
    margin-right: 2px; 
    font-size: x-large;
}

#sectioncut {
    height: 100%;
    background-color: #7DA5EB;
}

Answer №1

It seems like the issue you're facing is with #sectioncut overflowing its container due to it occupying the entire height of the container and being pushed down by another div (#subnav) within the same container.

If this is indeed the problem and you only want #sectioncut to take up the remaining space after #subnav, I recommend checking out this resource on filling the remaining height of a container div.

This is my first time providing an answer here, so I hope this solution works for you. Let me know if you need any further assistance!

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

Which specific element of CSS should be adjusted to ensure compatibility with Internet Explorer?

Struggling with my one-page website layout, I made some adjustments to have six sections in the HTML. Everything seemed to work fine on all browsers except for Internet Explorer. It kept redirecting me to a weird spot between the second last and last two s ...

Conceal dynamically generated divs based on their individual class identifiers

My task involves dynamically generating div elements with incremented class names. Each div contains a close button in the top right corner, and I need to hide a specific div when the close button is clicked. Example Code: var i=1; var newImageBoxdiv = $ ...

Discover the array of results by implementing a while loop in JavaScript

My goal is to create a list of outputs that are not evenly divisible by numbers smaller than the input value. For example, if the input value is 10, the list should be 10, 9, 8, 7, 6, 4, 3, 1. I have written some code in JavaScript for this purpose, but ...

An unusual outcome occurred while attempting to duplicate the text

After copying the letter A, I noticed that an empty string is being logged to the console instead of the expected A. However, when I paste, the console does successfully log the letter A. document.addEventListener('copy', handler); document ...

Ensure that the table in PHP always displays a number of cells that is divisible by 5

My goal is to display a table with 5 values in each row based on the input number. However, I am facing an issue where when I input 67, the output does not show the remaining empty cells in the table as desired. I want to always echo a number of cells that ...

I need help figuring out how to mention an id using a concatenated variable in the jquery appendTo() method

Using jQuery, I am adding HTML code to a div. One part of this code involves referencing a div's ID by concatenating a variable from a loop. $(... + '<div class="recommendations filter" id="recCards-'+ i +'">' + &apo ...

CSS Problems in IE9 Causing Alignment Issues with Two Items in List Item

Take a look at this: JSFiddle The code looks fine in firefox, chrome, and opera, but in ie9, the numbers are shifting. Please see the image for reference. Everything is correct on the left, but on the right is ie9. I'm stuck and need help to solve ...

Allow users to edit the Tinymce text area by simply clicking anywhere within it

On my website, I have implemented a tinymce panel text area. Currently, users can only enter edit mode by clicking on the first line of the tinymce text area. I am looking for a way to allow users to enter edit mode when clicking anywhere inside the tiny ...

Designing websites using elements that float to the right in a responsive manner

Responsive design often uses percentage width and absolute positioning to adjust to different screen sizes on various devices. What if we explore the use of the float right CSS style, which is not as commonly used but offers high cross-browser compatibilit ...

Calculate the total price from a combination of HTML and JavaScript options without altering the values

I'm currently facing an issue in my form where the final price needs to be updated when a different option is selected. I've searched extensively for the problem without success. I've used similar code before, just with different variables a ...

Looking for help organizing a navigation bar?

I recently embarked on the journey of creating my own website and I am in need of assistance from individuals who possess expertise in CSS and HTML. The specific challenge I'm currently facing involves aligning the navbar elements properly. I aim to p ...

What is the reason for the ID "home-ad" not functioning properly in Firefox?

While working on some CSS styling, I encountered an issue with the ID "home-ad" not displaying properly in Firefox. The box model was showing a content size of 0x-40 (with 40 being the padding value). Interestingly, when I changed the ID name, the code wor ...

When scrolling, the body content covers up the navbar

Whenever I try to scroll the page, the body contents start overlapping with the navbar. I have content over the navbar that should disappear when scrolling, and it is working correctly. The navbar should be fixed while scrolling, and this functionality ...

Dynamic JavaScript animation to retrieve the position of an element on-the-fly

I am currently exploring the world of animation in JavaScript and I have a few practical questions. In my script, I am attempting to "launch" a "rocket" upon clicking a "button". What I've observed is that although my function calculates values as int ...

Issue with displaying website monitors

I am facing an issue with my website where it displays differently on various monitors. Below is the HTML and CSS code snippets: HTML <body> <div id="Links"> <a href="About.html"><img src="Slideshow/About.png" width="140em" />< ...

Enhancing Element Visibility with CSS Centering

HTML <div class="container1"> <ul class="menu-dropdown"> <li>item</li> </ul> <div> CSS .menu-dropdown{ display: none; } .container1:focus .menu-dropdown{ display: block; } I am attempting to cr ...

Angular app - static List mysteriously clears out upon refresh

My goal is to create a login page using Angular. I have an Angular component with HTML, CSS, and TypeScript files that manage this functionality. The HTML file contains two fields (Username and Password) and two buttons (Login and Register). When a user en ...

Text does not wrap correctly when placed between elements with the property white-space: nowrap

When applying the white-space: nowrap property to all children of an element, an issue arises in Webkit (and blink) where white space doesn't break between elements as expected: View example on jsFiddle .pairs { width: 180px; overflow: hidde ...

Encountering difficulties with the functionality of Google Places API

I am attempting to incorporate the autocomplete functionality of Google Places API into a text field. Below is the code I have implemented: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script> <script ...

substitute a variable

I am trying to update the value of a variable using an HTML form. Within my config.php file, I have declared a variable $num = 3; I would like the value 3 to be replaced with whatever I input in the form form.html. Below is the code for my HTML form : ...