Overlapping content issue with responsive background image div and fixed nav
You can solve this issue by placing your <div id="content"></div>
inside the <div id="background"></div>
. For example:
<div id="background">
<div id="content">
margin-top: 0;
</div>
</div>
for some reason you dont want to do that, you can also do following by setting content div position to absolute and top: 50px; but than i will recommend to set z-index of your nav bar so it can stay on top.. for example:
#fixed-nav {
top: 0;
background: #EEE;
position: fixed;
min-height: 2em;
width: 100%;
z-index: 999;
}
#content {
position: absolute;
top: 50px;
}
Hope it helps.
Happy Coding, and happy holidays!
::before and ::after elements overlapping each other ruining the background transparancy
A Haworth's answer covers using linear gradient stops to hide the color of half of each pseudo element.
Another approach you could take is to use only one of the pseudo elements with a polygon clip path to make your shape.
.container { display: flex; }
.hoverable { position: relative; margin: auto; padding: 10px 100px; }
.hoverable:hover::before {
content: "";
position: absolute;
inset: 0;
/* top: 0; left: 0; right: 0; bottom: 0; */
background-color: rgba(0, 0, 0, 0.25);
clip-path: polygon(0 0, 100% 0, 80% 50%, 100% 100%, 0 100%, 20% 50%);
}
<div class="container">
<div class="hoverable">Hello, World!</div>
</div>
Overlap background until an element
I would make two sections. Say header
and section
. The header gets the background and padding-bottom
. The cards live in the section container and get NEGATIVE margin-top
equal to the card padding + text height.
This way you can add as much as you want to the header and it will always push the other stuff down.
body { margin:0; padding:0; font-family: Arial, Helvetica; background-color: blue;}header { background-color: red; color: white; margin: 0; padding: 10px 10px 50px 10px;}
.tiles { /* this is the important part. Make sure top margin = top padding + height of text */ margin: -25px 10px 0 10px; display:flex; justify-content: space-between;}
.tile { flex-basis: 25%; background-color: white; border-radius: 5px; padding: 10px; min-height: 100px;}
<header> <h2>Some Header Content</h2></header><section><div class="tiles"> <div class="tile">Tile Content</div> <div class="tile">Tile Content</div> <div class="tile">Tile Content</div></div></section>
Why is the body element overlapping its child element?
If you want main div
to show, without being cropped, you need to change the overflow on main
to overflow: visible
. Might need more clarification on what you're trying to achieve. :)
Why does text on the same layer overlap - even when it has an opaque background?
Why does text on the same layer overlap - even when it has an opaque background?
The spec says (emphases mine):
Within each stacking context, the following layers are painted in back-to-front order:
- the background and borders of the element forming the stacking context.
- the child stacking contexts with negative stack levels (most negative first).
- the in-flow, non-inline-level, non-positioned descendants.
- the non-positioned floats.
- the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks.
- the child stacking contexts with stack level 0 and the positioned descendants with stack level 0.
- the child stacking contexts with positive stack levels (least positive first).
The backgrounds and the text are considered separately in the painting order: the backgrounds are represented by #3, and the text is represented by #5. The second element appears later in the source, so it is painted over the first, but the text still needs to be painted over the backgrounds, because the two elements are participating in the same stacking context.
Must I create a new stacking context to prevent the text overlapping here?
Yes, the best way to deal with this is by positioning the elements or by having them establish their own stacking contexts. A stacking context is always self-contained, so having each element establish its own stacking context will always ensure that the backgrounds and text of the two elements don't overlap one another.
How do I prevent the CSS :after pseudo-element from overlapping other content?
As noted above:
It has nothing to do with being a pseudo element. You've toyed with its positioning, any other element would do the same thing with the styles you've provided. Unless your images are purely decorative (the fact that they have a caption/description clearly implies they are not decorative), you should be using the image element instead of a background property.
DIV Overlapping But Not Hiding The Portion Of the DIV That It Overlaps
You need to give the front most div a background color.
div.front {
height:60px;
width:100px;
border:3px solid blue;
position:absolute;
z-index:1;
background-color: white;
}
div.back {
background-color:#e0e0e0;
border:1px solid red;
position:absolute;
z-index:-1;
}
Related Topics
Position Footer At Bottom of Page Having Fixed Header
Matching the First/Nth Element of a Certain Type in the Entire Document
Making a Div Vertically Scrollable Using Css
How to Center Text Vertically With a Large Font-Awesome Icon
Which Characters Need to Be Escaped in Html
≪Embed≫ Vs. ≪Object≫
How to Customize the Numbers in an Ordered List
Angular 2 Dropdown Options Default Value
How to Send Email from HTML Form
Css Cut Out Circle from a Rectangular Shape
Difference Between ≪Section≫ and ≪Div≫
Css Background Image to Fit Width, Height Should Auto-Scale in Proportion
Change Bootstrap Tooltip Color
How to Delete an Item or Object from an Array Using Ng-Click
Background: Fixed No Repeat Not Working on Mobile
Using ≪Style≫ Tags in the ≪Body≫ With Other Html