Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Brian
Brian

Posted on

     

What do CSS right initial and right auto do?

Was doing code review today and saw some code that intrigued me.

.button {    position: fixed;    right: initial;}

Theright: initial was interesting I dug more into what initial does and found out it sets that attribute to what the browsers default settings is. There is a really good article oncss tricks about this.

So what is the initial value for the right attribute? I did some investigating and found out that the default value is auto (for chrome at least). That confused me because I always usedposition: fixed and then just positioned it wherever I wanted with the left, right, top, bottom. I never thought about what would happen if the right attribute was auto (which is it by default). I set up a code pen to demonstrate. What is interesting is when you scroll.

MDN describes what the right attribute does very well here.

"When position is set to absolute or fixed, the right property specifies the distance between the element's right edge and the right edge of its containing block."

Whenright: auto is set the browser will calculate what the right attribute needs to be set to so that the left side of the child element is right next to the left side of the parent element, because it is positioned fixed when you scroll you can scroll past the containing div but the positioning of the fixed element stays the same.

I hope that you learned something helpful alongside me today.

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
cameronapak profile image
cameronapak
I design, create, and maintain websites and apps, freely given, for people to connect with resources that point to God.

Thanks Brian!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Jesus Follower, Husband, Web developer, and gamer at heart. I love God, Family, and Technology
  • Location
    Oklahoma
  • Work
    Web Developer at Life.Church
  • Joined

More fromBrian

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp