How come this particular design is being passed down from a predecessor (and not a direct parent) div?

Web development can be frustrating at times. Hopefully, someone out there can shed some light on this issue and offer a solution.

You can view the HTML/CSS code below or check out this example on JSFiddle

The problem arises when I have a header div and a body div, both containing floating divs with a clearfix to ensure that the container spans over them. Despite setting the foreground color of the header div to WHITE and the body div to BLUE, the body div ends up inheriting the header div's color as well. How is this even possible?

In my actual code, things get even weirder. When I specifically set the foreground color for the body div to BLUE, the header div also changes to blue. While I can't replicate this exact issue in the JSFiddle provided, understanding it here might help me solve the bigger problem in my original code :)

HTML:

<div>
    <div id="head">
        <div class="headleft">
             <h1>that's my header, baby</h1>
        </div>
        <div class="headright">
            <p>righty right</p>
        </div>
        <div style="clear: both" />
    </div>
    <div id="body">
        <div class="feature">
             <h1>feature 1</h1>
        </div>
        <div class="feature">
             <h1>feature2</h1>
        </div>
        <div style="clear: both;" />
    </div>
</div>

CSS:

body {
    color: blue;
}
div#head {
    background-color: gray;
    width: 400px;
    color: white;
}
div#body {
    background-color: lightgray;
}
.headleft {
    float: left;
}
.headright {
    float: right;
}

.feature
{
    float: left;
    margin-right: 10px;
}

Thank you in advance for any insights into resolving this puzzling issue!

EDIT Apologies for editing the copied code incorrectly earlier. I've fixed it now, and the missing closing DIV has been added back. The issue was not related to the missing tag.

Answer №1

You made a mistake by not closing the tag on the head div. Check it out here

<div>
    <div id="head">
        <div class="headleft">
             <h1>that's my header, baby</h1>
        </div>
        <div class="headright">
            <p>righty right</p>
        </div>
        <div style="clear: both" /></div>
    </div>
    <div id="body">
        <div class="feature">
             <h1>feature 1</h1>
        </div>
        <div class="feature">
             <h1>feature2</h1>
        </div>
        <div style="clear: both;" />
    </div>
</div>

Answer №2

Your HTML issue stems from not properly closing the div tags. It is incorrect to close div's like this: <div/>. The correct way is to use <div></div>. For guidance, refer to this functional Fiddle.

Answer №3

Your code is missing a closing <div> tag for the "head" section.

<div>
    <div id="head">
        <div class="headleft">
             <h1>Here's my header content</h1>
        </div>
        <div class="headright">
            <p>on the right side</p>
        </div>
        <div style="clear: both" /></div>
    </div>
    <div id="body">
        <div class="feature">
             <h1>Feature number one</h1>
        </div>
        <div class="feature">
             <h1>Another cool feature</h1>
        </div>
        <div style="clear: both;" />
    </div>
</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

CSS - Is there a way to alter the arrangement of DIVs depending on the size of the screen?

My inquiry pertains to a CSS layout. I currently have 3 divs positioned in a horizontal line next to each other, as depicted below... div1 div2 div3 I am aiming for the divs to reorganize themselves as the screen size decreases. In one scenario, they sho ...

Tips on customizing the CSS responsiveness of your Bootstrap carousel

I have recently installed a Bootstrap theme on my Wordpress site and I am trying to make some CSS adjustments. One issue I am facing is with the carousel. Currently, when I resize the website or view it on a mobile device... The carousel maintains a lar ...

What is the correct method to sanitize the data obtained from a text area before inserting it back into the same text area?

When a user enters text into a textarea, it is directly inserted into a mySQL database. To ensure its security, I apply trim, htmlentities, mysql_real_escape_string functions to sanitize the input. Additionally, magic quotes are enabled. However, when it c ...

The function history.popstate seems to be malfunctioning, as it is triggered by both the forward and backward navigation buttons in

When I press the back button, I am attempting to retrieve the previous state. Upon inspecting, I noticed that the popstate function is also triggered by the forward button. However, it does not revert to the previous state even though the popstate function ...

Setting the CSS property `position: absolute; bottom: 0`, will move the div to the bottom of the screen rather than the bottom of

