On a static website (possible but not desirable to use JS), I’ve a blog with a column width of a large screen of maybe 50% for easy reading.
But then I have a large picture (actually it’s an interactive object) with lots of detail that would be great occupying (nearly) the full width of the screen.
width: 100vw;
(or w-screen
in Tailwind) is great, but the left edge of the picture is in line with the parent. Specifying relative positioning, I can force the picture to the left using Left = -X px
, but the distance X varies, so won’t work without JavaScript.
Using Tailwind, or vanilla CSS, I’ve also tried transform: translateY(-25%);
, but I still need to calculate the distance.
Absolute positioning is great, but the remainder of the blog doesn’t flow around the picture.
Fixed positioning doesn’t work either as the picture should scroll with the rest of the text.
So, I think I’m left with Javascript:
document.getElementById("myElementId").style.Left =
-document.getElementById("myElementId").getBoundingClientRect().left;
Any other ideas? (I would have thought my issue wasn’t that unusual, but haven’t seen any clean solutions.)
2
Answers
Whoever edited my original question: I find it unhelpful - to the community - to remove my best suggestion, as it could be useful for others, and it certainly had flaws so wasn't a 'true' solution, but was a effective hack or kludge, a quick fix.
So for other's use, another approach is to create a similar item to the 'absolutely positioned' image but put the absolute one at a higher Z-index. 2 lines & pretty clean, works regardless of your current theme, it's just inelegant:
You need to know the distance between the image’s left edge and screen’s left edge, so try putting everything that stand between them to variables and use
calc
totranslate
the image.