albtechportal

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 20 November 2013

Build a Responsive Pricing Table with Neat Hover States

Posted on 03:34 by Unknown

Final Product What You'll Be Creating

Download Source Files
Demo  View It Online
During this tutorial we’ll be creating a sleek pricing table with some striking hover effects. We’ll use Lea Verou’s Prefixfree script to keep our CSS clean, plus we’ll make the whole thing responsive, shifting the layout at a couple of breakpoints.


The Markup

The image below displays a visual skeleton of the markup we will be creating. As you can see, it’s not built using tables; we’re using unordered lists for maximum flexibility and responsiveness.
css3-pricing-table-markup

HTML Markup

Before anything else, we need to begin with an empty document. Very important here is the viewport meta tag which will allows all devices to properly interpret our responsive layout.
001
002
003
004
005
006
007
008
<!DOCTYPE html>
<html lang="en" >
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
</body>
</html>
Now we can begin with the meat of our table markup (or rather list markup):
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
<ul class="pricing_table">
    <li>...</li>
    <li class="price_block">
        <h3>Basic</h3>
        <div class="price">
            <div class="price_figure">
                <span class="price_number">$9.99</span>
                <span class="price_tenure">per month</span>
            </div>
        </div>
        <ul class="features">
            <li>2GB Storage</li>
            <li>5 Clients</li>
            <li>10 Active Projects</li>
            <li>10 Colors</li>
            <li>Free Goodies</li>
            <li>24/7 Email support</li>
        </ul>
        <div class="footer">
            <a href="#" class="action_button">Buy Now</a>
        </div>
    </li>
    <li>...</li>
    <li>...</li>
</ul>
<script src="prefixfree.min.js" type="text/javascript"></script>
At the very bottom we’ve included prefixfree (before the closing </body> tag), which allows us to use unprefixed CSS properties everywhere. It works behind the scenes, adding the current browser’s prefix to any CSS code, only when it’s needed.

Styles

Having sorted out our markup, let’s look at adding some styles. I’ll be doing so within <style> tags in the document head, but you can use a separate stylesheet if you’d rather.

1. Basic Styles

