The image is 280px x 2px. It works okay except the height of the image seems to vary if there is more than 1 section on a page. I can’t work out the actual height it’s dispayed at. The height seems to vary depending on the width of the browser window.
I get the same problem in FF, Chrome and Edge.
The live page that is giving me most grief is at https://www.williamstewartfoundation.org/news.php
Could you post a couple of comparitive screen shots? I don’t see any change in the height or width of the image at any browser width or number of sections. It doesn’t seem to be influenced by any css. I could be missing something.
I wondered whether to post a screenshot! I hope this helps. What is odd is it doesn’t exactly show what I see on screen although it does demonstrate the problem (I think).
What I see on screen is the first divider is “short” and the other 2 are “taller”; what the screenshot shows is the 1st and 2nd are short and the 3rd is taller.
I don’t know if I trust my vision when it comes to spotting a pixel difference. (I would have never noticed without that screen capture and looking for it) Does it look like they become the same height when you zoom in?
It does indeed. It’s odd how it changes. I had thought of making the image just 1px high and seeing if I still had the problem, but I would like to understand what is happening…
Sometimes it does, and sometimes not. In this case, I will guess that the issue is being caused by rounding, because I do not see it from your site… just on the screen shot. Can you replace the image with a gradient or create another image that is twice those dimensions? The larger image should scale down smoothly on an Apple O/S monitor.
The image shouldn’t be being scaled. It’s just displayed as is (or should be). The width (280px) was chosen so it wouldn’t need scaling, even on an iPhone 4. The after pseudo element has a height of 22.4px on my machine, and I’m not aware how that comes about.
Hmmm. Thanks Ron. It’s getting weirder. That works fine with a height of 4px or even 3px, but I get the same problem if I set the height to 2px. Even resizing the image to 1px high doesn’t change it.
If I use the 1px high image with my original CSS the separators are all the same. The problem just seems to be with a height of 2px.
Does anyone else actually see the problem, in the live site?
To me the lines are the same, in 3 different browsers.
I only see it in the screen shot where it looks to be 1px bigger.
The first thing that comes to mind is that you don’t originally specify any height, which Ron has addressed.
If it’s only you seeing it, it may be a rounding issue specific to your video hardware.
I spent some time giving my best effort at reading documentation for ::after, content:, <img>, etc. and got a bit lost. The best I got from it is that ::after is not in the DOM, and the image is a replaced element subject to the sizing algorithm. I’m most unclear about the algorithm. Something like when there are intrinsic dimensions they are used within the constraints of their containing element and in the case of a pseudo element the constraints of the element that is in the DOM are used.
My guess was that (as Paul has posted) line height is involved with the computed values used to paint the image and as the line height changes it affects the images height.
It is very interesting, but gaining a deeper understanding of the workings probably has little value except for educational reasons. At least in cases where there are ways to force the dimensions and not rely on the algorithm.
Pseudo elements are display: inline by default, so will be affected by line height for their overall size.
This is why Paul overrides that with display: block and an explicit height.
And not only that, the <img> was removed from the content: property and was set up as background image.
Even if you have a pseudo block element you would still have line-height effecting it if you injected an inline <img> by way of content:" "; . As was seen in the code from post #1
The :before and :after pseudo-elements interact with other boxes as if they were real elements inserted just inside their associated element.
That means that we can style them as any other html element.
It’s not that “the constraints of the element that is in the DOM are used” , it’s the constraints that you set on the pseudo itself that get used.
A pseudo ::after element set as display:block;, with fixed width and heights set on it, could have content spilling out. If you set a height of 5px and then placed 1000 characters of text in the content property. It would overflow just as any other fixed height block element would. That is unless you set overflow:hidden on it.
So in a nutshell you can make a pseudo behave in the same manner as you can any div. You can only fill it with content via the content property though.
Unless your using them as counters, pseudo before and after are mainly used for decoration without needing to add extra markup in the html. They are still used a a float clearing method though.