Zachscs
Zachscs

Reputation: 3663

Reduce width and height of any element of a certain class with CSS

It there a way to reduce the width and height of an element based on its CSS class by a fixed number. So for example if I have a div, and I apply a class to it, can I reduce the width by x and height by x? i.e.:

.slight-reduction {
    width: previousWidth - 2px;
    height: previousHeight -2px;
}

Is it possible to do this in CSS? How do you do it if it is possible?

Upvotes: 1

Views: 358

Answers (1)

Rob
Rob

Reputation: 15160

Not quite what you are asking for but sort of. You can use calc(); function in CSS to accomplish, perhaps what you want.

div {
    height:calc(100% - 300px);
}

It's not possible to obtain any previous width as you show in your question using CSS and the second value must be a unit of some kind, such as px.

Note the spacing before and after the subtraction operator. That needs to be there.

Further info

Upvotes: 1

Related Questions