Monday 29 August 2011

CSS3 Flexible Box Model | Van SEO Design

CSS3 Flexible Box Model | Van SEO Design


CSS3 Flexible Box Model

Posted: 29 Aug 2011 05:30 AM PDT

CSS offers several tools to help with site layout. Over the years we’ve worked mainly with floats, positioning, and margins, but let’s face it, most of us would like more. Fortunately css3 is giving us more tools for layouts. One of those tools is the flexible box.

A couple of weeks ago .net magazine published an article on The future of css layouts, in which they covered several new css3 layout modules. I’d like to work through some of them starting today with the flexible box layout module.

I’ve created a demo page illustrating some of the properties of the flexbox, though there’s not much to see in the demo that you can’t see from the images throughout this post. It’s there in case you want to play around with the source code.

Collage of browser logos

Browser Support

There’s actually pretty good support for flexible boxes in the latest browsers. Safari, Chrome, Firefox, and IE10PP all support everything discussed below.

On the other hand Opera as well as IE9 and below don’t support it so the flexible box isn’t yet ready for full time use unless you’re ok adding a javascript solution. Flexie is one such solution, though I haven’t had a chance to test it.

You should also know that the spec is changing. The latest W3C working draft and editor’s draft use different terminology than what currently works in practice. I’ll stick with the terminology that currently works and make note of the corresponding terms in the latest specs.

Also note that I’ll stick with the generic terminology in this post, but to make flexible boxes work in practice you’ll need to use vendor prefixes like -webkit and -moz.

Horizontal flexbox

Creating a Flexbox

CSS 2.1 defined 4 layout modes

  • block — for overall layout
  • inline — for text
  • table — for tabular data
  • positioned — for explicit positioning

Flexbox is a new layout mode provided by css3 and it’s similar to block layout on the surface. It lacks some properties of blocks such as floats and columns, but it adds some simple tools for aligning content inside a box.

In a flexbox content can be laid out in any direction, elements can be reordered dynamically, and the size and position of elements can flex in response to the available space.

A flexbox will act like a block when placed it other layout modes by default, but it can be set to act as an inline-box as well. Child elements of a flexbox are referred to as flexbox items.

Here’s a simple example of how it will work.

 <div id="flexbox">   <div id="box1">box 1</div>   <div id="box2">box 2</div> </div> 

Above we have a parent div with two child divs. The parent div will become the flexbox and the child divs will be the flexbox items inside the flexbox.

 #flexbox {display: box; width: 600px} #box1 {width: 300px} #box2 {width: 150px} 

Pretty simple to set up and again you need to use vendor prefixes at the moment.

  • display: -webkit-box
  • display: -moz-box

You’ll notice that horizontally we have 150px extra of space inside of the flexbox. Properties we later set on the flexbox items will allows us to modify this extra space and alter the behavior of the flexbox.

Note: In the current specs flexbox is being used instead of box so in time we’ll use display: flexbox.

Flexbox with box-orient set to vertical

box-orient and box-direction

box-orient sets the direction in which flexbox items will be laid out inside the flexbox and has several allowable values

  • horizontal — Lay out children from left to right in a horizontal line
  • vertical — Lay out children from top to bottom vertically
  • inline-axis — Lay out children along the inline axis (map to horizontal)
  • block-axis — Lay out children along the block axis (map to vertical)
  • inherit — The value will be inherited from the parent element

In the image above I set box-orient to vertical, which is probably the value you’ll set most often. Horizontal is the default.

box-direction is a more general way to set the order of the flexbox items. The one value to know about is reverse which displays the flexbox items in reverse order of how they’re listed in the html.

Note: It looks like both box-orient and box-direction are becoming the single flex-direction in the current working drafts.

flex-direction will have the associated values lr, rl, tb, bt, inline, inline-reverse, block, and block-reverse. lr stands for left to right and tb stands for top to bottom.

Flexbox items centered in flexbox through box-pack and box-align

box-pack and box-align

We won’t always want to fill up all the extra space inside a flexbox. We may instead prefer to have child elements positioned within that space, for example centered vertically or horizontally.

One property we can use is box-pack, which has associated values of start, end, center, and justify.

Start and end can ultimately be any of the 4 box sides depending on whether your flexbox is horizontal or vertical and which direction it’s items are laid out in.

 .box {box-pack: center} .box {box-align: center} 

Assuming a horizontal flexbox with no reverse set, start refers to the left edge and end refers to the right edge.

Items would be packed against this edge with the next item packed against the first. Center packs things toward the center and justify packs toward the edges.

Another property for dealing with extra space is the box-align property. It’s values are start, end, center, and stretch, which work similarly to the same values for box-pack.

A new value here is baseline which says to set each flexbox item so their baselines align and then distribute the space above and below. The baseline can be either horizontal or vertical depending on the direction of the flexbox.

