Functional CSS

The real way to scale css, is to stop writing css

Have you ever...?

An overwhelming majority of css you would need for your site has already been written

How does it look like?

const Card = ({ title, content }) => (
  <div className='flex flex-column border rounded max-width-1'>
    <img className='fit' src='' />
    <div className='p1'>
      <h2 className='h2'>{title}</h2>
      <p className='ml1'>{content}</p>
      <button className='btn btn-primary right'>Next</button>
    </div>
  </div>
);

Tools

Setup with React

PostCSS

const postcssImport = require('postcss-import');
const postcssCssnext = require('postcss-cssnext');

module.exports = {
  plugins: [
    postcssImport,
    postcssCssnext
  ]
};
postcss.config.js

Basscss

import React from 'react';
import ReactDOM from 'react-dom';
import 'styles/index.css';
// ...
src/index.js
@import 'basscss';

* {
  margin: 0px;
  padding: 0px;
}

html {
  height: 100%;
}
/* ... */
src/styles/index.css

Addons

@import 'basscss';
@import 'basscss-btn';

* {
  margin: 0px;
  padding: 0px;
}

html {
  height: 100%;
}

/* ... */
src/styles/index.css

Customizations

@import 'basscss';
@import 'basscss-btn';
@import './forms';
@import './colors';
@import './animations';
/* ... */

:root {
  --button-font-weight: normal;
  --button-background-color: #62b3d2;
}

* {
  margin: 0px;
  padding: 0px;
}

html {
  height: 100%;
}

/* ... */
src/styles/index.css

Pros & cons

Pros

Cons

Sources

Thanks!