Due to some circumstances, this blog is now up for sale, for more enquires contact: Plushista@gmail.com
RealcomBiz
Pin It

10 Amazing Things I Bet You Didn't Know You Could Do With CSS

by Durodola Ridwan | Sunday, May 18, 2014 | 35 Comments

CSS is almost certainly one of the best developments in web design since the first graphical web browsers were adopted on a wide scale. Where tables created clunky, slow-loading pages, CSS created much more streamlined and usable web pages. Also, CSS has allowed developers and designers to achieve a number of different styles that used to only be possible with images.

Being able to adapt to new ideas and different techniques, as well as seeking new solutions to old problems is part and parcel of being a web designer/developer. And with the speed at which CSS development is constantly moving, keeping up with new developments can be challenging.



Recently, I came across some useful CSS features I believe it will be new to most developers. So, I thought I had to share them with you. Enjoy!


1. The border Property

When dealing with borders. Usually, we sets border-width, border-style, and border-color all in a single declaration, like:

.class {
  border: 1px solid black;
}

But since each of the properties that the border property represents is itself a shorthand property. So we can also do these with border-width:

.class {
  border-width: 1px 4px 3px 6px;
}

This will set different widths for each four sides of the border. And can also be done with border-style and border-color.

Each of those properties can be broken down even further with border-top-width, border-bottom-style, border-left-color, and so on. See the below example:




2.  Three New Values Are Available for background Property

In CSS2.1 the background shorthand property included 5 longhand values which are: background-color, background-image, background-repeat, background-attachment, and background-position. In CSS3, we now have three new values - background-size, background-clip and background-origin.

The background-size property specifies the size of the background images. The contain values scales the image, while preserving its aspect ratio (if any), which may leave uncovered space. The cover scales the image so that it covers the whole area, completely covering the element.

With possible values of border-box and padding-box, the background-clip property determines whether the background position is relative to the border or the padding, specifying whether an element’s background extends underneath its border. This only has any visual effect when the border has transparent regions (because of border-style) or partially opaque regions; otherwise the border covers up the difference.

The background-origin property determines how the background-position is calculated. Takes one or two parameters: border-box, padding-box and content-box.

So the syntax looks like this:

.class {
background: black url(img.png)
no-repeat
scroll
center center / 50%
content-box
content-box;
}

Note: If one of the properties in the shorthand declaration is the background-size property, you must use a / (slash) to separate it from the background-postion property. As in the example above, we specify center center for the background-position, then separate it with a slash from 50% which happens to be the background-size.


3. You Can Use Unicode as CSS Classes

Some developers camelcase class names, others use dashes, and others use underscores. But I haven't seen any developer using Unicode in is document.

The idea is that you can use unicode characters for class names in your HTML, and write CSS selectors with those same characters.

<div class="❤">
I Can See The Pines Are Dancing
</div>
<div class="□">
I Can See The Pines Are Dancing
</div>

We then declare styles for the class:

.❤ {
background: white;
border: 1px solid black;
}

.□ {
background: white;
border: 1px solid red;
}

Although, you can use Unicode as CSS classes and yes it works in IE6 and yes it validates. But I don't advise you to use it!


4.  You Can Use Keyword Values for border-width

The shorthand property border-width sets the width of the border on all four sides of an element using the values specified. In addition to the standard length values (px, pt, em, and so on), the border-width property now accepts three keyword values: thin, medium, and thick. Percentage values are not allowed.

The keyword with values of thin, medium, and thick aren’t explicitly defined - their display will depend on the user agent, but have the following meaning: thin - medium - thick.

As an example, Internet Explorer versions (up to and including 7) sizes thin, medium, and thick borders at 2px, 4px, and 6px respectively, while Firefox 2.0 sizes them at 1px, 3px, and 5px. Internet Explorer version 8 now falls in line with other modern browsers and renders the border thickness at 1px, 3px, and 5px respectively.

inherit - Is a keyword indicating that all four values are inherited from their parent's element calculated value.


5. text-decoration Property is Now a Shorthand

The property is used to add visual emphasis to content that is independent from the text's font style, weight or other properties.

The property supported five values: none, underline, overline, line-through, and blink.

In CSS3, text-decoration is now a shorthand property, incorporating the following new properties (written in this order):

  • text-decoration-line, which supports the five values from CSS 2.1
  • text-decoration-style, which supports the values: solid, double, dotted, dashed, wavy 
  • text-decoration-color, which supports any CSS color value.

This is now standard, according to the spec:

.text {
  text-decoration: underline dashed red;
}

The new property is in process of being implemented. It is backward compatible but forward incompatible. What this means is that CSS2 rules work in CSS3 but a CSS3 rule specifying the three values is totally invalid in CSS2. For best, support a CSS3 text-decoration rule with a fallback like this:

.text {
  text-decoration: underline;
  text-decoration: underline dashed red;
}


6.  Pointers Events

The CSS property pointer-events allow authors to control under what circumstances (if any) a particular graphic element can become the target of mouse events. The pointer-events property is even more JavaScript-like, preventing:

  • The default cursor pointer from displaying
  • CSS hover and active state triggering
  • JavaScript click events from firing
  • Click actions from doing anything

