Showing posts with label css. Show all posts
Showing posts with label css. Show all posts

Wednesday, February 11, 2015

anil

How to Upgraded Font Awesome


HTML KickStart now uses Font Awesome version 4.2.0! A lot of people have been asking for this upgrade. I was a little hessitant to upgrade because of the new CSS naming convention in Font Awesome (FA). The older version of FA used a nice verbose "icon-name" CSS class, I like that better. The new class is "fa fa-name" and I don't find this very human readable. However, the benifits of over 200 more new icons and keeping FA up-to-date far outweights the downside. 
You may have also noticed that I have removed the visual reference from the elements (documentation) page. The reason is that it's too hard to maintain that list. Instead, head over to the Font Awesome Cheatsheet to copy and paste your icons.
Read More

Tuesday, February 3, 2015

anil

Simple CSS-Only Row and Column Highlighting

Highlighting rows of a table is pretty darn easy in CSS.tr:hover { background: yellow; } does well there. But highlighting columns has always been a little trickier, because there is no single HTML element that is parent to table cells in a column. A dash of JavaScript can handle it easily, but Andrew Howe recently emailed me to share a little trick he found on StackOverflow, posted by Matt Walton.
It was a few years old, so I thought I'd just clean it up and post it here.

The trick is using huge pseudo elements on the <td>s, hidden by the table overflow

You don't really know how big the table is from CSS, so just make the pseudo elements super tall with a negative top value of half of that.
table {
  overflow: hidden;
}

tr:hover {
  background-color: #ffa;
}

td:hover::after,
th:hover::after {
  content: "";
  position: absolute;
  background-color: #ffa;
  left: 0;
  top: -5000px;
  height: 10000px;
  width: 100%;
  z-index: -1;
}
The negative z-index keeps it below the content. Negative z-index is a fun trick, but beware this table then can't be nested within other elements with backgrounds, otherwise the highlight will go below them.

Making it work with touch

Hover pseudo classes only kinda work on touch devices. First, the element needs to be focusable, which table cells are not by default. You could certainly add a click event handler to the table cells and just do everything in JavaScript, but here's a method to keep most of the work in CSS:
// Whatever kind of mobile test you wanna do.
if (screen.width < 500) {
  
  // :hover will trigger also once the cells are focusable
  // you can use this class to separate things
  $("body").addClass("nohover");

  // Make all the cells focusable
  $("td, th")
    .attr("tabindex", "1")
    // When they are tapped, focus them
    .on("touchstart", function() {
      $(this).focus();
    });
  
}
Then in the CSS you add :focus styles as well.
td:focus::after,
th:focus::after { 
  content: '';  
  background-color: lightblue;
  position: absolute;  
  left: 0;
  height: 10000px;
  top: -5000px;
  width: 100%;
  z-index: -1;
}

td:focus::before {
  background-color: lightblue;
  content: '';  
  height: 100%;
  top: 0;
  left: -5000px;
  position: absolute;  
  width: 10000px;
  z-index: -1;
}
In my final demo, I got a little fancier with the CSS selectors ensuring that empty table cells didn't trigger anything, table headers in the <thead> only selected columns, and table headers in the <tbody> only selected rows.
You can see that in the final demo. And here's touch working:



Credit :- css-tricks.com
Read More
anil

The Two Flavors of a ‘One Web’ Approach: Responsive vs. Adaptive

You’ve probably heard people say we’re living in a “post-PC world.” What does that mean for web developers? It means that 30% to 50% of your website’s traffic now comes from mobile devices. It means that soon, desktop and laptop users will be in a minority on the web.
How do we deal with this tectonic shift in user behavior? We’ve moved beyond the era of m-dot or t-dot hacks, into one where responsive and adaptive design techniques rule the day — what the W3C calls aOne Web approach. The key part of the W3C’s recommendation is that “One Web means making, as far as is reasonable, the same information and services available to users irrespective of the device they are using.”
For developers that means that taking a One Web approach ensures that not only does your site work on the smartphones and tablets of today, but it can be future-proofed for the unimagined screens of tomorrow.
There are currently three popular approaches to developing a One Web site: using a responsive design; client-side adaptive designs; and server-side adaptive designs.
One is not better or worse than the other; each has its own strengths and weaknesses and the wise web developer will consider the benefits and drawbacks of each before picking the one that works for their next project.

Responsive Web Design

