Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning less.js
  • Table Of Contents Toc
Learning less.js

Learning less.js

By : Alex Libby
5 (2)
close
close
Learning less.js

Learning less.js

5 (2)
By: Alex Libby

Overview of this book

If you are a designer or developer who wants to quickly learn how to harness the power of Less.js to write more efficient CSS styles that can be applied to a website of any size, then this book is for you. This book will help you master both the basic functions and advanced features of Less.js. It would be helpful to have some familiarity of writing CSS styles, although no prior experience of using CSS preprocessors is required.
Table of Contents (17 chapters)
close
close
16
Index

Supporting CSS4 standards within Less

With the advent of CSS2 and CSS3, it is natural to assume that CSS4 will arrive at some point in the future. You are probably wondering how it might affect CSS preprocessors—let's take a look at what CSS4 is likely to mean for Less.

Officially, there is no such thing as CSS4. Strange as it might seem, we won't see the appearance of a new global standard; CSS4 instead will be grouped under smaller headings, of which each will have its own level. There is still a long way to go, but one of the groupings that is closest to being finalized is CSS4 Selectors.

Note

You can see more details about the proposed changes for CSS Selectors in the W3C's draft proposal at http://dev.w3.org/csswg/selectors4/. There is an interesting discussion on the possibilities of using Selectors at http://vandelaydesign.com/blog/design/some-interesting-possibilities-with-css4/.

Although these have been around since the beginning of CSS, CSS4 brings a number of new logical operators, such as :not and :matches, as well as some new local pseudo classes in the form of :any-link or :local-link. The latter, in particular, brings some useful features to styling links, as shown in the following code example:

nav:local-link(0){
   color: red;
}

nav:local-link(1){
   color: green;
}

nav:local-link(2){
   color: blue;
}

nav:local-link(3){
   color: yellow;
}

nav:local-link(4){
   color: gray;
}

We can rewrite this using the following code in Less:

nav {
  &:local-link(0) { color: red; }
  &:local-link(1) { color: green; }
  &:local-link(2) { color: blue; }
  &:local-link(3) { color: yellow; }
  &:local-link(4) { color: gray; }
}

If we compile this code, we can see the results within a page that has a breadcrumb trail—take, for example, the URL as http://internetlink.com/2014/08/21/some-title/, and this in the form of a breadcrumb trail as follows:

  • Home (http://internetlink.com/)
  • 2014 (http://internetlink.com/2014/)
  • August 2014 (http://internetlink.com/2014/08/)
  • 21 August 2014 (http://internetlink.com/2014/08/21/)
  • Article (http://internetlink.com/2014/08/21/some-title/)

The first link will be red, the second will be green, the third blue, then yellow, and finally gray.

Supporting future CSS standards within Less

Support for future CSS standards (or CSS4, as it is frequently termed) is still very much in its early stages within Less. Some progress has been made to allow the use of selectors in Less, which can be used with the ampersand symbol, as we saw earlier in the Supporting CSS4 standards within Less section in this chapter.

At the time of writing this book, the developers have refrained from adding too many new features for CSS4, as most of the current proposed changes are still in the draft state and are subject to change. The main feature added so far is that of support for attributes, which appeared in Version 1.4 of Less—others will appear once the specification has been finalized and support has appeared in more than one browser. The key thing to note though is that any CSS4 standard with CSS3 syntax is automatically supported in Less.

There will still be a need for Less once CSS4 standards become mainstream; Less will evolve to include the new standards while still allowing us to be more efficient when writing CSS.

Tip

How much support does my browser offer for CSS4?

As an aside, you may like to test your browser of choice to see how much support it offers for CSS4; browse to http://css4-selectors.com/browser-selector-test/ and then click on Start test! to see the results.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning less.js
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon