CCS to position an HTML element to the left edge of window without 'absolute' or JS?

Описание к видео CCS to position an HTML element to the left edge of window without 'absolute' or JS?

Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram:   / ky.emrah  

Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!CCS to position an HTML element to the left edge of window without 'absolute' or JS?

On a static website (possible but not desirable to use JS), I've a blog with a column width (on 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.
width: 100vw;
w-screen
Left = -X px
Using Tailwind, or vanilla CSS, I've also tried transform: translateY(-25%);, but I still need to calculate the distance.
transform: translateY(-25%);
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;

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.)


Tags: css,tailwind-cssSource of the question:
https://stackoverflow.com/questions/7...

Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/

Комментарии

Информация по комментариям в разработке