GithubHelp home page GithubHelp logo

css3-mixins-tricks's Introduction

css3-mixins-tricks

Tips & Tricks, A bunch of tips and tricks I've learned and found very helpful.

Css3 Best Practice

It's important when building a web page to avoid unecessary element, to remind this there is some tricky way using css3. In the sample below we will display a counter within a badge.

Note: The content property is used with the :before and :after pseudo-elements, to insert generated content. The attr() CSS function is used to retrieve the value of an attribute of the selected element and use it in the style sheet. It can be used on pseudo-elements too and, in this case, the value of the attribute on the pseudo-element's originated element is returned.The attr() function can be used with any CSS property.

See sample below:

#bad practice

Example:

Alt text

HTML:

<a href="#">Inbox <span class="badge">42</span></a>

<button class="btn btn-primary" type="button">
  Messages <span class="badge">4</span>
</button>

CSS:

#good practice

HTML:

<a href="#" data-count="4">Inbox <span class="badge">42</span></a>

<button data-count="4" class="btn btn-primary" type="button"></button>

CSS:

  .btn:after { 
    position: absolute; 
    z-index: 1; 
    top: 2px; 
    right: 5px; 
    content: attr(data-count); 
    display: block; 
    width: 13px; 
    height: 13px; 
    border: 1px solid #FFF; 
    border-radius: 13px; 
    background-color: #C30019; 
    font-weight: bold; 
    white-space: normal; 
    color: #FFF; 
    text-align: center; 
    font-size: 9px; 
  } 

css3-mixins-tricks's People

Contributors

neolanders avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.