Note: The current spec refers to box-pack as flex-pack and box-align and flex-align.

box-lines

The box-lines property sets how the box handles content that overflows it’s size and has the associated values single and multiple.

  • single — All child elements will be placed in a single row or column (elements that do not fit will simply be considered overflow)
  • multiple — The box is allowed to expand to multiple lines, to accommodate all of its children

Note: box-lines aren’t mentioned in the most recent spec, but the editors draft refers to flex-flow, which looks to mimic box-lines. I also haven’t been able to get box-lines working in any browser I’ve tested in.

Packaging for elastic bands showing front of flexible box

Flexbox Items

The properties above control how the flexbox itself behaves. We also have some properties to control how the flexbox items behave.

Only direct descendants of the flexbox are considered flexbox items. Children of flexbox items (grandchildren of the flexbox) are not also flexbox items of the same flexbox.

A new flexbox would need to be created for them to become new items of a new flexbox.

Flexbox with box-ordinal-group set on flexbox items

box-ordinal-group

box-ordinal-group controls the order in which the flex-items are displayed within the flexbox. The values of the box-ordinal-group property are integers.

 <div> <span id="span1">span1</span> <span id="span2">span2</span> <span id="span3">span3</span> <span id="span4">span4</span> </div> 

Above we have 4 spans inside a div. Below we’ll set the div to be a flexbox and assign a box-ordinal-group to some of the spans.

 div { display: flexbox; } #span1 { box-ordinal-group: 2; } #span3 { box-ordinal-group: 2; } #span4 { box-ordinal-group: 1; } 

Because span 4 is given a box-ordinal-group of 1 it will display before both spans 1 and 3, which have a box-ordinal-group of 2.

Span 2 doesn’t have a box-ordinal-group specified and so defaults to a box-ordinal-group of 1. Because span 2 appears in the html before span 4 and because both have the same box-ordinal-group, span 2 will display first.

The order the spans will be displayed is

  • span2
  • span4
  • span1
  • span3

This will solve a lot of the problems I talked about last week in regards to rearranging html boxes as we’ll have more control over the order the boxes are displayed.

Note: In the latest specs box-ordinal-group is being referred to as flex-order, though it will work the same way.

Flexbox with box-flex set on flexbox items

box-flex

box-flex sets whether or not the child items are inflexible or flexible and in the case of the latter, how. It tells the flexbox and flexbox items what to do with the extra space.

It’s values should be seen as fractions. An element with a box-flex of 2 would get twice the extra space as an element with a box-flex of 1.

 <div id="flexbox">   <div id="box1">box 1</div>   <div id="box2">box 2</div>   <div id="box2">box 3</div> </div> 

The above html is the same example used at the start of this post.

 #flexbox {display: box; width:600px} #box1 {width:150px; box-flex: 1} #box2 {width:150px; box-flex: 13} #box3 {width:150px; box-flex: 1} 

Again we have 150px of extra space inside the box. Here we’ve set box-flex values of 1, 13, and 1 respectively on our flexbox items.

The center flexbox item will receive an additional 130px of the extra space and the other items will each receive 10px of the additional space.

Another property, box-flex-group, is meant to group flexbox items. However at the moment it has no browser support and no mention in the latest spec.

Note: The latest working draft makes no mention of box-flex or box-flex group. Both seem to be absorbed into the flex() function, though the syntax of flex() is still under discussion.

Additional Resources

Below are some other articles that cover the flexible box layout module. They discuss the same properties as I have here and offer their own examples of the code in use.

Packaging for elastic bands showing back of flexible box

Summary

The Flexible box layout module adds a lot tools to control the boxes you create in your layouts. Hopefully you can see how much flexibility it truly adds.

There’s more support for flexboxes than you might think as long as you stick with a terminology from the 2009 spec. Do note that the terminology is changing, though it shouldn’t be hard to transition to it.

There’s probably not enough support to use flexboxes in practice, though of course it depends on what browsers you need to support.

The good news is flexbox seems to be coming in the next version of IE. The bad news is we’ll have to wait for enough people to upgrade or use a Javascript workaround. I suspect Opera will get on board soon enough.


iCan't Internet

iCan't Internet


Top 5 Most Successful AdSense Entrepreneurs

Posted: 29 Aug 2011 12:48 AM PDT

If you made $10 million a year working ONE hour a day, what would you be doing the rest of the time? Trying to figure out how to spend all your money!

[[ This is a content summary only. Visit my website for full links, other content, and more! ]]


Thursday 25 August 2011

Who Wants A Google+ Invite? | Van SEO Design

Who Wants A Google+ Invite? | Van SEO Design


Who Wants A Google+ Invite?

Posted: 25 Aug 2011 05:30 AM PDT

A few weeks ago I wrangled an invite to Google+ and now have some invites of my own to share. I thought I’d also offer a few thoughts for those of you who haven’t had a chance to get inside yet.