I'm currently working on a website where I want to attach a menu-bar to the bottom of the header using #menu { position: absolute; bottom: 0; } Unfortunately, instead of sticking to the bottom of the parent div, the menu-bar is stuck to the ...

Tips for choosing an item in a multi-select dropdown using Selenium WebDriver

Currently delving into Selenium WebDriver while utilizing Java.. I am curious about how to select values in a Multi-select box where the options are already pre-selected. If I want to choose two or more additional options, how can I go about it? The HTML ...

HTML5 Slideshow with Smooth Image Transitions

So, I have created an HTML5 image slideshow and it's working perfectly on my localhost. However, I am puzzled as to why there is no transition effect within the slideshow. I was expecting something like fading out the first picture and then having the ...

Hover over an element to trigger the background fading effect on the parent div

I'm looking to create a hover effect on an element within a fullscreen div. When I hover over the element, I want a background image to fade in on the div with the class ".section." While I can easily display the background image, I am unsure of how t ...

Display only the static placeholder in Angular 2 multi-select feature

My experience with angular 4 is fairly new and I've recently delved into using the angular multiselect feature with the npm package available here. I've managed to successfully configure it, as well as capture selected and deselected items/event ...

Lag in responsiveness of iOS devices when using html5 applications

My HTML5 video app includes a combination of video, a JavaScript swipable playlist, and other animated overlays. When using the app on iOS, the performance of playlist swiping and overlay animations is great upon initial load. However, after playing a vid ...

I am in need of a JavaScript event that will take precedence over the CSS pointer

There is an image causing issues with scrolling on a mobile device because it's located in the finger-friendly area where people tend to scroll. I attempted to use pointer-events: null; to allow scrolling, but this also prevented the click event from ...

Obtain the image format from an HTML page using the Jsoup library on Android

<div class="_jjzlb" style="padding-bottom: 55.2778%;"><img alt="AT Dam party.. #nashik #big #dam" class="_icyx7" id="pImage_11" src="https://instagram.fbom1-2.fna.fbcdn.net/t51.2885-15/e35/17438694_254543168340407_6435023364997251072_n.jpg" style ...

How do I get my navbar to change color using a JavaScript scroll function?

I've been struggling with changing the color of my navbar when it's scrolled. I have some JavaScript code at the bottom that should handle this, but for some reason, it's not working as expected. I've double-checked that my bootstrap CD ...

SCSS: When hovering over one div, display a different div

My goal is to display the elements in another div when hovering over a specific div. However, my current code does not seem to be working as expected. At the moment, there is no response upon hover and it remains non-responsive. I would greatly appreciate ...

What is causing the spinner with CSS rotation transform to bounce rhythmically?

In my design, I have created a simple Spinner icon in Figma. It's meant to be perfectly aligned at the center of an enclosing frame that has dimensions of 64x64. To achieve the rotating effect, I applied CSS rotation as shown below: let rotation = ...

Attaching onchange event to a select menu

I'm a bit confused about how to bind the onchange event to a select element. There seem to be multiple ways to accomplish this. HTML <select id="ddl" onchange="test()"></select> jQuery $(function(){ $("#ddl").change(function(){ ...

Tips for designing a navbar specific to a profile section

I am currently working on an angular application with a navigation bar composed of anchor tags. When the user logs in, I have an ngIf directive to display my profile icon with dropdown options. However, I am facing challenges in styling it correctly. I aim ...

What could be causing the issue with the focus not being activated when clicking on the input field in Vue?

I am facing an issue where I have to click twice in order to focus on a specific input field, and I'm having trouble setting the cursor at the end of the input. I attempted to use $refs, but it seems like there may be a deeper underlying problem. Any ...

Rearrange the order of items in the fancybox gallery

Typically, fancybox displays items in the gallery based on the order they are added in the HTML code. Is there a way to customize the order of items when they are opened in the popup, while keeping the original order when displayed on the page? The solut ...

Deleting database information using Jquery when a div is clicked

I'm looking to create an alert system where users will see a pop-up alert on their screen. However, I am facing a major issue in removing the div completely. I understand that I need to remove it from the database, but I'm struggling with finding ...