Responsive web design is the most common One Web approach. The approach uses CSS media queriesto modify the presentation of a website based on the size of the device display. The number of responsive sites is rapidly increasing, from the Boston Globe to Disney to Indochino.
A key advantage of this approach is that designers can use a single template for all devices, and just use CSS to determine how content is rendered on different screen sizes. Plus, those designers can still work in HTML and CSS, technologies they’re already familiar with. Additionally, there’s a growing number of responsive-friendly, open-source toolkits like Bootstrap or Foundation which help simplify the process of building responsive sites.
On the other hand, there are few shortcuts to a sound responsive design. To go responsive, organizations often have to undertake a complete site rebuild.
The design and testing phase can be quite fussy, as it can be difficult to customize the user experience for every possible device or context. We’ve all seen responsive site layouts that look like a bunch of puzzle pieces that don’t quite fit together. Responsive web design works best in combination with a mobile-first approach, where the mobile use case is prioritized during development. Progressive enhancement is then used to address tablet and desktop use cases.
Performance can also be a bugbear for responsive sites. At Mobify, we recently completed an analysis of 15 popular responsive e-commerce sites. Among these sites, the home pages loaded an average of 87 resources and 1.9 MB of data. Some responsive pages were as big as 15MB.
The numbers are that high because a responsive approach covers all devices. Your user is only using one device, but they have to wait for all of the page elements and resources to load before they can use it. Put simply, performance affects your bottom line. On smartphones, the conversion rate drops by an extra 3.5 percent when users have to wait just one second. By the three second mark, 57 percent of users will have left your site completely.
While responsive design is fast becoming the de facto standard, it also creates new challenges for online businesses, including how to handle images, how to optimize mobile performance and often means sites need to be rebuilt from the ground up with a mobile first approach.

Client-Side Adaptive

Adaptive design builds on the principles of responsive design to deliver user experiences that are targeted at specific devices and contexts. It uses JavaScript to enrich websites with advanced functionality and customization. For example, adaptive websites deliver Retina-quality images only to Retina displays (such as the new iPad) while standard-definition displays receive lower-quality images.
There are two approaches to adaptive design — one where the adaptations occur on the client side, in the user’s browser, and another where the web server does the heavy lifting of detecting various devices and loading the correct template. Examples of client-side adaptive sites include Threadless and ideeli. One of the strengths of the adaptive templating approach is the ability to reuse one set of HTML and JavaScript across devices, simplifying change management and testing.
A client-side adaptive approach means you don’t have to rebuild your site from the ground up. Instead you can build on existing content while still delivering a mobile-responsive layout. For expert developers, this approach also enables you to specifically target particular devices or screen resolutions. For example, for many of Mobify’s online fashion retail clients, 95% of their mobile traffic comes from iPhones. Client-side adaptive means they can optimize specifically for Apple smartphones.
Unlike responsive design, adaptive templates ensure that only the required resources are loaded by the client’s device. Because device and feature detection is shifted to the mobile device itself, CDN networks like Akamai and Edgecast can use most of their caching functionality without disrupting the user experience.

The client-side adaptive approach has a higher barrier to entry than responsive design. Developers need to have a solid grasp of JavaScript to use this technique. It also depends on a site’s existing templates as the foundation. Finally, because the client-side adaptations are a kind of layer on top of your existing code base, you need to maintain them as your site as a whole evolves.

Server-Side Adaptive

We can achieve the server-side adaptive approach in a variety of ways, through server-side plugins and custom user agent detection. Sites that use server-side adaptive include Etsy, One Kings Lane and OnlineShoes.com.
Why choose server-side adaptive? It typically offers distinct templates for each devices, enabling more customization, and it keeps device-detection logic on the server, enabling smaller mobile pages that load faster. Additionally, there are numerous server-side plugins available for common CMSs and eCommerce systems such as Magento.
This approach isn’t for the faint of heart–it typically requires significant changes to your back-end systems, which can result in a lengthy (and costly) implementation. The requirement to manage multiple templates raises ongoing maintenance costs. Finally, this approach can encounter performance issues when servers are under heavy load. When mobile user agent detection is performed on the server, a lot of common caching mechanisms deployed by CDNs like Akamai need to be turned off. This can result in a slower user experience for mobile and desktop visitors.
Of course, many companies are still wrestling with the basics of responsive, and they’re not ready to confront the more sophisticated flavors of adaptive. Increasingly, competition and mobile traffic, however, will drive more and more organizations to kick the tires on all three approaches, and pick the one that works best for their users.
Read More

Sunday, February 1, 2015

anil

8 simplest CSS hover effects

With support for CSS3 increasing with each new release for every browser, and those tiresome CSS2-only browsers slowly dropping off the usage charts, we have far more options for hover effects and transitions in general. Almost all the calls to action that you see on the Web use some form of hover effect, because they draw the eye and make a website feel more engaging.
  
Last year I brought you a set of 8 simple transitions that will wow your users, and today we’re going to look at 8 more…

Getting started



As before, we’re going to start off with some very simple HTML on which to hang our effects:

<button>Hover Me</button>
We’ll also use a core set of CSS styles for all of the transitions and animations. We’re just setting some simple defaults, like background color and font size.
The only really important rule is the last one, transition: all 500ms ease; means that we wantall properties to animate when changed, over a period of 500 milliseconds:
button {
 border: none;
 background: #3a7999;
 color: #f2f2f2;
 padding: 10px;
 font-size: 18px;
 border-radius: 5px;
 position: relative;
 box-sizing: border-box;
 transition: all 500ms ease; 
}
Now, on to the fun stuff…