If you’d like an invite

  • Leave a comment below
  • when filling out the comment use the email you want the invite to be sent to
  • Your email doesn’t need to be a Gmail address
  • You will need to have or set up a Google account for the email address

I’ll send out invites to the first 50 people who ask for one, assuming there are 50 of you out there that want one.

Here’s my profile for those of you with an account who’d like to connect.

Screenshot of Steven Bradley's Google+ profile

Thoughts on Google+

I’ll spare you talk about what Google+ is or how it’s similar and different to other social networks like Facebook and Twitter. There’s plenty of information out there already that’s easy to find.

Instead I’ll offer some observations from my own use of Google+ these last few weeks.

  • I find myself checking in to Google+ more than I am other social networks
  • I find it easier to navigate and set up than Facebook
  • I like how circles makes it easy for me to send posts to different groups of people though Facebook is now adding similar controls
  • I like being able to follow people without them having to follow me back
  • Despite it’s quick growth there are far less people posting than joining

I’m following a little more than 100 people and about 40 people are following me. My network isn’t particularly large which could account for why I don’t see many people posting. Of the 100 I follow only 20 or so seem to post regularly.

On the bright side the number of people posting seems to be increasing and less people currently active means more opportunity to have a conversation and get to know others.

When I’ve sought out people to add to circles they tend to fall into one of several camps.

  • Internet celebrities
  • Internet marketers
  • Designers and developers
  • The generally tech and web savvy

Perhaps that’s more to do with my own interests than who’s really there, but understand that for now your mom isn’t there. Neither is mine.

While Google+ is growing it’s not mainstream yet. That may or may not be an issue depending on who you want to connect with.

I also find myself drawn more to the design of Google+ which makes better use of space and color than Facebook. That helps contribute to the easier navigation for me.

Why Google+

If you’re already on Facebook or Twitter you may be wondering why you should sign up for Google+

I’ll leave it to you to decide if Google+ makes sense for your personal life. It’ll probably depend on whether or not your friends are there or can be convinced to join you.

On the business side Google+ is still small so there’s opportunity to build up an influential account before the masses arrive, assuming the masses do arrive at some point. My guess is Google finally got social networking right enough that the masses will arrive in time.

Google has said a few times they look to social signals as a way to determine rankings. SEOmoz posted a few months back about how they were seeing a strong correlation between ranking and social signals. Correlation is not causation, but given how Google has said they do look at social signals it seems likely that what happens on social networks influences where web pages rank.

It also makes sense that Google will use data from their own network over data they might get from another network as they’ll have more and cleaner data from their own network.

Even without changes in ranking Google+ might already be influencing click through as results now show when your Google+ friends have +1d one of the results. You might even see the recommended content ranking better for you.

Google+ still hasn’t introduced business pages but they should be coming and again being an early adopter will probably put you in a better position once the mainstream arrives.

Closeup of an invitation

Who Wants an Invite?

Again I have invites to give out if you want in.. Just leave a comment below and use the email address you want me to send the invite to. It doesn’t need to be a Gmail account, but you will need to either have or create a Google account with a public profile in order to use Google+ with your preferred email address.

I’m guessing we won’t reach that 50 invite limit, but if there’s a large demand I’ll offer more in the near future. I want to hold some in reserve and also don’t want to overwhelm myself having to send them out so quickly.

Naturally if I do invite you I’d be happy to have you add me to a circle. Like I said there’s not a ton of conversation going on at the moment so we can easily connect.


iCan't Internet

iCan't Internet


How to Add a Printer to an iPhone

Posted: 24 Aug 2011 11:39 PM PDT

Printing from your iPhone made easy Having a printer in your iPhone will be of great help to you. This will ease your work, if maybe you have an email that you would like to send to people and it is...

[[ This is a content summary only. Visit my website for full links, other content, and more! ]]


Wednesday 24 August 2011

iCan't Internet

iCan't Internet


The Beauty Of Google Adsense

Posted: 23 Aug 2011 11:51 PM PDT

Turning a Profit Using Google Adsense Anyone can set up a website these days and earn money from the project. You don't even have to sell products or services through your site to bring in some...

[[ This is a content summary only. Visit my website for full links, other content, and more! ]]


The Best iMac apps for Your Health

Posted: 23 Aug 2011 10:48 PM PDT

Let your iMac help you get healthy Everyone is pretty familiar with the downloading apps for your phone. Angry birds, Facebook, twitter, and pandora are just a few of the regulars. Still, the iPhone...

[[ This is a content summary only. Visit my website for full links, other content, and more! ]]


Welcome to iCan’t Internet!

Posted: 22 Jul 2011 12:56 PM PDT

Tweet

[[ This is a content summary only. Visit my website for full links, other content, and more! ]]