CSS Reactions

A postmodern modular front-end web development approach that is based on an extrapolation of the W3C Visual Formatting Model and expressed in object orientated and function orientated naming conventions.

ver

1.1.0

10 March 2018

Postmodern Modular Front-end Web Development

Front-end web developers should focus on engineering unique variations of compatible, reusable and useful HTML structures and spend less energy confusing the ideologies of data management techniques with the fundamental principles and rules of the language being managed. Authoring coherent, consistent and organised code is important. It is important to those who share a similar perception of it.

CSS already exists.

Dashboard Template

A template that demonstrates the use of this naming pattern.

Standalone Template

A template that contains a 40Kb minified version of the CSS framework.

Pattern Library

Documentation and examples of the naming pattern

Development

Ordinarily, development can be defined as, "a state of constant growth or advancement", however the meaning is distorted by the words "growth" and "advancement" as they trigger subjective emotional responses. From a linguistic perspective the word "development" is similar to a homonym in that it can be defined either as an event or a process. In the context of this discussion, development is defined as a process that consists of multiple events.

Front-end web development

The way in which CSS is used and how it is applied, is being questioned in the context of the "evolution of styling in JavaScript", indicating a postmodern stage of development. Authoring reusable code in the format of 'modular CSS' within component based web applications, is currently a popular approach to front-end web development.

Linear thinking

A mechanistic scientific view is an analytical, reductionist and linear-causal paradigm, in which the observed phenomenon is broken into parts, isolated from the whole and examined separately. Event orientated thinking interprets data by the causal chain of events, for example A B . From this perspective, event [ A ] is the root cause of [ B ] .

Systems thinking

Systems theory is a conceptual framework that can be used to explain and understand the complex interrelationships and interdependence of components that form a functioning whole. A system consists of a group of components that collectively represent an environment known as an interface, a user interface (UI) is an environment intended for user interaction. A systems view opposes the reduction of systems and criticizes the mechanistic scientific view. The totality, complexity and dynamics of a system are instead, emphasized. Systems thinking interprets data as a series of feedback loops, as all elements are perceived as interconnected in a pattern of complex relationships that can be non-intuitive and non-linear. Removing [ A ] could result in the system replacing it with [ C ] resulting in C B = - A

Page based design

The method of page based design is a standard approach to front-end web development, however it is not scalable. This type of design adopts a particular perception: a web application is perceived as a collection of interconnected pages, each serving as the context for a particular set of components.

Component based design

Object Oriented Programming (OOP) introduced the concept of organised data structures as the basis of application development. "Object design is the drawing of boundaries between the logic of our application, and how we can then envisage the interaction of such logic." This type of thinking setup the conditions for a new perception to emerge: a web application is a system of interconnected components.

The Naming Pattern Continuum

Function Object Orientated

FOO

Object Orientated

OO

Function Orientated

FO

A naming pattern is a multidisciplinary data management technique. Object orientated and function orientated naming patterns are positioned at opposites ends of a continuum. Object orientated class names are based on content type and function orientated class names are defined in isolation.

Object Orientated

The BEM naming methodology is a popular content dependant object orientated CSS naming pattern. A BEM block level class derives its name from the content-type it expects to contain or be contained within. Element and modifier classes are prefixed with the parent block class name, thus forming a naming dependency that restricts adaptability and re-usability. The need to author new object orientated classes arises when changes to the HTML are required. BEM components are described using three entities...

block __element --modifier .menu .menu__item .menu__item--link <div class="menu"> <span class="menu__item"> <a class="menu__item menu__item--link"> ... </a> </span> </div>

Function Orientated

Function orientated naming patterns are content independent, as classes are named in isolation of an environment. A function orientated class name can be derived from a single property and its value. The class name describes itself and answers the question, "what does it do?". Function orientated stylesheets only need to be authored once, as function orientated classes are immortal.

.width-90-perc { width: 90%; } .width-80-perc { width: 80%; } .width-70-perc { width: 70%; }

Function Object Orientated

Function orientated and object orientated naming patterns should be integrated in a multi-class syntax. In terms of the cascade, function orientated classes should have greater specificity and precedence over object orientated classes. Object orientated naming patterns such as BEM establish a directional relationship between HTML and CSS. Components made up of object orientated classes are reusable, however the object orientated classes are not. Function orientated classes can extend existing components, allowing one to develop variations of a component without the need to author new styles. Authoring Function Object Oriented 'multi-class' HTML establishes the conditions for code re-usability.

<div class="menu"> <span class="menu__item width-100-perc"> <a class="menu__item--link width-50-perc"> ... </a> </span> </div>

The focus should be on the structure of HTML.

CSS already exists.

Dependency Structure Matrix

Luca Alfaro, the Professor and Department Chair of the Computer Science Department at the University of California & Thomas Henzinger, the President of the Institute of Science and Technology in Austria, co-authored an academic article on system components, "Interface Theories for Component Based Design", while studying at the University of California. The academic article describes components from one of two perspectives, both of which are congruent with content independent naming patterns.

Component Description
content independent

A component description defines a component in isolation and answers the question: what does it do? A content independent utility class .margin-lr-20 is equivalent to a component description.

Component Interface Description
content independent

A component interface description defines a component in relation to the environment and answers the question: how can it be used? Interface descriptions are content independent reusable classes that establish containing blocks for structure with a zone of dependency that begins at the level it is applied and extends outwards into the surrounding environment. The class name .horizontal-inline-flex describes the structure and layout mode that is established, however it does not describe what it contains.

BEM
content dependant

The BEM methodology follows a particular sequence of events. A block name is first authored and then applied to the outermost layer of HTML. An element name is prefixed with the block name and then applied to the child elements of the block. The block name is directly related to the type of content it contains. The zone of dependency starts at the level of application and extends inwards.

Content independent class names

.horizontal-inline-flex

.margin-lr-20
.margin-lr-20
.margin-lr-20

Content dependent class names

.nav-bar

.nav-bar__item
.nav-bar__item
.nav-bar__item

Class Types

Component Descriptions

.margin-t-20 .padding-all-20 .flex--1

Component Interface Descriptions

.horizontal-inline-flex .vertical-inline-flex

BEM

.header .nav .nav__link

HTML Syntax

BEM can exist independantly.

<header class="header"> <nav class="nav"> <a class="nav__link"> </a> <a class="nav__link"> </a> </nav> </header>

BEM can be authored in a multi-class syntax.

<header class="header horizontal-inline-flex"> <nav class="nav horizontal-inline-flex"> <a class="nav__link flex--1"> </a> <a class="nav__link flex--1"> </a> </nav> </header>

BEM classes can be replaced.

<header class="horizontal-inline-flex padding-all-20"> <nav class="horizontal-inline-flex max-w-350"> <a class="color--ffffff flex--1"> </a> <a class="color--ffffff flex--1"> </a> </nav> </header>

Modular Components

Complex components can be broken down into sub-components.

Mon
Tue
Wed
Thu
Fri
Sat
Sun

Different HTML configurations can be developed by replacing BEM classes with component interface descriptions and component descriptions.

Calendar variation 1

BEM

Mon
Tue
Wed
Thu
Fri
Sat
Sun

Calendar variation 2

Component interface descriptions and component descriptions

July 2022
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

3D View

The structure of the calendar

3D view of component

React

Function Object Orientated Application

Styles for styled-components are injected during runtime into the DOM, at the end of the head. These styles take precedence over global CSS. Utility classes should be collectively positioned at end of the cascade, such that specific properties of components can be overridden.

Method 1)

Apply a global class global-utility-class together with a styled component class.

class MyComponent extends React.Component { render() { // Attach the passed-in className to the DOM node return <div className={`${this.props.className} global-utility-class`} />; } }

Method 2)

To develop variations of a styled component class call extend on the component.

// Button const Button = styled.button` color: #888888; font-size: 16px; margin: 15px; padding: 5px 0; width: 100%; max-width: 180px; border: 2px solid #888888; border-radius: 2px; `; // extend Button const MagentaButton = Button.extend` color: magenta; border-color: magenta; `; // extend Button const BlueButton = Button.extend` color: #1193FF; border-color: #1193FF; `; render( <div> <Button>Default Button</Button> <MagentaButton>Magenta Button </MagentaButton> <BlueButton>Blue Button</BlueButton> </div> );

Structure

FOO Methodology

"The rules of logic are to mathematics what those of structure are to architecture."
Bertrand Russell

The Visual Formatting Process

The W3C have defined a universe of rules that govern how CSS properties visually format HTML elements. The Visual Formatting Model is an algorithm that processes the document tree and displays it on visual media. During this process, each element within the document tree generates zero or more boxes, according to a box model. A box is rendered in relation to the edge of its containing block. Once rendered, a box can establish itself as a containing block for its descendants. A box can be given a positioning scheme in combination with a specific layout mode and its dimensions can be precisely defined or constrained.

Different types of boxes can be generated depending on the value of the display property. When the value of a box's display property is declared, the element is said to be at 'block-level'. The display property equates to the layout mode which is an algorithm that determines the position and the size of a box. After a box is generated it can then be positioned by a positioning scheme.

A containing block is established when a positioning scheme and a display property are declared.

.containing-block { position: relative; display: inline-flex; }

BEM only

The following example is a demonstration of the BEM naming convention as of 10th March 2018.

HTML

<body class="page"> <div class="page__inner"> <header class="header page__header"> <button class="button header__button"> </button> </header> <footer class="footer page__footer"> </footer> </div> </body>

CSS

.page__inner { margin-right: auto; margin-left: auto; width: 960px; } .page__header { padding: 20px; } .page__footer { padding: 50px; } .button { font-family: Arial, sans-serif; text-align: center; border: 1px solid black; } .header__button { margin: 30px; position: relative; }

The example displays as such:

BEM example one

The BEM methodology places great importance on how accurately the name of a selector describes the entity it represents. There is very little documentation on the establishment of containing blocks or what CSS properties can be used to reinforce the function of each BEM entity.

This is strange.

Modern Browser (User Agent) CSS

The manner in which the UI is structured should echo the principles of the W3C visual formatting modal. Establishing properly formatted containing blocks increases browser compatibility and allows one to more accurately control the position and size of elements.

Earlier versions of Normalize.css contained the following:

Normalize.css

/* HTML5 display definitions ========================================================================== */ article, aside, details, figcaption, figure, footer, header, main, menu, nav, section, summary { display: block; }

This update to Normalize.css removed the HTML5 display definitions, however, the following elements are by default, set to display: block; within modern browsers as of 10th March 2018.

(User Agent) CSS

article, aside, details, div, dt, figcaption, footer, form, header, hgroup, html, main, nav, section, summary { display: block; }

If the following CSS is added:

article, aside, details, div, dt, figcaption, footer, form, header, hgroup, html, main, nav, section, summary { display: initial !important; }

The layout mode of the elements will be set to their initial value. The display property is not set by default, as such, the basic structure is removed and the BEM example would display as such:

BEM example two

The (User Agent) CSS establishes the structure within the BEM example.

<block-level> <block-level> </block-level> <block-level> </block-level> </block-level>

Layout Mode Establishes Structure

The layout mode of .page__inner, declared within the (User Agent), in combination with the BEM styles margin-left: auto; margin-right: auto; center aligns the element.

(User Agent) CSS

div { display: block; }

BEM CSS

.page__inner { margin-right: auto; margin-left: auto; width: 960px; }

(User Agent) + BEM

.page__inner { display: block; margin-right: auto; margin-left: auto; width: 960px; }

The presentation and structure of components should not depend on User Agent (CSS).

Part 6

Containing Block

part six

Extrapolation of the Visual Formatting Modal

Containing blocks establish a base structure and utility classes manipulate the presentation of existing object orientated component classes in order to reuse code. Declaring a positioning scheme and a specific layout mode establishes a base structure from which to develop further. I have assumed a box-model of border-box;

<div class="primary-menu"> <div class="primary-menu__content max-width--1024"> </div> </div>

containing block = component interface description

<div class="containing-block"> <div class="containing-block component-description"> </div> </div>

Complexification

Within the CSS2 paradigm, layout configuration is controlled at the same level the properties are applied, except for tables.

Within the CSS3 paradigm, layout configuration of child elements is controlled by the properties and property values declared at a parent level and a child level. The BEM methodology emphasizes equal specificity, however, the CSS3 paradigm requires parent child interface descriptions.

The W3C began the development of Flexbox in 2011. On the 10th of August 2017, Bootstrap announced their first beta release of Bootstrap4 with Flexbox being used as the base layout mode and primary grid system. On the 19th of October 2017, the W3C released a document describing Flexbox as, "a CSS box model optimized for user interface design". Developing layouts that combine CSS Grid and Flexbox will setup the conditions for further evolution.

The function of a front-end web developer has remained the same, however, the development process has complexified. Modern web applications have intricate requirements that need to be satisfied in the context of competitive deadlines and high expectations. Although front-end web development is a process, it is unfortunately judged in a single event.

CSS controls the presentation of HTML in a uni-directional manner. Properties and property values determine how elements will be presented and how they interact in relation to other elements.

CSS is made visible by HTML.