html - Change top position based on width% -


i trying change navigation bar's position top of screen based on screen width. tried in css: top: 10%, based on height of screen not width.

is there way top: .1 * width?

quite overlooked vertical margin percentage properties of elements refer containing block's width, not horizontal ones.

that means if set margin-top:10%;, have top margin equivalent 10% of it's containing block's width.

you can see in jsfiddle. try resizing output panel vertically , horizontally, , note resize direction makes inner block move , down.

you can use vw , vh , if browser targets allowing, i'd recommend that. if can't use them, don't have use javascript right away. many people gun right away javascript when opens whole new can of worms (like, if browser resizes?), when bit of creative use of css can out of sticky spot anyway.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -