Thursday, June 15, 2017

Realm Mobile Database for iOS

CashNotify

CashNotify

Smart One Pager promoting CashNotify - a macOS taskbar app that chimes Stripe payments 💸

by Rob Hope via One Page Love

A Practical Guide to CSS Variables (Custom Properties)

CSS Variables or Custom Properties

Preprocessors like Sass and Less certainly help to keep your CSS codebase organized and maintainable. Features like variables, mixins, loops, etc., by adding dynamic capabilities to CSS coding, contribute to minimize repetition and speed up your development time.

Lately, a few dynamic features have started to make their appearance as part of the CSS language itself. CSS variables or custom properties are already here and have great browser support while CSS mixins are currently in the works.

In this article, you'll find out how you can start integrating CSS variables into your CSS development workflow to make your stylesheets more maintainable and DRY (Don't Repeat Yourself).

Let's dive right in!

What are CSS Variables?

If you've used any programming language, you're already familiar with the concept of a variable. Variables let you store and update values your program needs in order to work.

For instance, consider the following JavaScript snippet:

[code language="js"]
let number1 = 2;
let number2 = 3;
let total = number1 + number2;
console.log(total); // 5
number1 = 4;
total = number1 + number2;
console.log(total); // 7
[/code]

number1 and number2 are two variables which store the number 2 and 3 respectively.

total is also a variable which stores the sum of the number1 and number2 variables, in this case resulting in the value 5. You can dynamically change the value of these variables and use the updated value anywhere in your program. In the snippet above, I update the value of number1 to 4 and when I perform the addition again using the same variables, the result stored inside total is no longer 5 but 7.

The beauty of variables is that they let you store your value in one place and update it on the fly for a number of various purposes. No need for you to add new entities with different values all over your program: all value updates happen using the same storage place, i.e., your variable.

CSS is mostly a declarative language, lacking in dynamic capabilities. You'd say that having variables in CSS would almost be a contradiction in terms. If front-end development were just about semantics, it would be. Fortunately, the languages of the web are very much like living languages, which evolve and adapt according to the surrounding environment and the needs of their practitioners. CSS is no exception.

In short, variables have now become an exciting reality in the world of CSS, and as you'll soon see for yourself, this awesome new technology is pretty straightforward to learn and use.

Are There Benefits to Using CSS Variables?

The benefits of using variables in CSS are not that much different from those of using variables in programming languages.

Here's what the spec has to say about this:

[Using CSS variables] makes it easier to read large files, as seemingly-arbitrary values now have informative names, and makes editing such files much easier and less error-prone, as one only has to change the value once, in the custom property, and the change will propagate to all uses of that variable automatically.

W3C Specification.

In short:

By naming your variables in ways that make sense to you in relation to your project, it'll be easier for you to manage and maintain your code. For example, editing the primary color in your project will be much easier when what you need to change is one value for the --primary-color CSS custom property, rather than change that value inside multiple CSS properties in various places.

What's the Difference Between CSS Variables and Preprocessor Variables?

One way you might have been taking advantage of the flexibility of variables when styling websites is by using preprocessors like Sass and Less.

Preprocessors let you set variables and use them in functions, loops, mathematical operations, etc. Does this mean CSS variables are irrelevant?

Not quite, mainly because CSS variables are something different from preprocessor variables.

The differences spring from the fact that CSS variables are live CSS properties running in the browser, while preprocessor variables get compiled into regular CSS code, therefore the browser knows nothing about them.

What this means is that you can update CSS variables in a stylesheet document, inside inline style attributes and SVG presentational attributes, or choose to manipulate them on the fly using JavaScript. You can't do any of this with preprocessor variables. This opens up a whole world of possibilities!

This is not to say that you need to choose between one or the other: nothing will stop you from taking advantage of the super powers of both CSS and preprocessor variables working together.

CSS Variables: The Syntax

Although in this article I use the term CSS variables for simplicity's sake, the official spec refers to them as CSS custom properties for cascading variables. The CSS custom property part looks like this:

[code language="css"]
--my-cool-background: #73a4f4;
[/code]

You prefix the custom property with two dashes and assign a value to it like you would with a regular CSS property. In the snippet above, I've assigned a color value to --my-cool-background custom property.

The cascading variable part consists in applying your custom property using the var() function, which looks like this:

[code language="css"]
var(--my-cool-background)
[/code]

The custom property is scoped inside a CSS selector and the var() part is used as value of a real CSS property:

[code language="css"]
:root {
--my-cool-background: #73a4f4;
}
/* The rest of the CSS file */
#foo {
background-color: var(--my-cool-background);
}
[/code]

The snippet above scopes the --my-cool-background custom property to the :root pseudo-class, which makes its value available globally (it matches everything inside the <html> element). Then it uses the var() function to apply that value to the background-color property of the container with ID of foo, which as a consequence will now have a nice light blue background.

That's not all. You can use the same nice light blue color value to style other color properties of multiple HTML elements, e.g., color, border-color, etc., simply by retrieving the custom property's value using var(--my-cool-background) and applying it to the appropriate CSS property (of course, I recommend giving some thought to your naming convention for CSS variables before things get confusing):

[code language="css"]
p {
color: var(--my-cool-background);
}
[/code]

See the Pen Basic Workings of CSS Variables by SitePoint (@SitePoint) on CodePen.

You can also set the value of a CSS variable with another CSS variable. For instance:

[code language="css"]
--top-color: orange;
--bottom-color: yellow;
--my-gradient: linear-gradient(var(--top-color), var(--bottom-color));
[/code]

The snippet above creates the --my-gradient variable and sets it to the value of both the --top-color and --bottom-color variables to create a gradient. Now, you can modify your gradient at any time anywhere you have decided to use it by just changing the values of your variables. No need to chase all the gradient instances all over your stylesheets.

Here's a live CodePen demo.

See the Pen Setting Value of CSS Variable with Another CSS Variable by SitePoint (@SitePoint) on CodePen.

Finally, you can include one or more fallback value/s with your CSS variable. For example:

[code language="css"]
var(--main-color, #333);
[/code]

In the snippet above, #333 is a fallback value. If fallbacks are not included, in case of invalid or unset custom properties, the inherited value will be applied instead.

CSS Variables Are Case Sensitive

Continue reading %A Practical Guide to CSS Variables (Custom Properties)%


by Maria Antonietta Perna via SitePoint

The Pros and Cons of Selling on ThemeForest

This insider’s experience has been shared by Henry Rise, the CEO of ThemeRex, Power Elite Author on Themeforest. Five years is a very long period in anyone’s life, especially if you are talking about the life of the IT business. Five years in the IT business could be regarded as 20 years in any non-virtual […]

Continue reading %The Pros and Cons of Selling on ThemeForest%


by Henry Rise via SitePoint

I’m Ready for an Online Store. What Hosting Should I Choose?

This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.

So you’re ready to launch your online store. Can you just use your existing web hosting, or do you need something special?

While eCommerce hosting doesn’t need to cost a fortune, invest the time and money you need up front to make sure you have a solution that is going to work with you—not just now, but take future growth into account as well.

If you’re planning to use a hosted solution like Shopify, and embed it into WordPress, then your hosting requirements are less stringent, since the security and heavy lifting are being taken care of by Spotify.

But if you’ll be hosting your own shopping cart software, the choice of hosting is critical. It’s a key factor in ensuring your customers have a smooth and responsive online shopping experience.

What sort of hosting should you choose? A company experienced in hosting eCommerce, and a plan optimised for eCommerce. Here are some factors to take into consideration.

1. You Need a Hosting Plan with Sufficient Storage Space and Bandwidth

An eCommerce site will need to store shopping cart software, a product catalogue, and a customer database. You need to choose a hosting plan with enough space to store all of this, and enough bandwidth for your customers to access your products, including copy, images and other resources. Err on the side of caution—underestimating your needs may lead to financial penalties if you go over your limits.

Plans with at least 2 GB of disk space and 10 GB/month of bandwidth are common, and will give you more than enough resources for an online store with thousands of products. This is a good starting point for your online store.

2. You Need Hosting that Supports Your Shopping Cart Software

There’s quite a variety of eCommerce software available today. Choose the solution that best meets your needs, then choose a hosting solution that supports the system requirements of that software—or better still, can install it with a click of the mouse.

Two powerful and free shopping carts are Magento and PrestaShop. They are full-featured, and worthy of consideration. There are also plugins for WordPress and Joomla to turn your favorite CMS into an eCommerce platform. How do you choose?

SiteGround lets you choose between 18 popular eCommerce applications, and install them automatically. Their Shopping Cart Guide will help you decide on the right software for your store. Take your time making your decision—it will be a lot of work if you change your mind later on.

Continue reading %I’m Ready for an Online Store. What Hosting Should I Choose?%


by Adrian Try via SitePoint

Hubscale

Hubscale

Clean long-scrolling Landing Page for Hubscale – a marketing tool to track digital ad campaign performance. Quite a neat even switcher where you get to meet the team and schedule a private demo.

by Rob Hope via One Page Love

What Are List Comprehensions in Python?