At it's simplest, a style object is an object of CSS properites and values. For ease of use, CSS property names are camel-cased.
const button = css({
backgroundColor: 'gainsboro',
borderRadius: '9999px',
fontSize: '13px',
border: '0',
})
.button {
background-color: gainsboro;
border-radius: 9999px;
font-size: 13px;
border: 0;
}
Hypergood CSS converts numeric values to px
, if the CSS property doesn't
accept unitless values.
const button = css({
backgroundColor: 'gainsboro',
borderRadius: 9999,
fontSize: 13,
border: 0,
})
.button {
background-color: gainsboro;
border-radius: 9999px;
font-size: 13px;
border: 0;
}
const button = css({
':hover': {
backgroundColor: 'lightgray',
},
})
.button:hover {
background-color: lightgrey;
}
const button = css({
'::before': {
content: `''`,
display: 'block',
backgroundImage: 'linear-gradient(to right, #1fa2ff, #12d8fa, #a6ffcb)',
position: 'absolute',
top: '-3px',
left: '-3px',
width: 'calc(100% + 6px)',
height: 'calc(100% + 6px)',
borderRadius: 'inherit',
zIndex: -1,
},
})
.button::before {
content: '';
display: block;
background-image: linear-gradient(to right, #1fa2ff, #12d8fa, #a6ffcb);
position: absolute;
top: -3px;
left: -3px;
width: calc(100% + 6px);
height: calc(100% + 6px);
border-radius: inherit;
z-index: -1;
}
const button = css({
'.custom-class': {
boxShadow: '0 0 0 3px blueviolet',
},
})
.button.custom-class {
box-shadow: 0 0 0 3px blueviolet;
}
In addition to the class selector, you can style all other available basic selectors such as ID selectors, attribute selectors, universal selectors, and type selectors.
const button = css({
'[data-pressed]': {
boxShadow: '0 0 0 3px royalblue',
},
})
.button[data-pressed] {
box-shadow: 0 0 0 3px royalblue;
}
const button = css({
'svg': {
display: 'inline-block',
verticalAlign: 'bottom',
height: '13px',
marginLeft: '5px',
},
})
.button svg {
display: inline-block;
vertical-align: bottom;
height: 13px;
margin-left: 5px;
}
const button = css({
'& + button': {
marginLeft: '10px',
},
})
.button + button {
margin-left: 10px;
}
You can create any combination of selectors using the &
character.
const button = css({
'@media (prefers-reduced-motion)': {
transition: 'none',
},
})
@media (prefers-reduced-motion) {
.button {
transition: none;
}
}
const button = css({
'@supports (display: grid)': {
display: 'grid',
},
})
@supports (display: grid) {
.button {
display: grid;
}
}