Header image in HTML won't stay in the same position in another computer #21483
-
Hello, I made this website with html the other day: https://ghiblimovs.herokuapp.com/ This is my html:
This is my css:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hello @micaelagimenez, The problem with absolutely positioned elements, is that, depending on the viewport and parent element, their positions can differ drastically, unless you have a bunch of media queries to correct those positions. What you’re attempting can be done without relying on position or transform. Here’s a few suggestions: .header
You could also put the image in the header as an .wrap
.searchTerm AND .searchButton
Here is the changed CSS:
The absolute position property is not all bad though, for example, if you have a For some more centering methods, check out this guide: Centering in CSS: A Complete Guide | CSS-TricksCentering things in CSS is the poster child of CSS complaining. Why does it have to be so hard? They jeer. I think the issue isn't that it's difficult to P.S. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for the detailed answer, it solved all the issues I had! I’ll remember it for the next time I write some css! P.S. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Hello @micaelagimenez,
The problem with absolutely positioned elements, is that, depending on the viewport and parent element, their positions can differ drastically, unless you have a bunch of media queries to correct those positions.
What you’re attempting can be done without relying on position or transform. Here’s a few suggestions:
.header
center
to thebackground
property; this will center the background on all devices.margin-right: 340px;
tomargin-right: auto;
, with left and right set toauto
, it’ll center the header on all devices.You could also put the image in the header as an
<img>
element, then set themax-width
on the image to 100% to resize the image on all d…