-1

Similer to how you can write:

margin: 12px 8px 10px 8px;
//or
padding: 12px 8px 10px 8px;

is there a way to shorthand position properties?

//from    
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;

//to
position: absolute 0 0 0 0;

or something?

MDN doesn't seem to have anything, but it could be called something else or a different method entirely.

amflare
  • 4,020
  • 3
  • 25
  • 44

2 Answers2

1

No you can't shorthand position with other properties like top as they're separate properties entirely, unlike background with image and color for example. If you want to save on writing CSS, you could check out mixins in CSS preprocessors like Sass and LESS.

An example mixin in Sass:

@mixin border-radius($radius) {
  -webkit-border-radius: $radius;
     -moz-border-radius: $radius;
      -ms-border-radius: $radius;
          border-radius: $radius;
}

.box { @include border-radius(10px); }

The above is taken from the Sass Mixin Reference.

Obviously if you don't want to use a preprocessor, you'll just need to manually write it out every time you want to use those properties.

0

No, there is not.

Here is the current definition of the CSS Positioning Module Level 3: https://www.w3.org/TR/css-position-3/ - the document does not define any shorthand form for position and left, right, top, or down.

Dai
  • 141,631
  • 28
  • 261
  • 374