Hi @vincent15000 you can add your combine your dynamic id with static class then you can concatenate function in CSS parts or you can do bootstrap classes for dynamic changes it easy for this if you want to use the first method then you have to use jquery and check the class have an even class or odd class then you can directly apply CSS using jquery.
How to set a background-color to a dynamically generated HTML tag in a component ?
Hello,
I need to generate dynamic CSS classes inside a component. Each class will have a color retrieved from the database (table states, field color). And theses colors can be modified of new states can be created. So in fact I need to generate as many classes as the number of states (each state has one color).
How is it possible to do that ?
What I have already tried to do :
- assign the color in a style attribute directly inside the HTML tag, but it's not possible because the HTML tag is dynamically generated by the CSS framework (Element-Plus)
- check the documentation to color the component, but UIkit doesn't give the possibility to color the component, so I have to find out how to do
To help understand, here is the written code.
<el-badge class="mf-badge" v-for="stat in student.sessions_statistics" :value="stat.count">
<el-button size="small">{{ stat.label }}</el-button>
</el-badge>
And here is the generated code.
<div class="el-badge mf-badge" data-v-22b2a284="">
<button class="el-button el-button--default el-button--small" type="button" data-v-22b2a284="">
<!--v-if-->
<!--v-if-->
<span>Réalisée</span>
</button>
<sup class="el-badge__content el-badge__content--primary is-fixed" style="background-color: green;">10</sup>
</div>
And I need to add a background color to the sup tag and the color is in the stat.color variable.
Thanks a lot ;).
Vincent
I had a project where we needed to get properties from a database and then generate css,
I ended up creating a style object and created the classes inside it
async function fetchPackings() {
let response = await getRequest('<url to fetch properties>');
let style = document.createElement('style');
let packClasses = '';
response.forEach(packing => {
packClasses += packing.PACKING_CLASSES + ' ';
});
style.type = 'text/css';
style.innerHTML = packClasses;
document.getElementsByTagName('head')[0].appendChild(style);
}
Please or to participate in this conversation.