I am the type of person who likes to do a lot of projects, especially when it comes to JavaScript only, as this is my forte.
I thought of a little funny idea. Writing small CSS snippets using JavaScript. These parts of CSS can then be used on Blob or implemented on a web page differently.
Most of the time, I do projects just for FUN and for build up in experience.
Let us get more from what we work with. One of these JavaScript style sheets might look like this:
var sheet = {
"h1": {
"font-size": "24px",
"color": "blue",
children: {
"a": {
"font-size": "15px"
}
}
},
"a": {
color: "red"
}
};
This will return:
h1{font-size:24px;color:blue}h1 a{font-size:15px}a{color:red}
Pay attention to the property childrenin the element h1.
This is my way of nesting when creating h1 a.
My question, however, is how can I create continuous nesting so that in the end I can get something like:
"h1 div span a"
, children.
script ( sheet).
var to = "";
for (var el in sheet) {
var props = [];
for (var prop in sheet[el]) {
if(prop != "children") {
props.push(prop + ":" + sheet[el][prop]);
}
}
to += el + "{" + props.join(";") + "}";
if (sheet[el].children) {
for (var el2 in sheet[el].children) {
var props = [];
for (var prop in sheet[el].children[el2]) {
props.push(prop + ":" + sheet[el].children[el2][prop]);
}
to += el + " " + el2 + "{" + props.join(";") + "}"
}
}
}
- , .
, . , .
: http://jsfiddle.net/shawn31313/2tfnz/1