Keep dividing and refactoring files as and when they get too big.
Your layout:
.header {
width: 100%;
height: 50px; // Magic number
}
.sidebar {
width: 100px; // Magic number
height: 100%;
top: 50px; // Magic number
}
.content {
top: 50px; // Magic number
bottom: 0;
left: 100px; // Magic number
right: 0;
}
Too many magic numbers!
Better approach
$header-height: 50px;
$sidebar-width: 100px;
.header {
width: 100%;
height: $header-height;
}
.sidebar {
width: $sidebar-width;
height: 100%;
}
.content {
top: $header-height;
bottom: 0;
left: $sidebar-width;
right: 0;
}
Better approach
$header-height: 50px;
$sidebar-width: 100px;
.header {
width: 100%;
height: $header-height;
}
.sidebar {
width: $sidebar-width;
height: 100%;
}
.content {
top: $header-height;
bottom: 0;
left: $sidebar-width;
right: 0;
}
.hud-stats {
position: fixed;
opacity: 0.7;
filter: sepia(90%);
bottom: 20px;
left: 20px;
}
.hud-map {
position: fixed;
opacity: 0.7;
filter: sepia(90%);
top: 20px;
right: 20px;
}
.hud-stats {
position: fixed;
opacity: 0.7;
filter: sepia(90%);
bottom: 20px;
left: 20px;
}
.hud-map {
position: fixed;
opacity: 0.7;
filter: sepia(90%);
top: 20px;
right: 20px;
}
.hud-element {
position: fixed;
opacity: 0.7;
filter: sepia(90%);
}
.hud-stats {
bottom: 20px;
left: 20px;
}
.hud-map {
top: 20px;
right: 20px;
}
<div class="hud-element hud-stats">9999</div>
%hud-element {
position: fixed;
opacity: 0.7;
filter: sepia(90%);
}
.hud-stats {
@extend %hud-element;
bottom: 20px;
left: 20px;
}
.hud-map {
@extend %hud-element;
top: 20px;
right: 20px;
}
<div class="hud-stats">9999</div>
Selectors have strengths...and they do fight!
Example:
div.tabs {
width: 100%;
}
<div class="tabs"></div>
.tabs-half {
width: 50%;
}
<div class="tabs tabs-half"></div>
strength(div.tabs) > strength(.tabs-half)
!important
div.tabs
.tabs
Supports Component abstraction
.slider { position: relative; }
.slider .slider-track { background: white; }
.slider .knob { position: absolute; }
// Variation
.slider.slider-with-input .slider-input { display: block; }
.slider { position: relative; }
.slider__track { background: white; }
.slider__knob { position: absolute; }
// Variation
.slider--with-input .slider__input { display: block; }
Selectors - Less specific. More uniform.
Issue?
Separate them out into your config as variables
$z-index-overlay: 1;
$z-index-slideout-backdrop: 1;
$z-index-slideout: 1;
$z-index-sidebar: 2; // above help panel for tooltips
$z-index-navigation: 4; // top of sidebar
$z-index-header: 4;
$z-index-modal-underlay: 4; // Below modal-box & top of others.
$z-index-modal-box: 5; // on top of everything
Changing existing z-indexes become really easy because you know what might break.
Setting z-index for new UI elements is very easy because you can actually position it in a similar hierarchy.
z-index: 99999;
Simple example:
.error {
color: red;
background: #ff8888;
}
.sidebar {
.error {
padding: 10px;
}
}
.error-notification {
@extend .error; // GONNA BE BAD!!!
}
Result
.error {
color: red;
background: #ff8888;
}
.sidebar {
.error {
padding: 10px;
}
}
.error-notification {
@extend .error;
}
.error, .error-notification {
color: red;
background: #ff8888;
}
.sidebar .error,
.sidebar .error-notification {
padding: 10px;
}
Unnecessary CSS generated
Solution: Use placeholders
%error {
color: red;
background: #ff8888;
}
.error {
@extend %error;
}
.sidebar {
.error {
padding: 10px;
}
}
.error-notification {
@extend %error;
}
.error, .error-notification {
color: red;
background: #ff8888;
}
.sidebar .error {
padding: 10px;
}
PUT_YOUR_IP_HERE:8000
on your mobiles/laptop to play along