I have simplified my question to this:
HTML
<div class="dropbox">
</div>
CSS
.dropbox {
border:2px solid #ff0000;
height:200px;
width:50%;
margin:auto;
}
.dropbox:after {
content:'';
width:10px;
height:10px;
background:#ff0000;
top:100%;
left:50%;
margin-left:5px;
}
Why can't I get the :after
pseudo element to show up?
I need it at the bottom middle of the div. To by clear, it should be under the div in the middle.
Basically replaced elements will have all its contents replaced - so when rendered by the browser, we cannot see any :after or :before pseudo elements. Therefore the styling will not apply. So if you are using :after for the above HTML tags, then most likely it will not work.
::after. In CSS, ::after creates a pseudo-element that is the last child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
The input element has no content in the CSS view, and so has no :before or :after pseudo content. This is true of many other void or replaced elements.
CSS ::before and ::after pseudo-elements allow you to insert “content” before and after any non-replaced element (e.g. they work on a <div> but not an <input> ). This effectively allows you to show something on a web page that might not be present in the HTML content.
It's worth noting that the pseudo element is inline
by default - you therefore can't add margins or change the dimensions of it. If you were to change the display to block
you will notice that it shows up as you would expect (example).
In your case you need to absolutely position it relative to the parent element.
Example Here
.dropbox {
border:2px solid #ff0000;
height:200px;
width:50%;
margin:auto;
position:relative;
}
.dropbox:after {
content:'';
position:absolute;
width:10px;
height:10px;
background:#ff0000;
top:100%;
left:50%;
margin-left:5px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With