Skip to content

Component Scoped CSS

Daniel Puckowski edited this page Apr 2, 2023 · 1 revision

Scoped CSS

Sling.js version 15.0.0 supports scoped CSS for components.

Scoped CSS may be applied to a class by specifying a slStyle function which returns CSS.

Supported

Not Supported

class ExampleScopedStyleComponent {
    constructor() {
    }

    slStyle() {
        return 'div a[target="_blank"], nav { background-color: #cacaca; } kbd { background-color: #cacaca; }';
    }

    view() {
        return markup('div', {
            attrs: {
                'id': 'divslstyle4'
            },
            children: [
                markup('a', {
                    attrs: {
                        target: "_blank"
                    },
                    children: [
                        textNode('Styled a')
                    ]
                }),
                markup('nav', {
                    children: [
                        textNode('Styled nav')
                    ]
                }),
                markup('kbd', {
                    children: [
                        textNode('Tab')
                    ]
                })
            ]
        })
    }
}
Clone this wiki locally