• Home
  • Categories
  • Video Tutorials
    • Angular 5
  • News
  • About us
  • Contact us
  • Login
test
Code4Developers

Code4Developers

Code4Developers
  • Home
  • Categories
  • Video Tutorials
    • Angular 5
  • News
  • About us
  • Contact us
  • Login
  • HTML/Stylesheet

Advanced CSS Tricks and Techniques

  • Arif Khoja
  • August 9, 2017
  • 3 minute read
Total
0
Shares
0
0
0

A wonderful collection of some bleeding edge CSS techniques for you to try out. Some of these might not be fully supported, so use in production at your peril!

As time goes by, CSS is becoming more and more powerful. Nowadays, it allows a lot of possibilities. This article is a compilation of fresh, advanced tips and techniques to master your CSS skills.   

cssWarning: Some techniques contained in this article are still considered as experimental. Make sure to check the browser compatibility before you implement them on a production site.

Using SVG for Icons

SVG is supported by all modern browsers and scales well for all resolution types, so there’s no reason to continue using .jpg or .gif images for icons. Note the use of the background-size property to scale the background image on the on container size.

.logo {
 display: block;
 text-indent: -9999px;
 width: 100px;
 height: 82px;
 background: url(kiwi.svg);
 background-size: 100px 82px;
}

Source: CSS Tricks

Fixed Table Layouts

A widely supported but surprisingly little-known property which changes the way the tables are rendered and gives you a sturdier, more predictable layout.

table {
 table-layout: fixed;
}

Source: CSS Tricks

Curve Text Around a Floated Image

The shape-outside is a CSS property that allows geometric shapes to be set in order to define an area for text to flow around.

.shape {
 width: 300px;
 float: left;
 shape-outside: circle(50%);
}

Here’s the result of the .shape class applied to the image:
curved-text-css

Source: WebDesigner Depot

Intrinsic Ratio Boxes

Using 20% for padding makes the height of the box equal to 20% of its width. No matter the width of the viewport, the child div will keep its aspect ratio (100% / 20% = 5:1).

.container {
 height: 0;
 padding-bottom: 20%;
 position: relative;
}
 
.container div {
 border: 2px dashed #ddd; 
 height: 100%;
 left: 0;
 position: absolute;
 top: 0;
 width: 100%;
}

Source: AllThingsSmitty

Color Fade on Hover

A very easy way to make your links (or any other element) look better.

a {
 color: #000;
 -webkit-transition: color 1s ease-in; /*safari and chrome */
 -moz-transition: color 1s ease-in; /* firefox */
 -o-transition: color 1s ease-in; /* opera */
}
 
a:hover { 
 color: #c00;
}

Source: Matt Lambert

Style Broken Images

Broken images never look good, but ievery now and then, one or two images on your site are broken. Using some advanced CSS, it is possible to style broken images and provide custom error messages to your visitors.

img { 
 min-height: 50px;
}
 
img:before { 
 content: " ";
 display: block;
 position: absolute;
 top: -10px;
 left: 0;
 height: calc(100% + 10px);
 width: 100%;
 background-color: rgb(230, 230, 230);
 border: 2px dotted rgb(200, 200, 200);
 border-radius: 5px;
}
 
img:after { 
 content: "\f127" " Broken Image of " attr(alt);
 display: block;
 font-size: 16px;
 font-style: normal;
 font-family: FontAwesome;
 color: rgb(100, 100, 100);
 position: absolute;
 top: 5px;
 left: 0;
 width: 100%;
 text-align: center;
}

 

Look what can be achieved with that technique. Way better than browsers’ default, right?
broken-image-css

Source: Bitsofco.de

Empty and Not Empty Attribute Selectors

CSS3 makes it easy to apply different styles to an element regardless of whether a data-* attribute is empty. Have a look at the HTML code below:

<div data-attr="">
</div>
<div data-attr="value">
</div>

And now, our CSS, with specific styling for any div element with an empty data-attr attribute:

div {
 border: 1px solid gray;
 height: 100px;
 margin: 10px;
 width: 100px;
}
/* Empty attribute selector */
 div[data-attr=''] { 
 background: red; 
}
 /* Not empty attribute selector */ 
div:not([data-attr='']) {
background: green;
}

Source: Vacheslav Starikov

Comma-Separated Lists

A little snippet to display an unordered list as a comma-separated list. Note the use of :not(:last-child)to ensure that the last list element won’t be followed by a comma.

ul > li:not(:last-child)::after {
content: ",";
}

Source: AllThingsSmitty

Arif Khoja
Arif Khoja

Arif Khoja is a Developer. He is a Javascript Enthusiatic who loves logical programming and has first hand experience in building a cutting edge internet product using Angular. He is also an open source freak and keen about learning and sharing. He writes Javascript both frontend and backend. He loves learning and sharing tech all the time. He also has a hands on experience in SEO and writes articles about latest emerging technologies.

Views: 8,764

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print

Like this:

Like Loading...

Related Posts

Total
0
Shares
Share 0
Tweet 0
Pin it 0
1 comment
  1. Pingback: Bootstrap basics for beginners - Code4Developers

Leave a ReplyCancel reply

Subscribe to Website via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Recent Posts
  • Getting Started with AWS Step Functions: Orchestration Made Simple

    Getting Started with AWS Step Functions: Orchestration Made Simple

    4 months ago
  • React Hooks Guide: Top Tips for Optimizing Performance in Your React Applications

    React Hooks Guide: Top Tips for Optimizing Performance in Your React Applications

    2 years ago
  • Demystifying JavaScript Tree Shaking: Boosting Performance and Reducing Bundle Size

    Demystifying JavaScript Tree Shaking: Boosting Performance and Reducing Bundle Size

    2 years ago
  • Unlocking the Power of React Hooks: A Comprehensive Guide with Examples

    Unlocking the Power of React Hooks: A Comprehensive Guide with Examples

    2 years ago
  • Celebrating a Decade of Phenomenal Growth: Insights and Reflections on 10 Years of Software Engineering

    Celebrating a Decade of Phenomenal Growth: Insights and Reflections on 10 Years of Software Engineering

    2 years ago
  • Angular Custom Elements: Creating Reusable Components with Angular

    Angular Custom Elements: Creating Reusable Components with Angular

    3 years ago
  • Connect Firebase Realtime NoSQL Database with Angular App from Scratch

    Connect Firebase Realtime NoSQL Database with Angular App from Scratch

    5 years ago
  • How to Build an Inclusive Esports Community

    How to Build an Inclusive Esports Community

    5 years ago
  • Best Digital Icebreakers

    Best Digital Icebreakers

    5 years ago
  • Email alerts when a docker container stopped in AWS ECS CLUSTER

    Email alerts when a docker container stopped in AWS ECS CLUSTER

    5 years ago
Subscribe to Website via Email

Enter your email address to subscribe to this website and receive notifications of new posts by email.

Featured Posts
  • javascript 1
    Spread syntax (three dots) in JavaScript
    • March 21, 2018
  • Angular 2
    Angular 6 CRUD – Part 1: Project Setup, Routing, Service
    • May 9, 2018
  • javascript 3
    Local Storage and Session Storage
    • May 22, 2017
  • Angular 4
    Angular 4 Project Structure
    • June 18, 2017
  • AWS 5
    Email alerts when a docker container stopped in AWS ECS CLUSTER
    • July 24, 2020
Code4Developers
Learning is never ending process

Input your search keywords and press Enter.

%d