001
002
003
004
005
006
007
008
@import url(http://fonts.googleapis.com/css?family=Ubuntu);
* {
    margin: 0;
    padding: 0;
}
body {
    font-family: Ubuntu, arial, verdana;
}
To start with, we apply a basic CSS reset and use a custom font ‘Ubuntu’ which is being pulled in from Google Fonts.

2. Pricing Table and Price Blocks

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
.pricing_table {
    line-height: 150%;
    font-size: 12px;
    margin: 0 auto;
    width: 75%;
    max-width: 800px;
    padding-top: 10px;
    margin-top: 100px;
}
.price_block {
    width: 100%;
    color: #fff;
    float: left;
    list-style-type: none;
    transition: all 0.25s;
    position: relative;
    box-sizing: border-box;
    margin-bottom: 10px;
    border-bottom: 1px solid transparent;
}
The .pricing_table is kept 75% wide, but limited to 800px so that it does not take a huge amount of space on wide screens.
We are approaching things mobile first, hence .price_block is 100% wide by default to cover the entire width available. Later we will use media queries to fit in more blocks horizontally on wider screens.
css3-pricing-table-1x4
The 10px bottom margin given to .pricing_block comes into play when users view the pricing table on smaller screens, particularly when some of the pricing blocks fall down and stack below one another. It goes towards compensating a negative 10px top margin applied to the .price_title of the pricing blocks stacked below. You will read more about the 10px negative margin in the next section.
The 1px transparent border for .pricing_block creates a gutter helping in separation of the different blocks of content.
.price_block is also set to have position: relative; so that when box shadows are applied for hover effects, z-index can be used on the hovered block to make its shadow appear above the nearby elements.

3. Price Heads

css3-pricing-table-header
001
002
003
004
005
006
.pricing_table h3 {
    text-transform: uppercase;
    padding: 5px 0;
    background: #333;
    margin: -10px 0 1px 0;
}
The price heads have a -10px top margin. This causes the contents of the .price_block to move upwards so that they’re displayed above the shadow, giving a top-light feel.

4. Price Tags

Now for the sections which actually display the pricing details.
css3-pricing-table-price-tags
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
.price {
    display: table;
    background: #444;
    width: 100%;
    height: 70px;
}
.price_figure {
    font-size: 24px;
    text-transform: uppercase;
    vertical-align: middle;
    display: table-cell;
}
.price_number {
    font-weight: bold;
    display: block;
}
.price_tenure {
    font-size: 11px;
}
One point worth noting here is that the price tags are aligned vertically center. This is required for prices which may not have a tenure (eg. FREE).
.price is set to have display: table; and its immediate child .price_figure is set to have display: table-cell; and vertical-align: middle; to achieve the effect.
.price_figure acts as a container for .price_number and .price_tenure so that they can be vertically center-aligned as a single unit.

5. Features

001
002
003
004
005
006
007
008
009
010
.features {
    background: #DEF0F4;
    color: #000;
}
.features li {
    padding: 8px 15px;
    border-bottom: 1px solid #ccc;
    font-size: 11px;
    list-style-type: none;
}

6. Footer and Action Button

001
002
003
004
005
006
007
008
009
010
011
012
013
014
.footer {
    padding: 15px;
    background: #DEF0F4;
}
.action_button {
    text-decoration: none;
    color: #fff;
    font-weight: bold;
    border-radius: 5px;
    background: linear-gradient(#666, #333);
    padding: 5px 20px;
    font-size: 11px;
    text-transform: uppercase;
}

7. Hover Effect

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
.price_block:hover {
    box-shadow: 0 0 0px 5px rgba(0, 0, 0, 0.5);
    transform: scale(1.04) translateY(-5px);
    z-index: 1;
    border-bottom: 0 none;
}
.price_block:hover .price {
    background:linear-gradient(#DB7224, #F9B84A);
    box-shadow: inset 0 0 45px 1px #DB7224;
}
.price_block:hover h3 {
    background: #222;
}
.price_block:hover .action_button {
    background: linear-gradient(#F9B84A, #DB7224);
}
There will be three aspects to the hover effect:
  • Color change – The background color is changed from dark grey to an orange-yellow gradient for .price and .action_button. Additionally, .price also gets an inset orange shadow to enhance the color effect.
  • Shadow – a basic 5px translucent shadow.
  • Upward shift and scaling using CSS3 transforms – The .price_block hovered is scaled to 104% and moved upwards by 5px.
.price_table already has CSS3 transitions applied which makes the hover change a smooth animation.
You can also use these hover effects as an active state if you wish to highlight one of the prices by default. All you need to do is add an active class to one of the price blocks and move/copy the hover styles to it.

Adding Media Queries

We’ll follow a simple approach to make the pricing table responsive. The sections are already fluid as they use % based widths, so all we need to do is control the number of horizontal blocks visible on different screen sizes.
  • < 480px – show 1 block (this is our default)
  • 480px – 768px – show 2 blocks
  • 768px+ – show all 4 blocks
These breakpoints are defined purely on what works visually with this design. Let’s add our media queries underneath our other styles.
001
002
003
004
005
006
007
008
009
010
011
012
@media only screen and (min-width : 480px) and (max-width : 768px) {
    .price_block {width: 50%;}
    .price_block:nth-child(odd) {border-right: 1px solid transparent;}
    .price_block:nth-child(3) {clear: both;}
    .price_block:nth-child(odd):hover {border: 0 none;}
}
@media only screen and (min-width : 768px){
    .price_block {width: 25%;}
    .price_block {border-right: 1px solid transparent; border-bottom: 0 none;}
    .price_block:last-child {border-right: 0 none;}
    .price_block:hover {border: 0 none;}
}
For the viewport range of 480px – 768px we make each pricing block 50% wide. This will effectively stack them in rows of two. The .price_block:nth-child(3) {clear: both;} ensures that the third block clears the upper two blocks, even when hover states change the size of everything. We’re also setting a 1px right border on .price_block(odd ones) to create a vertical gutter between the price blocks on the left and right hand sides.
css3-pricing-table-2x2
For 768px and above we set the width of each block to 25% giving us rows of four. We’re also setting borders on the right side of all the price blocks, except the last one, to create the same vertical gutter as above.

Conclusion

With a fluid layout, some simple styling and a couple of breakpoints, we’ve built a neat CSS3 pricing table. I hope you find use for it!

Source 
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Tutorials, Webdesign | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • ‘Strata’ for iOS and Android game review
    There are games that are fun. There are games that look great. And then there are games that do both. Strata is one such game that h...
  • Call of Duty: Ghosts Review
    Developer: Infinity Ward Publisher: Activision Platforms: PC, X360, PS3, PS4, Xbox One Price: £39.99 Reviewing a Call of Duty game is a ...
  • Review: Seagate 600 480GB SSD
    Seagate Joins the Fray It’s been quite an interesting turn of events over the past couple years in the storage industry. Whereas practical...
  • CCBoot - LAN Boot Software for Windows
    LAN Boot Solution Background LAN boot is a technology based on IP (Internet Protocol), UDP (User Datagram Protocol), DHCP (Dynamic ...
  • How To Splice Fiber Optic Cable - Mechanical Splice
    Instructions for splicing fiber optic cable with the AFL CS004162 mechanical splice kit. Watch quick overview video at bottom of post. 1.0 ...
  • Smart Power Strip now works with SmartThings WiFi hub to keep your home always connected
    If you couldn't tell by its name alone, the Smart Power Strip's a card-carrying member of the 'internet of things' or, for ...
  • Xbox One vs. PS4: How They Stack Up Today
    Two new gaming consoles. Both very powerful. Both very ambitious. Both about to meet head to head... and do battle for your time, money an...
  • ASUS R9 270X DirectCU II TOP 2 GB
    AMD's new Radeon R9 270X draws its lineage more from the Radeon HD 7800 series than any other. The R9 270X is, for all intents and purp...
  • Corsair Raptor M40 Review
    Manufacturer: Corsair UK price (as reviewed): £44.99 (inc VAT) US price (as reviewed): $59.99 (ex Tax) Along with the Raptor M30, Corsai...
  • Intel NUC DC53427RKE / HYE Review
    Manufacturer: Intel UK Price (as reviewed): £308.32 (inc VAT) US Price (as reviewed): $539.99 (ex TAX) Preferred Partner Price: £308.32...

Categories

  • Android
  • Apple
  • Audio
  • Blogger
  • C/C++
  • Cabling
  • Cameras
  • Cases
  • CISCO
  • Cooling
  • CPU
  • Desktop
  • DNS
  • Ebook
  • Fiber Optic
  • Gadgets
  • Game
  • Google
  • Graphic Card
  • Hardware
  • HDD
  • HTC
  • HTMLCSS
  • Hyper-V
  • Intel
  • iOS
  • iPad
  • Iphone
  • IT
  • jQuery
  • Laptop
  • Linux
  • Mac
  • MacTut
  • Microsoft
  • Mobile
  • Mouse
  • Networking
  • News
  • Nexus
  • Nokia
  • Nvidia
  • OS
  • PERIPHERALS & COMPONENTS
  • Photoshop
  • Printers
  • Programming
  • Projectors
  • PS4
  • Ram
  • RedHat
  • Review
  • Samsung
  • Scanners
  • Seagate
  • Security
  • Server2008
  • Server2012
  • Servers
  • Smartphone
  • Software
  • Sony
  • Storage
  • Tablets
  • TechNews
  • Template
  • Tutorials
  • TV
  • Ubuntu
  • Voip
  • Webdesign
  • Webiste
  • WebServer
  • Win7
  • Win8
  • Windows Phone
  • Wordpress
  • Workstation
  • XBOX

Blog Archive

  • ▼  2013 (495)
    • ►  December (35)
    • ▼  November (332)
      • DesktopOK 3.71 + Portable
      • Lynda - Up and Running with iOS SDK with Ron Lisle
      • SIM-free BlackBerry Z10 now available for $199
      • Hands-on with the Fitbit Force
      • Lenovo IdeaCentre Erazer X700 Gaming PC Review
      • LG G2 to get the Android KitKat update in Q1, 2014
      • Image shows Nokia Lumia 929 in white; leak reveals...
      • Watch Out for Seagate Drives Allegedly Sold Under ...
      • Starting a Website? Get a Domain Name and Hosting ...
      • Our Favorite Android, iOS and Windows Phone Apps o...
      • iBuypower Chimera 4SE FX Ultimate: AMD Gaming PC
      • How to Buy a Business Desktop
      • Google Nexus phones are vulnerable to rebooting vi...
      • Android 4.4 KitKat now seeding to Korean LG G2
      • Best For Music: PS4 or Xbox One?
      • Fix your Mac yourself with the new TechTool Pro 7!
      • How to buy the right sound bar to go with your TV
      • Understanding LSI SandForce SF3700 Series Controller
      • ASUS R9 270X DirectCU II TOP 2 GB
      • FIFA rolls out iOS and Android apps ahead of 2014 ...
      • How to Protect Wi-Fi network From Hackers
      • Recover Deleted Files From External Hard Drive
      • Best Video Editing Apps for Android Users-Must have
      • iPhone 6 Release Date,Full Specifications-whats new
      • How to r00t on server : Free E-Book
      • Samsung Galaxy S5 will not have OIS camera
      • Create Windows 8 Bootable Pendrive
      • Top 5 things to look for in a PC monitor
      • 5 things to look for in an 802.11ac router and ada...
      • 7 ways to maximise your Wi-Fi speeds
      • How to make your own Android ROM
      • VMWare Fusion 6 Opens Windows On Your Mac
      • Control iTunes & Apple TV From The Palm Of Your Ha...
      • Use Your Computer, Don’t Let It Use You: Five “U”s...
      • What’s Trending? Find Out With These Real-Time Dat...
      • Cool Websites & Tools – Remote Website Sharing, Lo...
      • Fascinating Earth: 5 Citizen Science Projects For ...
      • Brix on BRIX – Colin talks to Newegg about the lat...
      • Samsung Galaxy S5 Coming Early 2014 With 64-Bit Ex...
      • Get Your (Linux) Game On: Steam Autumn Sale Highli...
      • Firefox debuts new UI that looks like Chrome, but ...
      • World’s fastest wireless network hits 100 gigabits...
      • Intel Unveils 72-Core x86 Knights Landing CPU for ...
      • United States falls to 31st place in global broadb...
      • Xbox One vs. PS4: How They Stack Up Today
      • Got a Defective Xbox? Here’s How Microsoft Will Ma...
      • ASUS Releases “Faster Than Titan” ROG Mars 760 Vid...
      • How to get Android and iOS apps for free or on the...
      • How to remotely install apps on your smartphone
      • Community driven Core Apps convergence
      • Introduction & Packaging
      • Fix: Change PC Settings does not open in Windows 8...
      • How to make your Android look like it's running iOS 7
      • Switching Monitor Profiles
      • Web Administration Scripts
      • Top 10 apps from last week: Courses123, 500 Firepa...
      • Does the idea of a modular phone appeal to you?
      • How to Boost and Increase your Internet Speed
      • Ubuntu Linux server with ARM processor rolled out ...
      • 6 steps for setting up a small business server room
      • The best home backup plan options - Part 3: Extern...
      • The best home backup plan options - Part 4: Cloud ...
      • The best home backup plan options - Part 5: A comp...
      • How to Backup Files On Your Computer - Part 1: The...
      • The best home backup plan options - Part 2: Same m...
      • How To: Crucial Ballistix Elite Memory Installatio...
      • iBuypower Reveals First Steam Machine Prototypes
      • Kingston ships HyperX Predator 2800MHz Memory for ...
      • Samsung ChatON for Android now supports SMS and MM...
      • Grand Theft Auto: San Andreas coming to Android, i...
      • Google bakes photo goodies deep inside KitKat, but...
      • Oops -- YouTube's new commenting system actually i...
      • WD My Cloud Personal Cloud Server Review
      • Acer Unleashes Affordable, Touchscreen Chromebook
      • Apple iPhone 5s makes up a larger percentage of th...
      • Microsoft giving a free game to owners of Xbox One...
      • Samsung Galaxy S4 Google Play edition scores Andro...
      • Apple iPad mini 2 vs Google Nexus 7
      • Sony resetting some PSN passwords as a 'precaution...
      • Chromecast stand-in CheapCast now beams browser ta...
      • Galaxy S5 rumors, the Snapdragon 805 chip, and wil...
      • What about the Wii U?
      • Red Mac Pro Designed by Jony Ive, Marc Newson Fetc...
      • HTC One GPE getting Android 4.4 KitKat
      • BlackBerry ousts marketing and operations chiefs, ...
      • Recuva Data Recovery Software: Recover deleted fil...
      • Mass-market HTC One in Gold goes official
      • Assassin's Creed: Pirates launches for phones and ...
      • WP to put pressure on iOS in enterprise market
      • New Tegra 4-powered Nook leaked from GFXBench
      • Apple confirms PrimeSense buyout, paves way for mo...
      • Pen computing returns: Revenge of the stylus
      • 3D Systems Sense review: a 3D scanner for the mass...
      • Intel Demonstrates First 64-bit Android Tablet
      • DOOO for iPhone Makes Gorgeous To-Do Lists With Te...
      • Chinese supercomputer twice as fast as closest US ...
      • Best 802.11ac routers
      • Mac vs. PC: Is an Apple computer really better tha...
      • Android 4.4 Kit Kat Update Rolling Out to AT&T Mot...
      • Review: Seagate 600 480GB SSD
    • ►  October (12)
    • ►  September (27)
    • ►  August (2)
    • ►  July (10)
    • ►  June (42)
    • ►  May (35)
Powered by Blogger.

About Me

Unknown
View my complete profile