10x Developer
  • Introduction
  • HTML
    • HTML DOM Jquery
    • HTML: Form
    • CSS
    • CSS Layout
    • CSS Flexbox
    • CSS Grid
    • SASS/LESS
    • CSS/LESS/SASS Cookbook
    • Bootstrap
  • JavaScript
    • JavaScript
    • ES6
    • TypeScript
    • JavaScript Testing
    • JavaScript Event Loop
    • DOM
    • Web APIs
    • JSON
    • RegEx
    • Functional Programming
    • JavaScript Lib
    • CoffeeScript
    • CoffeeScript to ES6 cheatsheet
  • Angular.js
    • Angular
    • Angular Cookbook
    • Angular Mistakes I Made
    • Angular 1.x
  • React.js
    • React.js
  • Node
    • Node.js
    • CLI command line tool
    • Electron / Atom
    • NW.js (node-webkit)
  • Serverless
    • AWS Lambda
    • Google Cloud Function
    • Actions on Google / Google Assistant
  • Full Stack Development
    • HTTP
    • Meteor
    • MongoDB
    • Digital Ocean
    • UI
    • Sketch
    • Web Dev Resources
  • Lang
    • Ruby
  • Know Your Tools
    • Chrome DevTools
    • Editor: VS Code
    • Editor: Vim
    • Editor: Sublime
    • Editor: Atom
    • Windows
    • Git
    • Linux / Bash
    • Mac
  • Cheatsheets
Powered by GitBook
On this page
  • How to center ul?
  • How to reposition the class under specified parent in SASS/LESS?
  • How to add search icon to input?
  • Form control margin
  • Bootstrap: row click and offmenu canvas
  1. HTML

CSS/LESS/SASS Cookbook

PreviousSASS/LESSNextBootstrap

Last updated 6 years ago

How to center ul?

Make ul display: inline-block in a text-align: center div

How to reposition the class under specified parent in SASS/LESS?

For example you have:

.parent1 {
  .parent2 {
    .container {
      margin: 5px 0;
    }
  }
}

And you want to adjust the margin under the root class .native:

.native {

    .parent1 {
      .parent2 {
        .container {
          margin: 10px 0;
        }
      }
    }
}
.parent1 {
  .parent2 {
    .container {
      margin: 5px 0;

      .native & {   // -> it turns to: .native .parent1 .parent2 .container {}
        margin: 10px 0;
      }
    }
  }
}
  • When & is placed before a selector, it refers to the immediate parent.

// -> .some-class.another-class
.some-class {
  &.another-class {}
}

// -> .button:hover {}
.button {
  &:hover {}
  }

.a {
  .b {
    // -> .a .b.b1 (not .a.b1 .b)
    &.b1 {
      color: red;
    }
  }
}
  • When & is placed after a selector, that selector becomes the root selector and & represents the whole path and the whole path is repositioned under the root selector.

// -> body.page-about .button {}
.button {
  body.page-about & { }
}

.a {
  .b {
    // -> .root .a .b 
    .root & {
      color: black;
    }
    // -> .a1.a .b
    .a1& {
      color: red;
    }
    // -> .a .b.b1
    &.b1 {
      color: yellow;
    }
  }
}

How to add search icon to input?

  • Could not use ::before because input doesn't have content

  • Position icon in input, and make it vertically center with top and translateY

  • Padding left on input for space of the icon

Form control margin

Bootstrap: row click and offmenu canvas

You can use & :

Usages of &: (also on my )

http://codepen.io/hamxiaoz/pen/egLOwV
LESS: Parent Selectors
Medium post
http://codepen.io/hamxiaoz/pen/MJdXyo
http://stackoverflow.com/questions/18562153/what-css-controls-the-right-and-left-margins-between-these-form-elements-in-twit
http://jasny.github.io/bootstrap/javascript/#fileinput