I have a React component called "ExplanationLists", I would like to add dynamic inline style into li
html element with css pseudo code li::after
, the way I can style the bullet-point with graphic better. For example,
li::before {
content: dynamic_content;
}
However, I couldn't really make it happen. Any suggestion would be appreciated.
Below is the code I've written.
class ExplanationLists extends Component{
populateHtml(){
// asign lists data into variable "items"
var items = this.props.items;
// loop though items and pass dynamic style into li element
const html = items.map(function(item){
var divStyle = {
display: "list-item",
listStyleImage:
'url(' +
'/images/icons/batchfield_fotograf_rosenheim_icon_' +
item.icon +
'.png' +
')'
};
// html templating
return (
<li style={divStyle}>
<h3 >{item.title}</h3>
<p>{item.desc}</p>
</li>
);
});
// return html
return html;
}
render(){
return (
<ul>
{this.populateHtml()}
</ul>
)
}
}
Refer to this link .
"&::before": { ...react style here }
content: `''`
example:
content: {
display: "flex",
margin: 10,
"&::before": {
content: `''`,
position: 'absolute',
left: '-50px',
top: '50px',
width: '0',
height: '0',
border: '50px solid transparent',
borderTopColor: 'red',
}
},
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With