Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do CSS functions exist?

Tags:

css

I'm not sure what to call this, but basically let's say I have a style that I use a lot,

.somepattern{
    font-size:16px;
    font-weight:bold;
    border:2px solid red;
}

but sometime I want to change the font-size and the color for border. Is it possible to treat this code as a library, where I can set the style to a div

<div class="somepattern">Text</div>

but still control the 16px and red like we do with functions?

like image 811
zmol Avatar asked Feb 06 '11 16:02

zmol


People also ask

Are there functions in CSS?

Introduction. Like any other programming language, CSS has functions. They can be inserted where you'd place a value, or in some cases, accompanying another value declaration. Some CSS functions even let you nest other functions within them!

Can we call a function from CSS?

No, you can't trigger JavaScript from CSS directly.

What do you understand by CSS functions?

CSS. Code used to describe document style. General-purpose scripting language. Protocol for transmitting web resources.

Which function does not belong to CSS?

The :not() property in CSS is a negation pseudo class and accepts a simple selector or a selector list as an argument. It matches an element that is not represented by the argument. The passed argument may not contain additional selectors or any pseudo-element selectors.


1 Answers

I know I'm late to the party but the selected answer IS NOT the right answer since it's deferring it to CSS preprocessors.

To answer the specific question "Do CSS functions exist?", the answer is: Yes.

However, CSS functions work completely different than the OP's concept initially is.

cuixiping's answer seems the most correct answer.

Examples of CSS functions are:

  • url()
  • attr()
  • calc()
  • rotate()
  • scale()
  • linear-gradient()
  • sepia()
  • grayscale()
  • translate()

A detailed, comprehensive list can be found here:

CSS functions on MDN Updated link 18/9/20

like image 51
Ricardo Zea Avatar answered Oct 13 '22 12:10

Ricardo Zea