Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS shorthand for positioning

There are any shorthand for top right bottom left or for width and height ?

I have a lot of css like this

#topDiv {     position:absolute;     top:0px;     left:0px;     right:0px;     height:100px; } #centerDiv {     position:absolute;     top:100px;     bottom:120px;     left:0px;     right:0px; } #consoleDiv {     position:absolute;     left:0px;     right:0px;     bottom:0px;     height:120px; } 

I would like to do anything like this

position: absolute 10px 50px 50px 100px; 

or

size: 400px 200px;  
like image 817
Vitim.us Avatar asked Jun 01 '12 18:06

Vitim.us


People also ask

How do you give a position in CSS?

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element. A fixed element does not leave a gap in the page where it would normally have been located.

What are positioning types in CSS?

Positioning types in CSS are Static, fixed, absolute.

What is a CSS shorthand?

What is CSS shorthand? CSS shorthand is a group of CSS properties that allow values of multiple properties to be set simultaneously. These values are separated by spaces. For example, the border property is shorthand for the border-width, border-style, and border-color properties.

What is CSS positioning of element?

The position CSS property sets how an element is positioned in a document. The top , right , bottom , and left properties determine the final location of positioned elements.


2 Answers

2021 Update: The inset property is currently gaining adoption. This property uses the same multi-value syntax as the shorthand margin property. For browser compatibility, please see MDN.


No short-hand exists to combine all of these values. These are all different properties, unlike, for instance background, which has colors, images, positions and repeat instructions and as such can be coalesced into a short-hand form.

If you really wanted this type of control, you could use something like SASS and create a mixin.

like image 53
Sampson Avatar answered Sep 23 '22 22:09

Sampson


I just found this, was looking for the same, I ended up using sass for top, bottom, left, right

here is my solution

@mixin position($top, $right: $top, $bottom: $top, $left: $right) {     top: $top;     right: $right;     bottom: $bottom;     left: $left;  } 

works like most css shorthands

@include position(5) // all 4

@include position(5,4) // vertical, horizontal

@include position(5,4,3) // top, horizontal, bottom

@include position(5,4,3,2) // top, right, bottom, left

like image 36
Adam Sparks Avatar answered Sep 22 '22 22:09

Adam Sparks