[TypeStyle] Style CSS pseudo elements with TypeStyle

Just like pseudo-classes, pseudo-elements are added to selectors but instead of describing a special state, they allow you to style certain parts of an element.

In this lesson we show how you can insert new content into the DOM using CSS pseudo elements. We also cover using other pseudo element selectors to change default browser behaviors.

import { style, media } from 'typestyle';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

const fontSize = (value: number | string) => {
    const valueStr = typeof value === 'string' ?
                     value :
                     value + 'px';
    return {
        fontSize: valueStr
    }
};
const className = style(
    {
        color: 'red',
        transition: 'font-size 0.2s',
        $nest: {
            '&::after': {
                content: `' Type after'`
            },
            '&::selection': {
                backgroundColor: 'black',
                color: 'gold'
            }
        }
    },
    media({maxWidth: 700, minWidth: 500}, fontSize(20)),
    media({minWidth: 701}, fontSize(30)),
    media({maxWidth: 499}, fontSize(15))
);

ReactDOM.render(
    <div className={className}>
        Hello Typestyle
    </div>,
    document.getElementById('root')
);
原文地址:https://www.cnblogs.com/Answer1215/p/6946588.html