Lemieux Design

Flash | Interactive | Web | Graphics | Brand | Video

Archive for the ‘Web Design’ Category

CSS Grid Course from Wes Bos

Posted on: July 3rd, 2018 by alemieux

CSS Grid Course

Coding guru and whiz Wes Bos put together a free online course on CSS Grid. I recently finished the course and have to say it was awesome!

Like his other courses, Wes focuses on the things that are important and gets right to it. There’s not a lot of chit chat and useless conversation—it’s all about the coding. I followed along with him (he gives all of the exercise files and more) and was really impressed by the way in which we go from zero to a full grid layout in a matter of minutes. He’s so fast in the code editor, you can tell he codes everyday. There were many times I had to pause the videos to catch up.

There are 25 lessons and the first 18 – 19 are all about the nuts and bolts of grid and how it works. There are several exercises and explorations on grid properties and situations. Then he progresses into practical applications of grid for responsive design, as an alternative to Bootstrap, for image galleries and more. It really comes together in the last 5 videos.

There are some golden nuggets in the first video in terms of his setup and how he uses NPM browser watch that really is a great productivity increase. He even sprinkles in some JavaScript. I highly recommend it.

Learn more about the course here: https://wesbos.com/announcing-my-css-grid-course/

CSS Variables

Posted on: June 28th, 2018 by alemieux

I’m not a fan of LESS or SASS, at least for my workflow. In marketing, I usually am designing landing pages or one-off experiences that don’t require a ton of styles to manage. I’m not collaborating with other designers who are also in the same code as I am.

I have played around with SASS, so I was familiar with the concept of setting variables. Having read a few articles on CSS Variables (Custom Properties), I was blown away by the utility of it. To set a property once and apply it throughout a design so that if and when it changes, it ripples through and changes it everywhere. That’s pretty powerful for CSS, which isn’t a programming language.

Support is pretty good except for IE and Opera Mini, but no surprises there. All of the major vendors do support it.

There are a couple of ways to implement vars in your stylesheet, but I feel like the most useful way is to use it in the :root selector, which is a unique selector that can store all the variables for your web application in one place. Here’s an example:

:root {
–purple: #cc69a7;
}

Notice the syntax of the variable is two dashes followed by the name of the variable and its property. The :root selector will have effect throughout the stylesheet and can be overridden in other selectors by declaring variables within them and using them there.

To apply a variable to a property within a selector, you use the var() command and call on the name of the variable:

.header {
background-color: var(–purple);
}

Variables can contain property values for color, font-family, box shadow, and any other property you can think of. It’s pretty amazing when you begin to realize the power of setting things for consistency throughout a design.

Here’s a basic code example:

See the Pen CSS Variables test by Al Lemieux (@alemieux) on CodePen.

Without a doubt, I’ll be putting this to good use in the future.

CSS Grid

Posted on: May 30th, 2017 by alemieux

I attended An Event Apart in Boston this May for an all-day workshop Designing Layouts: The New Superpowers of CSS, with Jen Simmons, Designer Advocate at Mozilla. I admit, I was a little skeptical that CSS Grids would be the answer and end all for web layout moving forward. However, after just a few demonstrations and seeing how little code was needed, my jaw hit the floor.

Simmons began the day by articulating Writing Modes, which at first myself and other participants were wondering “What does this have to do with CSS Grid?” Globally, about 70% of languages are left-to-right horizontally and top to bottom vertically when reading and writing. Some languages are right-to-left, like Chinese and some are totally different, like Mongolian. Since this applies to web pages, there are ways to control text-direction and other properties to affect the way a page is read. These can be manipulated via CSS. The most important concept that comes out of Writing Modes is Start and End. A block of text starts on left and ends on the right of a row. The start of a column of text is at the top and ends at the bottom. This aspect is also part of the CSS Grid specification.

