cup_of cup_of - 1 year ago 41
CSS Question

Possible to "cancel" out left/right css?

Hello I have a div that is positioned absolute and gave it a left position. For desktop it is necessary to have the left position of 100px, but for tablet I want to push it all the way to the right. To achieve this I tried doing

right: 0
but since
left: 100px
is already defined in the css, the
right: 0
does not push it all the way to the right as intended. Then I tried doing
left: 0
in tablet to cancel out the effect that it has but that didnt work either. Is there a way to cancel out the left position? Something like
left: none
(I know that does not work but its the only way I am able to explain this)

Desktop CSS:

.mydiv {
positon: absolute;
left: 100px;

Tablet CSS:

@media (max-width:768px){
.mydiv {
left: 0;
right: 0;

I could do something like
right: 400px
to get it to the position that I want but I am just curious if there is a way where I can use
right: 0
so I know for sure that it is pushed totally to the right.


Answer Source

To reset the left property use

left: auto;

You can use CSS reference to get initial values of CSS properties. For example here is the reference for the left property: