frontend designer
at
frontend
at
The order of CSS rules matter
h1 {
color: black;
}
* {
color: red;
}
Example
1/2
html {
color: black;
font-size: 16px;
}
.nav .body-text {
color: red;
margin-right: 1em;
}
Example
html {
color: black;
font-size: 16px;
}
.nav .body-text {
color: red;
font-size: 16px;
margin-right: 1em;
}
Computed
1/2
determines which CSS rule is applied by the browsers.
element {}
::pseudo-element {}
.class {}
[attribute] {}
:pseudo-class {}
#id {}
property: !important;
style="property: in-line;"
>, +, *, ~, :not()
@media
Specificity
Location in stylesheet
In order to avoid cascade problems.
body {
&.header {
&.nav {
ul {
li {
a#link {
color: red !important;
}
}
}
}
}
}
body.header.nav ul li a#link {
color: red !important;
}
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div class="frankestein">
Igor
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
.frankestein {
color: green;
}
div div div div div div div div div div div div {
color: red;
}
HTML
CSS
class specificity
div's specificity
.card {
margin: 1em !important;
}
.card {
margin-bottom: 1em !important;
margin-left: 1em !important;
margin-right: 1em !important;
margin-top: 1em !important;
}
1/4
.media-cardtreats your CSS as a dependency of your HTML.
2/4
.user-card__portrait {}
.nav ul li a img {}
.card
.btn, .btn--primary, .btn--secondary
.badge
.card-list, .card-list-item
.img--round
.modal-form, .modal-form-section
3/4
.positive-button {}
.submit-button {}
.green-button {}
4/4
<button class=“btn btn--secondary”>
Purchase
</button>
.btn {
display: inline-block;
color: blue;
}
.btn--secondary {
color: green;
}
<button class=“btn--secondary”>
Purchase
</button>
.btn--secondary {
display: inline-block;
color: green;
}
Bloc | Element | Modifier
Bloc | Element | Modifier
Good: reducing the amount of code by reusing it (DRY principle).
Bad: complex support.
When you change the style of a particular element, you will most likely have to change not only CSS (because most classes are common), but also add classes to the markup.
.nav {
margin-left: auto;
margin-right: auto;
padding-bottom: 1em;
padding-top: 1em;
}
.foo {
margin-left: .5em;
margin-right: .5em;
padding-bottom: 1.2em;
padding-top: 1.2em;
}
.gmail {
border-style: solid;
border-color: red;
border-width: 1px;
}
.nav {
border-style: solid;
border-color: red;
border-width: 1px;
margin-left: auto;
margin-right: auto;
padding-bottom: 1em;
padding-top: 1em;
}
.foo {
border-style: solid;
border-color: red;
border-width: 1px;
margin-left: .5em;
margin-right: .5em;
padding-bottom: 1.2em;
padding-top: 1.2em;
}
h3 {
color: red;
font-family: 'Lato';
font-size: 16px;
}
.text-bold {
font-weight: 900;
}
.nav h3 {
color: red;
font-family: 'Lato';
font-size: 16px;
font-weight: 900;
}
.foo h3 {
color: red;
font-family: 'Lato';
font-size: 16px;
}
Base: applies to HTML, no class/ID selectors.
Layout: big page sections.
.header, .sidebar, .footer
Module: encapsulation modules, re-usable.
State: overrides defaults.
.is-opened, .is-active
Theme
sass/
|
|– abstracts/
| |– _variables.scss # Sass Variables
| |– _functions.scss # Sass Functions
| |– _mixins.scss # Sass Mixins
| |– _placeholders.scss # Sass Placeholders
| …
|
|– base/
| |– _reset.scss # Reset/normalize
| |– _typography.scss # Typography rules
| …
|
|– components/
| |– _buttons.scss # Buttons
| |– _carousel.scss # Carousel
| |– _cover.scss # Cover
| |– _dropdown.scss # Dropdown
| …
|
1/2
|
|– layout/
| |– _grid.scss # Grid system
| |– _header.scss # Header
| |– _footer.scss # Footer
| …
|
|– pages/
| |– _home.scss # Home specific styles
| |– _contact.scss # Contact specific styles
| …
|
|– themes/
| |– _theme.scss # Default theme
| |– _admin.scss # Admin theme
| …
|
|– vendors/
| |– _bootstrap.scss # Bootstrap
| |– _jquery-ui.scss # jQuery UI
| …
|
`– main.scss # Main Sass file
2/2
1/3
sass/
|
|– settings/
| |– _config.scss # Project-level config
| |– _core.scss # Core setup
| |– _global.scss # Variables
| …
|
|– tools/
| |– _font-size.scss # Baseline mixin
| |– _clearfix.scss # Clearfix mixin
| |– _hidden.scss # Hidding mixin
| …
|
|– generic/
| |– _box-sizing.scss # Default `box-sizing`
| |– _normalize.scss # Normalize.css vendor
| |– _reset.scss # A tiny reset
| …
|
|– elements/
| |– _page.scss # Global `font-size` & `line-height`
| |– _headings.scss # Default styles for headings
| |– _images.scss # Default images styles
| …
|
2/3
|
|– objects/
| |– wrapper.scss # Page constraint object
| |– layout.scss # Generic layout module
| |– media.scss # Content side by side
| …
|
|– components/
| |– _buttons.scss # Default buttons styles
| |– _nav.scss # Default nav styles
| …
|
|– vendor/ (this folder is not mean to be used in ITCSS)
| |– _bootstrap.scss # Bootstrap
| …
|
|– utilities/
| |– _widths.scss # Widths helper classes
| |– _headings.scss # Headings helper classes
| |– _spacings.scss # Spacings helpe classes
| …
|
`_all.scss
3/3
/// Make a context based selector a little more friendly
/// @author Kitty Giraudel
/// @param {String} $context
@mixin when-inside($context) {
#{$context} & {
@content;
}
}
.frnk-js-btn--primary,
.frnk-js-btn--secondary,
.frnk-js-btn--tertiary {
font-family: 'Lato';
}
.body-text {
border-color: red;
border-style: solid;
border-width: 1px;
padding-left: 20px;
padding-right: 20px;
z-index: 666;
}
// Buttons can be applied to any HTML element that is used to trigger a user
// action (e.g. following a call to action link, submitting a form).
//
// 1. Line differently sized buttons up a little nicer.
.btn,
.link {
// Avoid @extends: creates unnecesary CSS
@extend .text;
@include fluid-font();
color: red;
vertical-align: middle; /* [1] */
@media (min-width: 64em) {
color: pink;
}
&--secondary {
width: 100%;
}
.nav & {
margin-left: auto;
}
&.is-disable {
opacity: .5;
}
}