Wednesday, June 29, 2016

Introducing the CSS text-align-last Property

Sometimes tiny details that mostly go unnoticed can make or break the user experience. This can include subtle text shadows applied to a headline or proper spacing between different elements on a web page.

The text-align-last property is useful in this respect. It specifies how either the last line of a block or the line right before a forced line break will be aligned. This is important because the last line in a paragraph generally doesn't have enough text to fill up the entire space. You may or may not notice the changes but it will improve the overall look of your website.

This tutorial will cover all the aspects of the text-align-last property including acceptable values, support and browser specific behavior.

Usage and Possible Values

It is pretty simple to use text-align-last in your projects. Here is a basic snippet to align the last line of text to the right:

.intro-graph {
  text-align: justify; // Required for IE and Edge 
  text-align-last: right;
}

This property has seven possible values. You are probably familiar with the usual left, right and center values. They align the text in the last line to the left, right and center of the container.
The following demo shows the differences between these three values:

See the Pen text-align-last — Example 1 by SitePoint (@SitePoint) on CodePen.

The fourth value, justify, aligns the last line in such a way that the text aligns its left and right edges to the left and right edges of the container. This is achieved by inserting an appropriate amount of space between words when necessary. Depending on the amount of text, you can use this property to completely fill the space on the last line without too much gap between words. The text in the second paragraph is also justified but since the last line only contains one word it is aligned to the left.

See the Pen text-align-last — Example 2 by SitePoint (@SitePoint) on CodePen.

While left aligning the last line of text works for languages that are read from Left to Right (LTR), it will be wrong to do so with RTL languages. In such cases, assigning the values left or right can cause issues when you don't know the language to be used beforehand.

Fortunately, you can use the keyword start to align the text to the starting position of a line based on the direction of text. This implies that setting text-align-last to start will left align the text of LTR languages and right align the text of RTL languages. Similarly, you can use the value end to align the text to the ending position of a line based on the direction of text. This will right align the text of LTR languages and left align the text of RTL languages.

See the Pen text-align-last — Example 3 by SitePoint (@SitePoint) on CodePen.

The default value for this property is auto. In this case, the text inside the last line is aligned using the value of the text-align property unless text-align is set to justify. When set to justified, the text is justified only if the value of the text-justify property is set to distribute. Otherwise, the text is start aligned.

Continue reading %Introducing the CSS text-align-last Property%


by Nitish Kumar via SitePoint

Disco with Design Patterns: A Fresh Look at Dependency Injection

Dependency Injection is all about code reusability. It's a design pattern aiming to make high-level code reusable, by separating the object creation / configuration from usage.

Illustration of people's outlines dancing in a disco

Consider the following code:

<?php

class Test {

    protected $dbh;

    public function __construct(\PDO $dbh)
    {
        $this->dbh = $dbh;
    }

}

$dbh  = new PDO('mysql:host=localhost;dbname=test', 'username', 'password');
$test = new Test($dbh) 

As you can see, instead of creating the PDO object inside the class, we create it outside of the class and pass it in as a dependency - via the constructor method. This way, we can use the driver of our choice, instead of having to to use the driver defined inside the class.

Our very own Alejandro Gervasio has explained the DI concept fantastically, and Fabien Potencier also covered it in a series.

There's one drawback to this pattern, though: when the number of dependencies grows, many objects need to be created/configured before being passed into the dependent objects. We can end up with a pile of boilerplate code, and a long queue of parameters in our constructor methods. Enter Dependency Injection containers!

A Dependency Injection container - or simply a DI container - is an object which knows exactly how to create a service and handle its dependencies.

In this article, we'll demonstrate the concept further with a newcomer in this field: Disco.

For more information on dependency injection containers, see our other posts on the topic here.

As frameworks are great examples of deploying DI containers, we will finish the article by creating a basic HTTP-based framework with the help of Disco and some Symfony Components.

Installation

To install Disco, we use Composer as usual:

composer require bitexpert/disco

To test the code, we'll use PHP's built-in web server:

php -S localhost:8000 -t web

As a result, the application will be accessible under http://localhost:8000 from the browser. The last parameter -t option defines the document root - where the index.php file resides.

Getting Started

Disco is a container_interop compatible DI container. Somewhat controversially, Disco is an annotation-based DI container.

Note that the package container_interop consists of a set of interfaces to standardize features of container objects. To learn more about how that works, see the tutorial in which we build our own, SitePoint Dependency Injection Container, also based on container-interop.

To add services to the container, we need to create a configuration class. This class should be marked with the @Configuration annotation:

<?php
/**
 * @Configuration
 */
 class Services {
    // ...
 }

Each container service should be defined as a public or protected method inside the configuration class. Disco calls each service a Bean, which originates from the Java culture.

Continue reading %Disco with Design Patterns: A Fresh Look at Dependency Injection%


by Reza Lavaryan via SitePoint

Acqua del Garda Perfumes

Brand of Italian perfumes and skin care products inspired by the scents of the land surrounding the Lake Garda, the biggest and most loved lake in Italy.


by csreladm via CSSREEL | CSS Website Awards | World best websites | website design awards | CSS Gallery

Bruk

David Guba is a freelance Web (UI/UX) Designer based in Hungary.


by csreladm via CSSREEL | CSS Website Awards | World best websites | website design awards | CSS Gallery

Bangui Oubliee

Discover the activities of the NGO Action Against Hunger in Central African Republic, through a VR experience.


by csreladm via CSSREEL | CSS Website Awards | World best websites | website design awards | CSS Gallery

Android From Scratch: How to Use Resources In an Application

This Week's HTML5 and Browser Technology News (Issue 246)


Read this e-mail on the Web
HTML 5 Weekly
Issue 246 — June 29, 2016
Zack Bloom
A enjoyable essay looking at technologies and approaches that were proposed for styling Web documents before CSS became the firm favorite.


Brandon Smith
“Few things are as annoying on the web as having the page layout unexpectedly change or shift while you’re trying to view or interact with it.”


Lynn Fisher
Detailed, elegant icons rendered with CSS upon just one div element. (You’ll want to open your browser's element inspector to dig into these.)


Red Gate  Sponsored
Boost the performance of your .NET application with ANTS Performance Profiler. Get rich performance data on your code and database queries to find your application's bottleneck fast. Try ANTS Performance Profiler on your app now.

Red Gate

Myles Maxfield
“Many fonts are large, causing a long delay until the browser can use them. WebKit has mitigated this.”


Baljeet Rathi
Baljeet Rathi explains the various CSS image replacement techniques available to web developers today and their pros and cons.


Zack Bloom
Mutation Observer is a feature, supported by all modern browsers, that let you detect when elements in a page are inserted, changed or removed.


Neil Jenkins
What is the Referer header and how can you control its presence (or lack thereof)? A handy resource for security-minded Web developers.


Bryan Elkus
A quick walkthrough of building your first animation with Velocity.js to animate a list. Includes a CodePen example.


Chris Brandrick
We’ve taken a look through all the stats from HTML5 Weekly published so far in 2016 and collected the most popular CSS links we shared.


Jobs

In brief

Curated by Peter Cooper and published by Cooper Press.
Want to post a job? E-mail us or use our self-serve system.

Unsubscribe : Change email address : Read this issue on the Web

Published by Cooper Press Ltd. Office 30, Lincoln Way, Louth, LN11 0LS, UK


by via HTML5 Weekly