We briefly took a look at support across browsers for CSS Grid. It was a hidden feature for a while, but now is fully supported in the major browsers with partial support for IE and Edge. Using the @supports media query though, graceful degradation can be utilized to serve it up to those major browsers while traditional layout methods are used in the main stylesheet for all the rest. As dismal as that sounds, the arguments for the grid are so compelling that I think a majority of designers will push for it and get on board with the code sooner than later. Something to note is that this is not a replacement for Flexbox. Flexbox has its place in web development and can be used in conjunction with the grid.

Probably the most amazing thing about CSS Grid is that it does not exist in the DOM. It’s not a new set of HTML tags or attributes. It is pure CSS. The beauty of this is that the order of page elements can be changed without touching the HTML structure. With a few lines of code, you can start a grid layout quickly and easily. Some terminology is needed first for an understanding of how the grid works. First, the grid needs a container defined with display: grid; to start a layout:

ul { display: grid; }

The grid consists of Grid tracks, grid items, grid cells, grid areas, grid lines and grid gaps.

Grid Terminology

Grid tracks are either grid columns or grid rows. Grid lines are important and not visible when you enable the grid. If you download Firefox Nightly though, you can enable the Layout Panel, which can show you the grid lines, which is very helpful when trying to understand CSS Grid.

Firefox Nightly

Starting off with a basic example. This is just a basic unordered list which would normally appear as a vertical list of text. By adding display: grid to the ul (container), we can then set up the grid using grid-template-columns: repeat(3, 1fr); This sets up a 3-column grid with each column being 1/3 of the width. The browser does all of the calculations and gives equal widths to each column and if needed, automatically gives us rows for when there are more the 3 elements in the list. We could’ve specified the grid-template-columns as 1fr 1fr 1fr, but the repeat syntax does this for us. 1fr is a new unit which is a fraction unit. We can also specify columns in pixels, ems, percentages too. Try changing the grid-template-columns to 1fr, 200px, 5em. The browser will first calculate the space needed for the second and third columns and the attribute the rest of the space to the first column. The other aspect of the grid that’s specified in this example is the grid-gap, which gives us the white space between the grid tracks. When flexing the browser width, the grid cells are flexible.

See the Pen CSS-Grid Simple Example by Al Lemieux (@alemieux) on CodePen.

In this next example we can also use the grid to explicitly place elements into grid cells. This is where grid-column-start and grid-column-end, grid-row-start and grid-row-end come into play. The grid is set up on the container (again an unordered list) and each list item is sent to a specific cell in the grid with grid-column and grid-row. Grid-column: 1 / 2 means start on grid line 1 and end on grid line 2. If you play with the designation of each rule, you can change the location of the items on the grid.

See the Pen CSS-Grid Explicit Placement by Al Lemieux (@alemieux) on CodePen.

Probably the most promising factor for CSS Grid is named Grid Areas. An area on the grid could span multiple columns and rows. You can assign a grid area a name so that when you call it in the code, you can recognize it. In the following example, HTML elements are given grid area names:

header { grid-area: header; }
footer { grid-area: footer; }

The named grid area names are then used in the grid container to define the areas for layout.

body { grid-template-areas: "header" "main" "sidebar" "footer"; }

See the Pen CSS-Grid Named Areas by Al Lemieux (@alemieux) on CodePen.

Notice the media query for larger browsers. This sets the layout to:

grid-template-areas: "header" "header"
"sidebar" "main"
"footer" "footer"

We can switch the location of the sidebar and the main content area by updating the code order:

grid-template-areas: "header" "header"
"main" "sidebar"
"footer" "footer"

I’m still playing around with the concepts and wrapping my head around the code. All of the examples I’ve built so far are a lot easier than floating elements, worrying about their container collapsing, or relative and absolute positioning. With minimal code, a layout can be achieved rapidly with minimal issues. More complex layouts might be more challenging, but I’m open for that. The next version of Bootstrap will have the grid built into it and I imagine that a lot of CMS themes will come out soon taking advantage of CSS Grid.

RESOURCES

