简体   繁体   中英

Why isn't a margin being applied with my CSS?

I have a div:

.divcom {
    background-color: lime;
    border-radius: 5px;
    width: 37.5%;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.39), 0 6px 20px 0 rgba(0, 0, 0, 0.39);
}

And i want it to have some space at the bottom before the page ends (Lets say 50%)

When I try to do bottom: 50% or margin-bottom: 50% it doesn't work (The color disappears).

I also tried putting margin-bottom: 50% into body but it didn't help.

Absolutely-positioned elements are outside of the normal document flow. They should be used sparingly, since they make a layout more complicated. Your element probably has a margin, but doesn't affect the other elements on the page because it's layered separately.

I'd also point out that bottom and margin-bottom are very different things, and that percentage margins can be troublesome (you don't always know what you're taking a percentage of).

For more specific advice, provide a more specific use case.

Try setting margin-bottom to auto and setting bottom to 10px. I can't really tell what you're trying though because of top which is set to 100%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM