Thursday, July 9, 2015

CSS Gradients: A Syntax Crash Course

In the past most websites used images heavily to create a fancy UI. Thanks to various CSS properties this trend has changed. This tutorial will help you to learn about CSS gradients.You can use gradients to replace images in various UI elements as well as in backgrounds. With a little practice you can create complex patterns without using a single image.

CSS gradients, which have excellent browser support, allow you to create smooth visual transitions between two or more specified colors. Gradients give you control over a lot of settings like the size of the gradient, its angle, position of color stops, etc.

In this post, I’ll cover linear, radial, as well as the newer repeating gradients.

Linear Gradients

Linear gradients are the most commonly used gradients. The looks like this, with the bracketed values representing the types of values:

[code language="css"]
.example {
background: linear-gradient(
[direction], [first-color], [second-color], [more-colors ...]
);
}
[/code]

If you don’t specify a direction, the gradient will start at the top with full strength of the first color then smoothly transition to the last color as it reaches the bottom.

For more control, you can specify the direction of gradient. You can do it either by using simple terms like to left, to bottom right, or you can specify angles. Here is the code snippet to create a background that goes from left to right:

[code language="css"]
.example {
background: linear-gradient(to right, hotpink, lightpink);
}
[/code]

See the Pen Left to Right Linear Gradient by SitePoint (@SitePoint) on CodePen.

Older browsers support a slightly different syntax and require browser specific prefixes. In older browsers, instead of specifying the end point you specify a start point. CSS3 gradient code for older browsers looks like this:

[code language="css"]
.example {
background: -prefix-linear-gradient(left, red, blue);
}
[/code]

Specifying Angles for Linear Gradients

If you need to create a gradient at a specific angle, you can specify one directly. The code below creates a gradient at an angle of 60 degrees.

[code language="css"]
.example {
background: linear-gradient(60deg, red, blue);
}
[/code]

Considering a line from bottom to top to be at zero degrees, the angle increases if the line moves in a clockwise direction. For instance:

[code language="css"]
.example {
background: linear-gradient(0deg, red, blue);
}
[/code]

This will create a gradient with red at the bottom and blue at the top. While the following will create a horizontal gradient with red on the left side and blue on the right:

[code language="css"]
.example {
background: linear-gradient(90deg, red, blue);
}
[/code]

See the Pen Linear Gradients with Different Angles by SitePoint (@SitePoint) on CodePen.

Specifying Color Stops in Linear Gradients

If you want to change the colors non-uniformly you can specify color stops yourself. Position of color stops can be specified as a percentage value or an absolute length. You don’t need to specify the stop position for first and last color. A given color is at its full strength on the position that you specified. Here, is an example:

[code language="css"]
.example {
background: linear-gradient(
to bottom, yellow, red 70%, black
);
}
[/code]

If there are no stops specified, the colors will be spaced evenly.

See the Pen Linear Gradient with Color Stops by SitePoint (@SitePoint) on CodePen.

Radial Gradients

Radial gradients are less common and more complex. This is the syntax for radial gradients:

Continue reading %CSS Gradients: A Syntax Crash Course%


by Baljeet Rathi via SitePoint

Structuring CSS Class Selectors with Sass

CSS naming conventions are legions. You probably know BEM and SMACSS already (the latter also being more than naming conventions). There is also OOCSS which is more like a full methodology. They all heavily rely on CSS class selectors, as they are heavily re-usable.

Using Sass can help writing those selectors in a more modular fashion. through selector nesting and mixins, we can come up with fancy crazy solutions to build the desired API. In this article, I"ll (re-)introduce a few of these ways, listing what I feel are the pros and cons of each of them.

Native Selector Nesting

Having a way to nest selectors in order not to have to repeat the original block name has been a long asked feature in Sass. In version 3.3 of Sass, this feature has finally been introduced. First with a very odd syntax during the beta, later changed for a better one when the stable version went live. The reasons behind this change are explained by Natalie Weizenbaum in this article.

Basically, the reference selector (&) can be used as part of a sub-class name in order to create another class name from the first at root-level of the document (meaning @at-root is not needed here).

Continue reading %Structuring CSS Class Selectors with Sass%


by Hugo Giraudel via SitePoint

The Tuts+ Guide to Template Tags: Fifth Batch

In the fifth part of the series, we went through the fourth batch of WordPress template tags. In this sixth part, we're going to go through the fifth batch of the almost 200 template tags. Throughout the tutorial, we'll see template tags about posts, pages and template parts.

Getting & Displaying Automatic Classes for Each Post: get_post_class() & post_class()

These template tags let you add extra classes to use in each post's container.

Parameters

Both template tags accept two parameters:

  • $class (optional—string):
    Extra CSS class names to add.
    (Default: Empty)
  • $post_ID (optional—integer or object):
    The ID of the post.
    (Default: Current post)

Usage

Getting & Displaying the Permanent Link of Current Post: get_permalink() & the_permalink()

This template tag returns or displays a "permalink" of the post.

Parameters

the_permalink() doesn't accept any parameters, but get_permalink() accepts two parameters:

  • $post_ID (optional—integer or object):
    The ID of the post.
    (Default: Current post)
  • $leavename (optional—boolean):
    Whether to keep page name or not.
    (Default: FALSE)

Usage

Getting & Displaying the Post ID: get_the_ID() & the_ID()

These template tags return and display the post ID.

Parameters

These template tags don't accept any parameters.

Usage

Getting & Displaying a Page Title for the Post: single_post_title()

This template tag returns and displays the page's title for using in page titles (the titles that go inside the <title> tag).

Parameters

This template tag accepts two parameters:

  • $prefix (optional—string):
    Prefix to the title.
    (Default: Empty)
  • $echo (optional—boolean):
    Whether echo (TRUE) or return (FALSE) the tag.
    (Default: TRUE)

Usage

Getting & Displaying the Link of the Next Post: get_next_post_link() & next_post_link()

These template tags let you return or display a "next post" link for, say, your single post pages.

Parameters

Both template tags accept five parameters:

  • $format (optional—string):
    Format of the link where %link is the $link parameter.
    (Default: '%link &raquo;')
  • $link (optional—string):
    Format of the anchor text where %title is the post title.
    (Default: '%title')
  • $in_same_term (optional—boolean):
    Whether to make the link a post from the same taxonomy term.
    (Default: FALSE)
  • $excluded_terms (optional—string or array):
    Excluded terms list.
    (Default: Empty)
  • $taxonomy (optional—string):
    Taxonomy to filter the next post.
    (Default: 'category')

Usage

Getting & Displaying the Link of the Previous Post: get_previous_post_link() & previous_post_link()

These template tags let you return or display a "previous post" link for, say, your single post pages.

Parameters

Both template tags accept five parameters:

  • $format (optional—string):
    Format of the link's anchor text.
    (Default: '%link &raquo;')
  • $link (optional—string):
    Format of the permalink.
    (Default: '%title')
  • $in_same_term (optional—boolean):
    Whether to make the link a post from the same taxonomy term.
    (Default: FALSE)
  • $excluded_terms (optional—string or array):
    Excluded terms list.
    (Default: Empty)
  • $taxonomy (optional—string):
    Taxonomy to filter the previous post.
    (Default: 'category')

Usage

Getting the Permalink of a Page: get_page_link()

This template tag returns the permalink URL of a given page.

Parameters

This template tag accepts three parameters:

  • $post_ID (optional—integer or object):
    The ID of the post.
    (Default: Current post)
  • $leavename (optional—boolean):
    Whether to keep page name or not.
    (Default: FALSE)
  • $sample (optional—boolean):
    Whether is it a sample permalink.
    (Default: FALSE)

Usage

Getting & Displaying the Permalink of a Post: get_post_permalink() & post_permalink()

These template tags return and display the permalink of the given post.

Parameters

get_post_permalink() accepts three parameters:

  • $post_ID (optional—integer):
    The ID of the post.
    (Default: Current post)
  • $leavename (optional—boolean):
    Whether to keep page name or not.
    (Default: FALSE)
  • $sample (optional—boolean):
    Whether is it a sample permalink.
    (Default: FALSE)

And post_permalink() accepts only one parameter:

  • $post_ID (optional—integer or object):
    The ID of the post.
    (Default: Current post)

Usage

Getting & Displaying the Shortlink of the Post: wp_get_shortlink() & the_shortlink()

These template tags return or display a shortlink for your posts.

Parameters

wp_get_shortlink() accepts three parameters:

  • $ID (optional—integer):
    Post or blog ID.
    (Default: Current post or blog)
  • $context (optional—string):
    Whether the ID is a blog ID, a post ID or a media ID. You can set it to 'post' (for blog posts) or 'query' (for every other kind).
    (Default: 'post')
  • $allow_slugs (optional—boolean):
    Whether to allow slugs in the shortlink.
    (Default: TRUE)

And the_shortlink() template tag accepts four parameters:

  • $text (optional—string):
    Text to display for the link.
    (Default: "This is the short link")
  • $title (optional—string):
    Tooltip title for the link.
    (Default: Empty, which is converted to sanitized post title)
  • $before (optional—string):
    The text or HTML code to display before the output.
    (Default: Empty)
  • $after (optional—string):
    The text or HTML code to display after the output.
    (Default: Empty)

Usage

Getting & Displaying the "Edit Post" Link: get_edit_post_link() & edit_post_link()

These template tags let you get or echo a "edit this post" link to use in your templates.

Parameters

get_edit_post_link() accepts two parameters:

  • $post_ID (optional—integer):
    The ID of the post.
    (Default: Current post)
  • $context (optional—string):
    Whether to escape the URL or not. Use anything but 'display' to prevent encoding the link.
    (Default: 'display')

And edit_post_link() accepts four parameters:

  • $text (optional—string):
    Text to display for the link.
    (Default: 'Edit This')
  • $before (optional—string):
    The text or HTML code to display before the output.
    (Default: Empty)
  • $after (optional—string):
    The text or HTML code to display after the output.
    (Default: Empty)
  • $post_ID (optional—integer):
    The ID of the post.
    (Default: Current post)

Usage

Getting the "Delete Post" Link: get_delete_post_link()

This template tag lets you use a "delete this post" link in your templates.

Parameters

This template tag accepts three parameters:

  • $post_ID (optional—integer):
    The ID of the post.
    (Default: Current post's ID.)
  • $deprecated (deprecated—string):
    This parameter is deprecated, pass it empty.
    (Default: Empty)
  • $force_delete (optional—boolean):
    Whether to delete completely, without sending the comment to Trash.
    (Default: FALSE)

Usage

Displaying Permalink "Anchor" for the Current Post: permalink_anchor()

This template tag displays a permalink anchor ID for a post. Check the example for more explanation.

Parameters

This template tag accepts only one parameter:

  • $mode (optional—string):
    Whether to set the id parameter of the <a> tag to the post title ('title') or post ID ('id' or any other text).
    (Default: 'id')

Usage

Loading Header Template: get_header()

This well-known template tag lets you load an external PHP file of a header.

Parameters

This template tag accepts only one parameter:

  • $name (optional—string):
    Name of the header file (header-{$name}.php).
    (Default: Empty, which will load header.php)

Usage

Loading Footer Template: get_footer()

This commonly used template tag lets you load an external PHP file of a footer.

Parameters

This template tag accepts only one parameter:

  • $name (optional—string):
    Name of the footer file (footer-{$name}.php).
    (Default: Empty, which will load footer.php)

Usage

Loading Sidebar Template: get_sidebar()

This popular template tag lets you load an external PHP file of a sidebar.

Parameters

This template tag accepts only one parameter:

  • $name (optional—string):
    Name of the sidebar file (sidebar-{$name}.php).
    (Default: Empty, which will load sidebar.php)

Usage

Loading a Template File: get_template_part()

This template tag lets you load an external PHP file in your theme folders.

Parameters

This template tag accepts two parameters:

  • $slug (required—string):
    The slug of the template filename.
    (Default: NULL)
  • $name (optional—string):
    The custom name that's suffixed to the filename with a hyphen.
    (Default: NULL)

Usage

Conclusion

Hope you liked this fifth batch of template tags. There are three more batches to go, so stay tuned for more template tags!

If you have any questions, comments or corrections, you can share your thoughts with us in the Comments section. And if you liked the article, don't forget to share it with your friends!


by Barış Ünver via Tuts+ Code

How to Boost Your Facebook Ad Visibility

Do you use Facebook ads to promote your business? Are you struggling to connect with your audience? By fine-tuning your Facebook ads, you can capture the attention of both customers and prospects. In this article you’ll discover how to boost the visibility of your Facebook ads. #1: Use a Clutter-Free Image With Minimal Text The […]

This post How to Boost Your Facebook Ad Visibility first appeared on Social Media Examiner.
Social Media Examiner - Your Guide to the Social Media Jungle


by Lisa Larter via Social Media Examiner

Stephen says hello…

Stephen says hello...

Colorful parallax scrolling One Pager featuring fun illustrations for Melbourne-based web dev, 'Stephen Ng'.

by Rob Hope via One Page Love

VIVAP Inc.

VIVAP Inc.

Unique layout with a left off-canvas content area in this corporate One Pager for 'VIVAP Inc.'.

by Rob Hope via One Page Love

Creative Cruise

Celebrating Amsterdam's creative vibe, bringing together like-minded industry pro's from agencies based on and around the canals. Hop on board for beers and beats.
by via Awwwards - Sites of the day