I highly recommend checking out Jen Simmons’ labs site labs.jensimmons.com for a variety of examples and resources.

There’s also Rachel Andrews site Grid By Example, which is good source for examples.

Also, check out the fun and informative game that helps you learn CSS Grid CSS Grid Garden.

Smooth Scrolling – With Bootstrap

Posted on: January 16th, 2017 by alemieux

Sending users to in-page targets with an ID can be jarring. They might lose context of the page when they move further down and they lose site of what came previously. A smooth scrolling animation can solve this issue and looks great!

This Pen has a great example: http://codepen.io/chriscoyier/pen/dpBMVP However, the page I was building also included Bootstrap Panels (Accordion). Since the target is any ID on the page, that will include the targets in the Panels, so it broke the functionality. I did some brief searching and found a StackOverflow response that tweaks the code to refine the targeting so as not to affect Bootstrap Carousels, or Panels. Here’s the full code:

$(document).ready(function() {
$('a[href*="#"]:not([href="#"]):not([data-toggle])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});

Now I have the functionality I want for scrolling to targets and the Panels still work.

5 Things I Learned in Web Design 2014

Posted on: December 22nd, 2014 by alemieux

Looking back on this year, I’ve learned some things for web design that’s made coding a bit easier if not more enjoyable. Some of these came about as a set of circumstances and others I just stumbled on. I hope you find some value in these too.

Bootstrap

Bootstrap

After wrestling with WordPress for so long, I started looking into some HTML frameworks for some boutique sites that I needed to build quickly. I heard about Bootstrap from a co-worker and she was using it for a the apps that her team was developing it. Once I started in, the full breadth of it was impressive and it took a while to get used to the grid system, but once I did, I saw the potential.

There are some really great things about Bootstrap that are baked in, like Buttons, forms, navigation, responsive images, and some great JavaScript components. I’ve used Bootstrap for a few sites now and beat up on it pretty good. It’s pretty stable / reliable and I really like the fact that there’s plenty of examples and good documentation on their site.

Media Queries

Media Queries

I must admit, that I was struggling with this one for a while. I understood the basic concept but its practical applications eluded me. I spoke to a friend about it and he simplified it for me. The trick is to start by creating all of your standard styles for mobile view first and then add media queries to support larger layouts. It made great sense and I still use that advice now.

JQuery

JavaScript & JQuery

I used JQuery heavily in a game that I created for a conference at work. Selecting elements and manipulating them with JQuery is so easy and JQuery offers some really powerful libraries to get things done. I was able to quickly create a working prototype with JQuery and then take that into full development.

John Duckett’s JavaScript & JQuery book offered some more great insights into JQuery that made me appreciate the language more.

.net Magazine

.net magazine

While wandering around Barnes & Nobles, I stumbled on .net magazine and was instantly hooked. This web resource magazine is packed with insightful articles, tutorials and information on best web practices and tools. The subscription price tag is pretty hefty, but the content is great. The November issue on Responsive Web Design was particularly helpful.

They have a great section of the mag called Showcase, which showcases websites from all over that are pretty fantastic. There’s a brief background story behind how each were built and it’s very inspiring. I highly recommend it.

Firebug

Firebug

I’ve been using Firebug for a while now, but I really started using the Console and debug mode this year. It’s making development easy for me. Not only do I inspect other site’s code, but I inspect my own code and am able to troubleshoot style and code issues. I do like Chrome’s dev tools, but I’m so used to Firebug now. Firebug’s add-ons are great too.

So there you have it, 5 things that made my life easier this year. What tools and sources made your life easier this year?

RWD – Media Queries Introduction

Posted on: December 19th, 2014 by alemieux

Media Query Basics

No, I’m not going to start in on the history of the @media usage in HTML. I’d rather focus instead on the practical uses of the @media property as it relates to Responsive Web Design. But first, a practical tip.

In Luke Wroblewski’s now famous Mobile First approach, we start by designing a site with the smallest screen in mind first. What that really means is that you develop all of your content in such a way that will engage mobile users who, most likely, are on devices that are on slow networks and might not be able to support all the whiz-bang that a desktop browser might be able to handle.

There are some pretty staggering statistics of mobile phone usage in third world countries. Most internet activity is achieved over mobile networks with an array of devices that aren’t that sophisticated and can’t handle most modern website features.

There’s also an important movement to improve website performance for such devices and platforms as illustrated in Scott Jehl’s new book Responsible Responsive Design. Certain design trends offer huge, full-width imagery or video. Learning what’s served best on the mobile platform is trial and error, but the basic idea is the limit the use of heavy graphics, video, and JavaScript effects for smaller devices. More importantly, the content needs to be tailored for small screens so that what’s hierarchically most important is easy to find and is most useful.

With those limitations in mind, start by building the site in a mobile view. You can resize your browser to its smallest width possible. In Firefox, you can use the Responsive Design View and choose the 320 pixel width, which will be the smallest screen size. Load up your page and start coding.

One handy tip that I learned straight away was to include all of the essential styles outside of any media query. You’ll want to establish your font sizes, colors and navigation first, working towards what will work best on the small screen. I thought that I would only put those styles into a media query that targets small screens, but that’s not the Mobile First workflow.

Once you’ve established your base styles and things in the mobile view are looking good, you can now start to resize the browser or switch to a wider layout (possibly to target Tablets).

Max and Min Width

The key components to a media query are max-width and min-width. Let’s define what those mean:

max-width Anything less than the value you have after it.

Ex.

@media screen and (max-width: 780px)

What this query is targeting is anything less than 780 pixels.

min-width Anything greater than the value you have after it.

Ex.

@media screen and (min-width: 1920px)

This targets anything greater than 1920 pixels.

It seems backwards, but this is the way that media queries work.

In Responsive Web Design, your HTML structure and CSS styles should be flexible enough that when the layout changes to accomodate different screen sizes, that the text reflows and images and videos scale. What it doesn’t account for is when layouts break. Say for example, you have a 4-column section on your site that has the bios of 4 different speakers for an event. Those columns are floated to the left and sit right next to each other in a desktop layout, but what should they do on a mobile screen? The floats should be removed so that the columns become stacked. That’s where you’ll need a media query.

Targeting and Breakpoints

The whole idea of using a Media Query is to change the layout at a certain point where it’s no longer viable on a certain device, as in the example above. When that happens, we define a breakpoint. This is your target and now you’ll need to write your media query. Following the example given, we may want to reduce the 4 columns long before we come down to a 320 pixel width. You might target anything under 480 pixels like this:

@media screen and (max-width: 480px) {
.bios { float: none; }
}

So, anything below 480 pixels and the floats are removed from the Bio section and those columns now get stacked.

See the Pen Media Query Example by Al Lemieux (@alemieux) on CodePen.

Using proportional units is best, so we can convert those pixels into ems:

480 / 16 = 30

So our media query now looks like this:

@media screen and (max-width: 30em) {
.bios { float: none; }
}

The exercise continues — resize the browser, find points that break your layout and then add breakpoints to adjust.

Base Font Size

One final consideration is base font size. We already talked about font sizes and line heights in this series. We’ve established that the base font size is 100% or 16px and the line height is 1. You can adjust the base font size up or down in your media queries. 16px body text and 36px headlines might be too large on a mobile device. You may have your base font size reduced in your body declaration to some percentage as it is comfortable to read on a small screen:

body { font-size: 70%; }

Then, in your media queries, you can increase that base font size for larger screens:

@media screen and (min-width: 80em) {
body { font-size: 90%;
}

@media screen and (min-width: 120em) {
body { font-size: 110%; }
}

I hope you’ve enjoyed this primer on media queries. We’ll get deeper into it next time, but this is a good foundation and is common practice these days. Be sure to check out the other articles in this series: