how to position one div above another using css

I currently have a page layout with 7 different div elements structured like this;

<div id="container">
    <div id="head"></div>
    <div id="A">
        <div id="A1">A1</div>
        <div id="A2"></div>
    </div>
    <div id="B"></div>
    <div id="foot"></div>
</div>

The CSS styling applied to these elements is as follows;

html, body {
    margin: 0;
    padding: 0;
    border: 0;
}
#A, #B, #foot {
    position: absolute;
}
#head{
    background: #FF9900;
    width: 100%;
    height: 35px;
}
#A {
    top: 35px;
    width: 200px;
    bottom: 35px;
    background-color: #999999;
}
#A1{
    height: 35px;
    width: 35px;
    margin-left: 200px;
    background-color: #CC0066;
}
#B {
    top: 35px;
    left: 200px;
    right: 0;
    bottom: 35px;
    background-color: #99CC00;
}
#foot{
    background: #0066CC;
    width: 100%;
    height: 35px;
    bottom: 0;
}

However, the div element A1 is currently not being displayed as intended. You can view a live example of this issue in action on this demo. My goal is to have div A1 appear above div B. Any suggestions on how to resolve this issue would be greatly appreciated.

Thank you in advance for your help. :)

Sincerely, blasteralfred

Answer №1

The issue lies with the #A1 margin-left property.

Specifically, the #A element has a width of 200px, and the #A1.margin-left property was mistakenly set to 200px.

Answer №2

Need to fix your #A1 div being covered by your #B div? Simply add z-index:100; (or another z-index number) to your #A div CSS. Check out this example http://jsfiddle.net/rGGEK/22/.

Answer №3

Oops! Looks like you missed adding the style for A1 in your fiddle. Also, keep in mind that the parent container, A, has a width of 200px, causing your A1 to begin just beyond its right edge.

Answer №4

The reason why it's not visible is due to the margin-left. Lowering it to 10 pixels will make it visible.

Answer №5

Eliminate the margin-left: 200px; in the style of A1

#A1 {
    height: 35px;
    width: 35px;
    background-color: cyan;
}

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

What is the best way to position an image using css?

I am looking to position an image on the left side of my homepage using CSS instead of HTML. However, I am having trouble figuring out how to make it work. The image I want to use is called Nobullying.jpg. HTML: <html> <head> <link re ...

How can the end event of a custom CSS animation be bound using jQuery or JavaScript?

We are currently managing multiple animations on the same object and need to execute different actions once each animation is complete. At present, we listen for the webkitAnimationEnd event and use a complex if/then statement to handle each animation sep ...

Is there a way to adjust the size of text to perfectly fit within a fixed size div?

I find this scenario quite common, but I haven't come across any solutions for it: Let's say there is a fixed-width div that displays dynamically changing numbers. How can we adjust the font size so that larger numbers fit well within the fixed ...

Aligning the Bootstrap navbar to the right causes the items to shift to the left

UPDATE: The issue has been resolved. It turns out that the navbar was not extending to 100% width and reaching the edges of the screen. I am currently facing a challenge with a Bootstrap 4 navbar, similar to issues I encountered with the previous version. ...

problems arise due to padding and floating on the navigation bar

I have been facing a couple of challenges with my code. Firstly, I am trying to remove the small annoying line underneath my selected navigation links and also attempting to float both the header and footer to the right without losing their backgrounds. I ...

The input-group-btn is positioned to the right of the field, appearing to float

The input-group-btn for the targetDate field remains fixed on the right side of the input group despite screen width variations until I introduce the automatically generated CSS from the hottowel generator. I require assistance in identifying which aspect ...

Struggling to display the inline navbar

For the past few hours (a little over 3 hours, to be exact), I've been grappling with an issue that seems fairly simple. Despite scouring through various SO posts and other resources, I just can't seem to figure out the problem. The crux of the ...

What is the best way to animate elements so that they move in a circular motion?

My goal is to recreate the image shown in the picture: https://i.sstatic.net/z08II.jpg In case the image is blocked, you can view it here: https://i.sstatic.net/YYg4J.jpg The picture appears to have only one icon visible, but there are actually 4 icons. ...

The hover effect is implemented across all image elements

Below is the code snippet in question: #mg1 { margin-left: 3%; } #mg1:hover { margin-top: 4%; } <div id="section1"> <center> <div id="bgp"> <center> <p>THUMBNAILS</p> </center> ...

Enhancing dynamically generated elements with CSS styling

I have been working on developing my own jQuery Gallery Plugin. The crucial initial markup that is required to initialize the plugin includes: Initial HTML <div class="riGallery"> <ul> <li><a href="http://www.example.com" ...

"Enhance Your Website Navigation with Bootstrap Navbar Links Extensions

I'm stuck on nesting a "navbar" in a Bootstrap row. The issue I'm facing is how to get the links to expand across the entire column. https://i.sstatic.net/9QbSN.png The code for this problem looks like: <div class="col-6 p-3 ...

The Media Queries in the Wordpress html5blank theme are failing to function properly

While using the html5blank theme to develop a WordPress site, I noticed that my media queries are functioning properly locally. However, when I add them to the WordPress style.css file, they seem to stop working. Even after stripping away all other media q ...

React DOM's offsetHeight prior to rendering

I am struggling to figure out how to position a React DOM element based on its offsetHeight. The issue is that I cannot determine the offsetHeight of an element that hasn't been created yet (so the height cannot be passed as a parameter to the render ...

Utilizing cookies to track the read status of articles - markers for reference

Currently, I am in the process of developing a website and am interested in implementing a feature that allows users to track which articles they have read. I am considering adding a small circle next to each article heading to signify whether it has been ...

Enhance your Divi theme with Elegant Themes: Explore mobile-friendly background image zoom effects

I have a regular section module with an image as the background. The design looks great on desktop but appears zoomed in and blurry on mobile devices. I'm struggling to understand why the mobile view is not adjusting properly, and I am unsure if there ...

The feature of option display is not supported on Safari browser

I am facing an issue with the functionality of two dropdown menus. The options in the second dropdown are supposed to be shown based on the selection made in the first dropdown. While this feature works perfectly in Chrome, it seems to be malfunctioning i ...

Increasing the padding at the top of the logo when scrolling down the page

When scrolling down the page, there seems to be extra padding above the logo that is throwing off the alignment with the rest of the site. I've been trying different solutions to correct this issue: //$('.navbar-brand').css({ 'padding- ...

Tips for creating a background image that seamlessly adjusts to various computer screen sizes

I am trying to make sure that an image fills the entire browser window, but unfortunately it has fixed width and height dimensions. Is there a way to adjust this so it displays correctly on screens of different sizes? Can CSS be used to stretch the backg ...

Using a CSS gradient with a variable in React.js - A guide to implementation

Looking to incorporate the following CSS property into the Navlink component. In the CSS file, the property is usually written like this using gradient. .ele { background-image: linear-gradient(45deg, #808080 25%, transparent 25%), li ...

What steps can I take to prevent the odd gaps from appearing in my horizontal flexbox gallery?

Take a look at this code: .gallery { display: flex; overflow-x: auto; resize: both; background-color: rgb(200, 200, 200); padding: 10px; height: 200px; } .item { display: flex; flex: 0 0 auto; max-width: 100%; } .item img { max-w ...