1. Horizontal immersion

A style I’ve been seeing more and more of lately is one where a semi-transparent background color makes the button appear to be immersed on hover. It usually comes from one side and transitions until the entire button is covered.
To achieve this we need to make use of the before pseudo element:
button:before {
 content:'';
 position: absolute;
 top: 0px;
 left: 0px;
 width: 0px;
 height: 42px;
 background: rgba(255,255,255,0.3);
 border-radius: 5px;
 transition: all 2s ease;
} 
This content is absolutely positioned and placed at the top left of the button. I’ve given it a width of 0px, because that’s what we’ll be animating.
To animate it, we simply set the width:
button:hover:before {
 width: 100%;
}

2. Vertical immersion

This effect is very similar to the one above, except that in this case we’ll be animating the height to make the color seem like it’s falling from the top of the button:
button:before {
 content:'';
 position: absolute;
 top: 0px;
 left: 0px;
 width: 100%;
 height: 0px;
 background: rgba(255,255,255,0.3);
 border-radius: 5px;
 transition: all 2s ease;
}
All that really changes here is setting the height instead of the width:
button:hover:before {
 height: 42px;
}

3. Ghost button

In this little snippet we’ll add a simple but highly effective transition to the button. The ghost button effect is when we invert the color in the button and add a border:
button:hover {
 background: rgba(0,0,0,0);
 color: #3a7999;
 box-shadow: inset 0 0 0 3px #3a7999;
}
On hover I’ve set the background as transparent so that it picks up the surrounding element background. Then I’ve added the color and a simple box-shadow.

4. Icon animate in

This effect is great for functions, like adding an item to a cart, or submitting a form. What we’ll do is have an icon slide in and appear next to the text, when the user hovers over the button.
The first thing I did was add a little bit more padding to the button to make room for the icon and set the overflow to hidden:
button{ 
 padding: 10px 35px;  
 overflow:hidden;
}
The next step is adding the cart icon (I’m using Font Awesome for the icon) in the beforepseudo-element and position it outside the bounds of the button:
button:before {
 font-family: FontAwesome;
 content:"\f07a";
 position: absolute;
 top: 11px;
 left: -30px;
 transition: all 200ms ease;
}
Now, all we need to do is animate in the icon by setting its left property:
button:hover:before {
 left: 7px;
}

5. Bounce effect

In this animation we’re going to set some keyframes for the button so that we have a bounce effect when the user hovers on it. This is always a great way to grab a user’s attention.
First, we need is to create the keyframes:
@keyframes bounce {
 0%, 20%, 60%, 100% {
  -webkit-transform: translateY(0);
  transform: translateY(0);
 }

 40% {
  -webkit-transform: translateY(-20px);
  transform: translateY(-20px);
 }

 80% {
  -webkit-transform: translateY(-10px);
  transform: translateY(-10px);
 }
}
Then we simply apply the animation on hover:
button:hover {
 animation: bounce 1s;
}

6. Skew

Skew is definitely one of the most peculiar transforms in CSS3. We’ve had it in Photoshop for years, but getting in in CSS3 was a surprise to say the least.
Nevertheless, it’s an interesting transition and using it is incredibly simple. Just set it on hover:
button:hover {
transform: skew(-10deg);
}

7. Dotted border

This effect is a lot like the ghost button effect, but instead of a uniform border, we get a dotted line.
All we really need to do is add the border to the button and invert its colors:
button {
 border: 3px solid #3a7999;
}
button:hover {
 border: 3px dotted #3a7999;
 color: #3a7999;
 background: rgba(0,0,0,0);
}

8. Flip 3D effect

This last effect is a little more complicated since it involves flipping the button over to reveal another message we’ve added in the after pseudo-element of the button.
Let’s start by setting the button’s transform style to preserve-3d so that all the children of the element will preserve their 3D position:
button {
 transform-style: preserve-3d;
}
After this we need to take care of our after pseudo element:
button:after {
 top: -100%;
 left: 0px;
 width: 100%;
 position: absolute;
 background: #3a9999;
 border-radius: 5px;
 content: 'Flipped';
 transform-origin: left bottom;
 transform: rotateX(90deg);
}
I’ve added this at the top, before our button, and I’ve also set the width and the border-radiusto match our button.
As for the transform properties, I’ve set the the bottom left corner of the element as the point of origin and set its x rotation to 90 degrees, so that it appears flat.
Now all that’s left to do is to create the hover animation:
button:hover {
 transform-origin: center bottom;
 transform: rotateX(-90deg) translateY(100%);
}
As you can see, to activate the effect I set the transform point of origin at the center, and also rotated the element to apply the transform.
Read More