The pointer-events property can have many values: auto, none, visiblePainted, visibleFill, visibleStroke, visible, painted, fill, stroke, all, and inherit. The none value prevents the click state, and cursor actions:

Examples

Example 1:

/* Makes all the img non-reactive */
img {
pointer-events: none;
}

Example 2:

Makes the link to http://example2.com non-reactive.

<ul>
<li><a href="http://example1.com">example1</a></li>
<li><a href="http://example2.com">example2</a></li>
</ul>

a[href="http://example2.com"] {
pointer-events : none ;
}

Example 3:

/* do nothing when clicked or activated */
.disabled { pointer-events: none; }

/* this will not trigger because of the pointer-events: none application */
document.getElementById("disabled").addEventListener("click", function(e) {
alert("Clicked!");
});

Note: Mouse events may target its descendant elements if those descendants have pointer-events set to some other value. In these circumstances, mouse events will trigger event listeners on this parent element as appropriate on their way to/from the descendant during the event capture or bubble phases.


7.  border-image Seems to Be Overlooked

Although, this is not a new thing, but I believe only few developers know about this feature. The border-image property is a shorthand property for setting the border-image-source, border-image-slice, border-image-width, border-image-outset and border-image-repeat properties.

The idea is that you can create flexible boxes with custom borders with a single div and a single image. Here’s what the syntax looks like, with the necessary proprietary syntax included:

.example {
border-width : 40px 30px 10px 20px;
-moz-border-image : url("border-image.png") 40 30 10 20 round;
-webkit-border-image : url("border-image.png") 40 30 10 20 round;
-o-border-image : url("border-image.png") 40 30 10 20 round;
border-image : url("border-image.png") 40 30 10 20 round;
}

The notation is broken up into three sections. The first is the URL that points to the image. The second section (the four numeric values) is the border-image-slice values which represent inward offsets from the top, right, bottom, and left edges of the image respectively, dividing it into nine regions: four corners, four edges, and a middle. While the third part of the shorthand rule tells the browser how to treat the middle sections of your image - the ones that will go along the edges of your element. Repeat (repeat, or tile, the image) and stretch (stretch, or scale, the image) are pretty self-explanatory. Round means tile the image but only so that a whole number of tiles fit, and otherwise scale the image. Right now, Safari and Chrome interpret round as repeat.

In order for border-image to work correctly, the element to which it’s applied must have the border (or border-width) property set with four values corresponding to the values given in the shorthand notation (otherwise your image slices will be stretched to fill the border width, which is rarely what you want). The four values behave similarly to margin and padding values. You can learn more about border-image from here and here.


8.  There’s an empty-cells Property

This property controls the rendering of the borders and backgrounds of cells that have no visible content in a table that’s using the separated borders model. If the collapsing model is used, this property will be ignored.

/* This style rule hides empty cells in the table element with the class ID "examples" */
.examples td {
  empty-cells: hide;
}

Three values can be set for empty-cell: show, hide, and inherit.

show - The value show means borders will be drawn around empty cells, and backgrounds will be drawn behind them.
hide - The value hide means that no borders or backgrounds will display empty cells. If all the cells in a row have this setting for empty-cells, and none of them have any visible content, the entire row will behave as if it had display:none. It support all major browsers including IE8.


9.  The color Property Isn’t for Text Only

As anyone who codes CSS knows, the color property in CSS defines the color of the text in a specified element. I’ve often wondered why this property was not named text-color or something similar.

According to the specs, here’s what the color property is supposed to do:

"This property describes the foreground color of an element’s text content. In addition it is used to provide a potential indirect value… for any other properties that accept color values."

Take a look at the example below:

.element {
background : #fff;
width : 100px;
height : 100px;
color : purple;
border : solid 2px;
}

Here’s what the above code produces:



The color of the border is not defined, but the purple value from the color property is used for the border color, because the border of an element is considered part of the foreground. This works the same in every browser. Of course, if the border property included a color value (which is almost always the case), then that would override the previously-defined color.

You can see another great example here. As you can see on the link page. The color property is applied only to the body element, and everything on the page shares the same color including: The alt text displayed on a missing image, the border on the list element, the bullet on the unordered list, the number marker on the ordered list, and the hr element. Big thanks to Louis Lazaris for this wonderful tip.


10.  Slide Up and Slide Down

CSS transitions often make it easy to replace effects with CSS animations that render much smoother on slower devices and computers assuming you’re running a browser that’s reasonably recent.
Most times we use jQuery’s .slideDown() and .slideUp() methods to do this sort of thing, but if you are actually trying to run that on most phones today, you’ll find that the animation is pretty jerky as it runs without hardware rendering assistance using only the CPU rather than the GPU. But what if I tell you that you can accomplish this task with CSS only?

/* slider in open state */
.slider {
overflow-y: hidden;
max-height: 500px;
transition-property: all;
transition-duration: .5s;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}
/* close it with the "closed" class */
.slider.closed {
max-height: 0;
}

As seen above, we'll make the height play nice with the max-height property. We'll set that property value to a reasonable default and then create another class to set that max-height to 0, thus sliding the element in.

