Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shorthand to set height and width of an element in CSS

Tags:

html

css

sass

Basic question but I can't find it anywhere, is it possible to set the width and the height on the same line at the same time with the same value in my CSS?

I'm not asking for something like:

width:100%;height:100%;

But more like one of those:

width, height: 100%; // Same for both
width, height: 100%, 90%; // Different for each ones
dimensions: 100% 90%; // Like padding/margin, 

I'm just asking about declaration, not Javascript on how to do that. I found a related question to this one but for border and the short answer was no.

If it's not possible with CSS, is it with SCSS ?

like image 621
ZazOufUmI Avatar asked Aug 06 '15 08:08

ZazOufUmI


People also ask

What CSS property is used for setting the height of an element?

The height CSS property specifies the height of an element. By default, the property defines the height of the content area. If box-sizing is set to border-box , however, it instead determines the height of the border area.

How do I change height and height of screen in CSS?

Syntax: To set a div element height to 100% of the browser window, it can simply use the following property of CSS: height:100vh; Example: HTML.

How do you create shorthand properties in CSS?

CSS Border - Shorthand Property To shorten the code, it is also possible to specify all the individual border properties in one property. The border property is a shorthand property for the following individual border properties: border-width. border-style (required)


1 Answers

You can set up Sass Mixin, like this:

@mixin size($width, $height) {
  width: $width;
  height: $height;
}

Then write just:

@include size(100%, 100%);
like image 189
Allrightman Avatar answered Sep 28 '22 08:09

Allrightman