Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a new css property?

Tags:

css

Is it possible to create a new property in CSS? For example, say you're developing a control that displays a photo and you want to add a property to css to control what style frame to have around the photo. Something like:

#myphoto { frame-style: fancy }

Is there some way to do this in a cross browser compatible manner, and how would you define whether the style inherits or not?

EDIT: It's a custom control - your JS code would deal with the style - I'm not expecting the browser to magically know what to do. I want the user to be able to style the control with CSS instead of JS.

like image 706
dan gibson Avatar asked Apr 26 '11 08:04

dan gibson


People also ask

Can we change CSS properties?

If you want to change the CSS styles dynamically you'll have to attach this portion of code to some event. For example, if you want to change the styles of your element when clicking on a button, then you have to first listen to the click event and attach a function containing the previous code.

How many CSS properties are there?

W3Schools lists 228 of them.

How will you declare a custom property in CSS?

The @property “at-rule” in CSS allows you to declare the type of a custom property, as well its as initial value and whether it inherits or not.


2 Answers

Sure, why not. Check this out as an example: http://bililite.com/blog/2009/01/16/jquery-css-parser/

You may also be able to get away with using CSS classes instead of properties. Not sure if that works for what you're doing.

like image 103
Jordan Avatar answered Oct 10 '22 06:10

Jordan


You can't. Browsers interpret CSS based on how their layout engines are coded to do so.

Unless you took an existing open source engine like WebKit or Gecko, added custom code to handle your custom CSS and made a browser that used your customized layout engine. But then only your implementation would understand your custom CSS.

Re your edit: it'd depend on whether you're able to read that style somehow. Typically browsers just instantly discard any properties they don't recognize, and CSS is not normally reachable by JavaScript because CSS code is not part of the DOM.

Or you could look at Jordan's answer.

like image 28
BoltClock Avatar answered Oct 10 '22 06:10

BoltClock