ubio / css

ubio CSS Framework
https://ubio.github.io/css
0 stars 0 forks source link

Initial work on v2.0 Typography and Button styles #15

Closed mrkrsl closed 5 years ago

mrkrsl commented 6 years ago

First steps at a broader approach to common styles. Contains a set of flat files and some (possibly questionable) selector naming.

https://github.com/universalbasket/css/issues/5

muzafarova commented 5 years ago

One comment on naming in CSS

There are 2 main approaches to CSS: traditional semantic markup and BEM (Block__Element--Modifier). We use BEM and I want to explain why.

1) But first.. Traditional semantic markup

TL; DR; in order to ship fast an be able to frequently re-do HTML+CSS markup people invented BEM

2) BEM (Block__Element--Modifier)

Take this markup as an example

input.css, group.css
<div class="input-group">
    <label class="label--left" for="[id]">[…]</label>
    <input id="[id]" placeholder="Text">
</div>

image

1) class name is .input-group so css file that contains this code should be called "input-group.css", according to BEM this is Block name (it consists of 2 words so they are - separated, this is fine)

2) each child (Element) of the block, according to BEM, should start with the same Block name (as a prefix) e.g. it could be .input-group__input where input-group part is "block", input part is "element. __ is a separator between Block and Element.

3) Looking at UI here we have 2 tasks to address: 1. style UI form elements (label and input) 2. line them up as a row, align vertically to centre or baseline

3.1) label is label, input is input. We can think of these 2 as independent Blocks (.label .input) and this works fine, but probably this blocks are too granular. Plus to that, they usually come together (at least label can't live on it's own) so we mentally group them for example as .form-input block, that contains label .form-input__label and field .from-input__field. Here input tag is referred as .form-input__field and we can think of possible modifiers for the field, e.g make it wide, big, 100% width, no-border e.t.c. Using Modifier .input-form__label--200, we can define label width (CSS looks like width: 200px, text-overflow: ellipsis e.t.c to we think of the case when actual text is longer than 200px and it will be truncated using "…")

3.2) to line things up we now have Grid in CSS so here we have even more options

3.2.1) modify Block e.g as

3.2.2) by looking at our UI we know that there is a frequent task to just put controls in the row one after another, and align properly; SO there can be an another Block dedicated to solve alignment problems, not necessary controls related, anything, e.g navigation items, breadcrumbs and so on: we often need to group things and line then up. We could think of a Block like .block and provide it with bunch of modifiers regulating space between elements, flow direction, line wrapping and the most importantly: alignment. If we have a Block like that, same HTML could use it together with .form-input specific styles as: .block.block--column.form-input

form-input.css
<div class=block block--column block--gap--small form-input form-input--error">
    <label class="form-input__label" for="[id]">[…]</label>
    <input class="form-input__field" id="[id]" placeholder="Text" type="text">
</div>

.block adds css grid .block--column changes elements flow from top to bottom .block--gap--small (modified modifier) adds gap--small sized spacing between cells of the grid .form-input (can do nothing, in this case, we can omit it and specify form-input--error alone .form-input--error adds pink background to the whole block in case of error