Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set all offset sides in CSS at once?

Tags:

html

css

Instead of having:

right:0px;
left:0px;
top:0px;
bottom:0px;

Can I have something like this?

sides:0px;
like image 958
ispiro Avatar asked Jul 24 '12 14:07

ispiro


People also ask

How do you make a border offset in CSS?

The outline-offset property adds space between the outline and the edge or border of an element. The space between an element and its outline is transparent. Outlines differ from borders in three ways: An outline is a line drawn around elements, outside the border edge.

What does outline-offset do in CSS?

The outline-offset CSS property sets the amount of space between an outline and the edge or border of an element.

What is the default value of offset in HTML?

By default, the offset value is applied to all record types with a current offset value of zero.


2 Answers

No, there does not exist a shorthand sides property for setting the offsets. You have to set them all separately.

There are shorthands for other kinds of properties that involve the sides of a box, e.g. margin, padding and border, but not for the positional offsets top, right, bottom and left.

like image 125
BoltClock Avatar answered Sep 29 '22 11:09

BoltClock


If you're using a preprocessor such as LESS or Sass, then yes, you can. If you're using vanilla CSS, then no, not yet.

Example in LESS

.sides (@length) {
  top: @length;
  bottom: @length;
  left: @length;
  right: @length;
}
div {
  .sides(0px);
}

Example in Sass

@mixin sides($length) {
  top: $length;
  bottom: $length;
  left: $length;
  right: $length;
}
div {
 @include sides(0px);
}
like image 38
0b10011 Avatar answered Sep 29 '22 12:09

0b10011