A word of caution – some of these features will not work in older versions of IE (9 and below). If these browsers are a large portion of your demographic, I am afraid that you will have to rely on fallbacks.

I am sure most experienced CSS developers will knew many, if not all the above listed features. But for starter, you might be surprised with most of them. Let me know in the comment if I have missed any cutting edge CSS features.



Go Social:

Subscribe For Free Updates!

*Please confirm the email sent to your inbox after clicking "Sign Up!".

35 comments : Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. A more creative website means more users will come and enjoy the technology stuff.
    hire php developer

    ReplyDelete
  2. HTML and CSS are best technology for design creative and effective navigation of the website. Through creative website user can stay on website and use benefit of user friendly environment. Web design company Delhi works with HTML and CSS for creative and effective website.

    ReplyDelete
  3. HTMl and CSS really helpful for seo masters during on page.
    SEO Company Jaipur

    ReplyDelete
  4. This is a pretty neat article. I knew about most of these features, but some of the things you are able to do with CSS leave me speechless! Thanks for this article!

    website development company in jaipur

    ReplyDelete
  5. Great post. I agree with your thoughts. I appreciate your work here. The post is very useful to me. I hope that you will keep posting again such types of useful information.
    web design and development company

    ReplyDelete
  6. I think .net is the best technique for designing and development because it is the safest type of platform. Most Web design and development company in Jaipur are using .net.

    ReplyDelete
  7. good In the Google android system you can discover the this page Install shareit for Computer /Notebook computer. shareitforpcc nice.

    ReplyDelete
  8. good just simply that, and it's obtainable in Kodi's key add-on repository. kodi app These plugins works extremely well for items like great.

    ReplyDelete
  9. good just simply that, and it's obtainable in Kodi's key add-on repository. kodi app These plugins works extremely well for items like great.

    ReplyDelete
  10. good Snapchat has got on top of that provided another ‘Travel and leisure Method’ http://isnapchatemojis.com hourglass mean this is usually on your end of the talk, you’ve delivered great.

    ReplyDelete
  11. good for enjoying and saving Television set displays and videos. this page video lessons in great definition employing ShowBox. Showbox Download Free nice.

    ReplyDelete
  12. good motion picture programs, cartoons, activities, this page With You TV Participant, you can perform You TV Player Windows phone great.

    ReplyDelete
  13. good and in that case you can simply set up the apps. go to iplaystoredownload.com shortage Take up Retail outlet by default. nice.

    ReplyDelete
  14. IOS has recently launched new version of Apple Operating System called IOS 10.To upgrade your IOS to Latest IOS 10 new release by Apple Inc. you can get New iOS 10 download free from CydiaNerd on your Browser.

    ReplyDelete
  15. good Knock Knock: See the caller before you pick up with Duo’s live preview feature. Download Google Duo APK The apps are available in Google Play Store for the users to download. nice.

    ReplyDelete
  16. iOS jailbreaking is the process of removing software restrictions imposed by iOS, Apple Inc's operating system, on its devices including the iPhone, iPod touch, iPad, and second-generation Apple TV. Jailbreaking is done by using software exploits, and it permits root access to the iOS file system and manager, so applications, extensions, and themes unavailable through the official Apple App Store can be downloaded. now you can get Pangu iOS 10 Jailbreak to enjoy all new features of iPhone.

    ReplyDelete
  17. awesome No other program is optimised as this nifty little program. Vidmate App Vidmate has an excellent interface that is not difficult to navigate and pleasing to examine nice.

    ReplyDelete
  18. this is nice and awesome way to express yourself. You know what snapchat emojis meaning are simple and easy to understand. You can easily unlock the trophy case to get all the trophies and the best tyhing about snapct ius you can share your views very easily website isn't it cool? peace. nice.

    ReplyDelete
  19. yea motion picture programs, cartoons, activities, this page With You TV Participant, you can perform You TV Player Windows phone great.

    ReplyDelete
  20. if you student and want to check gate results then right place here.
    if you using iphone and ipad devices and want to Verify an iCloud Account then click here.
    are you want to impress any girl ?? then few Romantic Questions to Ask a Girl to impress on first chat.

    ReplyDelete
  21. awesome No other program is optimised as this nifty little program. tubemate 2.2.9 has an excellent interface that is not difficult to navigate and pleasing to examine nice.

    ReplyDelete
  22. Tubemate youtube downloader is the world leader supporting viewing and downloading free unlimited videos for android smartphone.

    ReplyDelete
  23. good Bluestacks' site, after that take after the on-screen prompts to present the job. Little Mix Snapchat you could simply establish on up straightforwardly from the Blue-stacks emulator. nice.

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete

About Me

My Photo
Durodola Ridwan is a Professional blogger, SEO Consultant, Certified Web developer/designer and founder of www.realcombiz.com. He love writing about Blogging tips, SEO, and play around with codes. You can connect with him on facebook, twitter @realcombiz, and Google+.

Recent Posts

Let's Connect

Site Links

Copyright © 2014 RealcomBiz. All Rights Reserved.
Powered by Blogger