What should production CSS look like? Share your layout-to-web workflow
Tags: discuss, beginners, css, sass
Published: 2019-01-10 17:00:47

---
title: What should production CSS look like? Share your layout-to-web workflow
published: true
description: How does I write good CSS?
tags: discuss, beginners, css, sass
cover_image: https://fattoush.net/f/attachments/2016/08/31/67_13643033_138421626587207_1848841378_N_-_Qu80_RT1600x1024-_OS1080x1080-_RD1080x1080-.jpg
---

When someone asks you to build a layout in HTML and CSS, how do you approach it? And how do you approach it in a test, versus working for production?

I've been interviewing, testing, and can't seem to figure out what the bar is. I have worked at places with long af .css sheets, and others with LESS compiled ones. Previously I based my ideas of how to write CSS on docs I had seen or glitch.com examples. I had also heard of the need to [modularize CSS](https://spaceninja.com/2018/09/17/what-is-modular-css/) for different components to make it more reusable and shorter, and thus easier to read.

How I do It: 
0. Make sure I've got prettier or a linter installed on VSCode.
1. Slice layout with guides in Photoshop, measure between elements
2. Decide which areas require grid and flexbox. 
3. Start new HTML doc, embed external CSS file, convert px to em, include 3 media queries OR prototype with tachyons or bootstrap
3. OR Include all interactions with vanilla JS or use a JS framework

Docs and library code looks really thorough (ie. media queries for small, medium, desktop screens), and so I try to mimic that. After getting some feedback I realize that I'm overcomplicating stuff and my CSS is disorganized. 

Here's some things I've gathered for improvement so far:

- if using grid, use `height: 100vh` to make the minimum height appear the height of the viewport
- apply style using classes with semantic names instead of IDs or elements (i.e. `.site_header` instead of `#header ul`)
- include cross-browser prefixes for any animations or exceptions (i.e. for drop-capitals in Safari or `webkit-` for Safari and `moz-` for Firefox and `ms-` for IE. Using an autoprefixer makes that easier.
- convert any sizes to `em` and `rem` instead of px
- Use grid or flexbox where available, always stick to a grid
- Write as little to accomplish the most as possible, detailing margin and padding on every little thing makes your styles confusing for someone else to read.
- To make everything show as the size it should in the design, use `*{box-sizing: border-box;}`
- Stay away from inline styling at all costs. 
- `float` as a positioning selector is a thing of the past.
- `!important` does not always fix a problem

I'm open to you challenging any of these since this is cobbled-together afterthought based on medium posts and observing glitch community examples

I also have some questions for devs:

1. What do you do about responsiveness for mobiles when you get one layout? I totally get clarifying with the designer about what the decisions around positioning and stacking order may be and communication is key.But in the test situation or working with freelance clients who don't always know what they want, what do you usually do? I default to a hamburger menu with a slide/dropdown.

2. Any particular choice on grid (4, 10 or 12 columns. 30em, 40em) ?
I'm really tempted to use exact pixels on a smaller number of columns to make it match the desktop version as much as possible but ultimately I'm really confused about this. I've also seen grid layouts with the smallest grid item repeated 9 times... I suppose it depends on the design. 

3. How many media queries do you include? How do you decide where the breakpoints are?
I have seen totally functional examples with folks writing for only one screensize (400px or 768px). Is that enough?

4. Any opinions on using CSS vs JS for animations?

5. At what point do you see it necessary to use SASS or LESS? Is BEM still a thing?

Annnd... while it is my life goal to be really good at JS, I can't help being curious. I've discovered CSS is something I'm prone to think it's easy to be good at, but actually full of so many specifics. 
... any other thoughts or crits are much appreciated! Thank you for reading!

Update: Just discovered Jen Simmons' Layout Land series on YouTube and added a link to that because she's so great at explaining the differences and pros/cons to CSS grid/flexbox

Some other sources I'd been reading over the last few years:
[Simplify Styling with Functional CSS | Rangle.io](https://blog.rangle.io/styling-with-functional-css/)
[Common responsive layouts with CSS grid and some without | Medium](https://medium.com/samsung-internet-dev/common-responsive-layouts-with-css-grid-and-some-without-245a862f48df)
[Beginner's Guide to Choose Between Grid and Flexbox | Medium ](https://medium.com/youstart-labs/beginners-guide-to-choose-between-css-grid-and-flexbox-783005dd2412)
[CSS Grid Starter Layouts | CSS-Tricks](https://css-tricks.com/snippets/css/css-grid-starter-layouts/)
[Holy Grail Layout CSS Grid](https://bitsofco.de/holy-grail-layout-css-grid/)
[In Simple Terms: CSS vs Javascript](https://hackernoon.com/in-simple-terms-css-vs-javascript-abc9d709399d)
[Myth-busting CSS Animations vs Javascript] (https://css-tricks.com/myth-busting-css-animations-vs-javascript/)
[Flexbox vs. CSS Grid — Which is Better? | Jen Simmons for LayoutLand on YouTube](https://youtu.be/hs3piaN4b5I)