Answer the question
In order to leave comments, you need to log in
Passing parameters to css from Json?
Good afternoon!
Please tell me, I am reading width, height parameters from JSON.
How can I pass these parameters to CSS?
example:
{
"global": [
{
"id": "1",
"width": "50",
"height": "150"
},
{
"id": "2",
"width": "150",
"height": "350"
},
{
"id": "3",
"width": "750",
"height": "850"
}
]
}
.Layer + id{
width: px; /* Ширина блока вставить из того что я считал */
height: px; /* Высота блока вставить из того что я считал*/
}
<button style="height: px;width: px"></button>
Answer the question
In order to leave comments, you need to log in
const all = {
"global": [
{
"id": "1",
"width": "50",
"height": "150"
},
{
"id": "2",
"width": "150",
"height": "350"
},
{
"id": "3",
"width": "750",
"height": "850"
}
]
};
for(item of all.global){
let elm = document.querySelector('.layer' + item.id);
elm.style.width = item.width + 'px';
elm.style.height = item.height + 'px';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question