Style json with css

Implement CSS styling according to JSON data

To apply a required style to an element in the DOM, first locate the element that contains the desired text and then apply the style. If you already know where to add the style at the DOM level, you can call it as shown in the HTML and TypeScript examples. One possible solution to target specific cells is to filter the inputs and select their parent elements, as shown in the HTML example. If the row numbers are in an array, you can filter them and select their parent elements. Instead of creating dynamic classes, you can also add attributes to the elements and select and filter them using jQuery. While there may be a better way to structure this, the above changes would allow you to target the desired cells.

Apply CSS style based on JSON value

Attempt utilizing the dynamic binding of CSS classes in Angular.

The CSS class with the background color identified as Red is referred to as redBackground .

To achieve the desired style, make use of ElementRef. Locate the element in the DOM that contains the necessary text and apply the appropriate style as shown in the example.

 this.el.nativeElement.getElementsByClassName("k-grouping-header")[0].style.display = "block"; 

If you are aware of the location in the DOM where you need to apply the styling, you may use the following syntax.

private setStyles(): any < let styles = < 'font-size': '10px' >; return styles; > 

JSON Introduction, JSON is a lightweight data-interchange format. JSON is plain text written in JavaScript object notation. JSON is used to send data between computers. …

Читайте также:  Запрос через прокси python

How to add css to json response

function hasClass(element,clss) < return element.className.match(new RegExp('(\\s|^)'+clss+'(\\s|$)')); >function addClass(element,clss) < if (!this.hasClass(element,clss)) element.className += " "+clss; >BCL.onPlaylistSelect = function(something, element) < element.addClass("myClass"); //do stuff >; BCL.onSearchResponse = function(jsonData) < BCL.jsonData = jsonData; var str = ""; var html = ""; for (var i = 0; i < jsonData["items"].length; i++) < var playlist = jsonData["items"][i]; html = ""; str += BCL.markup(html,playlist); >str += "
>
"; //console.log(str); document.getElementById("results").innerHTML = str; // load the first playlist BCL.onPlaylistSelect(0); >;

JSON for Beginners – JavaScript Object Notation, JSON ( J ava S cript O bject N otation) is a text-based data exchange format. It is a collection of key-value pairs where the key must be a string type, …

How to add/insert json data[0] etc to/in jquery $(‘td’).css?

There may be a more effective approach to this structure, but a small modification to your current method will allow you to access those cells.

Please note that the class no longer has a row ID associated with it in HTML.

// Access *all* of them var allTransationPartnerCells = $("td.vtransaction_partner_name_td"); // Or access the one for a specific row var justOneCell = $("#transaction_partner_name" + someRowNumber) .closest("td.transaction_partner_name_td"); 

Perhaps the class is unnecessary in the final example.

// Access the one for a specific row var justOneCell = $("#transaction_partner_name" + someRowNumber) .closest("td"); 

If data represents an array of row numbers, it is possible to filter the inputs and choose their respective parent td elements.

$('input[name="transaction_partner_name[]"]').filter(function() < // Check existence of the numbers var n = + this.id.replace('transaction_partner_name', ''); return $.inArray(n, data) >-1; >).parent('td') .addClass('borderBottom'); 

Instead of using creating dynamic classes to select and filter elements, you have the option of adding data-* attributes to td elements. Afterwards, you can use the jQuery .data() method.

$('td.transaction_partner_name_td').filter(function() < return $.inArray( $(this).data('id'), an_id_array ) >-1; >).addClass('borderBottom'); 

CSS Backgrounds, The CSS background properties are used to add background effects for elements. In these chapters, you will learn about the following CSS background properties: …

Читайте также:  Java throw throwable exception

Источник

JSON in CSS

Jonathan Neal tweeted a heck of a little CSS trick the other day, putting JSON inside CSS and plucking it out with JavaScript. Valid values for custom properties are quite liberal! So this looks for a CSS rule (e.g. a whole block, like #x < y: z; >where the cssText starts with — (which is not a valid selector, but who cares — you could change it if you want to thisIsJson or something) and then slices out a string that JSON.parse() works on. I re-typed his example here:

Is this useful? WELL. Probably not, like, on a daily basis. But remember that JSONP is still a thing because CORS exists. Chucking some JSON in CSS I would think is another way around CORS. I kinda doubt it will catch on, but it’s possible. Remember not long ago we were talking about using CSS as an API for literal data. Another questionable idea. 😉 I think “putting weird stuff in custom properties” is the new “putting weird stuff in CSS content.” For example, ya know how there are media queries in JavaScript, à la matchMedia ? And, of course, there are media queries in CSS, too. There was a time (and I’m not sure it’s passed) where defining those media queries only once felt like a good idea, so we weren’t maintaining media queries in multiple places. To keep them “in sync” one idea was to define them in CSS and have them swap the value of some CSS content (e.g. @media (max-width: 500px) < body::after < content: "max500"; display: none; >> ) then literally watch for that content to change with JavaScript — and you’d know that media query was active. For real! No joke! And speaking of JSON in CSS, you can chuck straight-up JavaScript in there as well. This isn’t as clever as Jonathan’s extraction because it just yanks the value out and eval s it.

Читайте также:  Material design icon css

Источник

CSS JSON

Cascading Style Sheets (CSS) is a simple mechanism for adding style (e.g. fonts, colors, spacing) to Web documents. JSON (JavaScript Object Notation) is a lightweight data-interchange format. CSS may easily be expressed in JSON notation (CSS JSON). CSS JSON is a powerful and flexible approach allowing for inheritance and logical constructs within CSS.

CSS JSON Structure

Converting CSS JSON to CSS Text with JavaScript

var cssjson = < "selector-1":< "property-1":"value-1", "property-n":"value-n" >> var styleStr = ""; for(var i in cssjson) < styleStr += i + " styleStr += ">\n" >

The above example returns the following CSS text format:

Extending CSS with CSS JSON

Custom selector property/values can be used in CSS JSON as a mechanism to extend CSS. CSS text pre-processing is possible through the mapping of a specfied property to a conditionally executed parsing routine.

CSS Selector Inheritance with CSS JSON and JavaScript

A CSS selector may be inherited within another selector using CSS JSON.

var cssjson = < ".copy-1":< "font-family":"Verdana, Geneva, Arial, Helvetica, sans-serif", "font-size":"11px", "color":"#CCC" >, "div#container div#header": < "CSSJSON-INHERIT-SELECTOR":".copy-1", "position":"absolute", "top":"12px", "left":"4px" >> var styleStr = ""; for(var i in cssjson) < styleStr += i + " >else < styleStr += "\t" + j + ":" + cssjson[i][j] + ";\n" >> styleStr += ">\n" >

The above example returns the following CSS text format:

.copy-1 < font-family:Verdana, Geneva, Arial, Helvetica, sans-serif; font-size:11px; color:#CCC; >div#container div#header

CSS JSON Using Other Processing Languages

CSS JSON Implementations

Alternative CSS Data Serialization Formats

Источник

Оцените статью