10 CSS Calc

CSS calc() performs simple calculations to determine CSS property values. The calc() function allows mathematical expressions with addition ( + ), subtraction ( – ), multiplication ( * ), and division ( / ) to be used to create a value. A useful feature of this function is the ability to mix percentages and absolute values or to mix different units. Pixels can be subtracted from percentages and viewport widths can be added to pixels, for example.

CSS calc() can be used anywhere there’s a css length or number in your stylesheet. .item { width: calc(100% - 60px);} Notice that the operator has a space on either side. That is a requirement for + and - . Leaving it out renders the calculation void. Dividing by 0 voids the result as well.

CSS Tricks has a Complete Guide to Calc

For those of you that are mathematically inclined, calculate sine, cosine, tangent. Check out this trig functions in CSS article.

CSS Code View

using calc to change text size

10 CSS Variables

CSS variables are entities defined by CSS authors that contain specific values to be reused throughout a document. Variables or CSS Custom Properties for Cascading Variables have a precursor of sorts in curentcolor. Currentcolor sets the current color as a variable with that name. It was originally introduced by Opera. Various CSS preprocessors are popular because they implemented variables.

Variables save time and help in the organization of complex documents. It is part of the computer programer’s ethic known as DRY or don’t repeat yourself. Create a variable for colors used in developing the website. To change a color only the definition has to be updated. CSS variables work like any other CSS custom property, like normal CSS properties. CSS variables can be used almost everywhere there are values, including in @media queries.
The variable is defined by -- dash dash, like an empty prefix. Think of it as -webkit- without webkit. The variable is case sensitive and defined as a :root pseudo-class . For example: :root { --main-color: orange;}.

The variable is then applied as a value: background-color: var(--main-bg-color);

CSS Code View

10 Responsive Images and Video

Images and videos can be resized the same way that background images can be resized. Videos can maintain their proportion in what is a boon for responsive design. The object-fit and object-position properties define how an element responds to the height and width of its content box. The object-fit property implements cover and contain to determine the size of an image based on its longest or shortest length. There is also a scale-down value that keeps an image in proportion as it is resized (think video). The object-position property allows placement of the image in the box. The default is 50% 50% which centers the image. In the following demo, the images is enlarged to fill the box using cover, pinned to the left side center. The image will resize proportionally with a change in the box’s size.

CSS Code View

Taiyo in image size demonstration

Video

It is important to keep video ratio in proportion. Previous hacks used percentage based bottom padding of the parent container’s width and stretched the video to that ratio. It’s now possible to specify contain or scale-down.

04 Multiple Columns

CSS3 provides several new ways to do layout. The easiest is multiple columns within an element. It’s easy to create multi-column layouts using the new CSS3 multiple columns property. The document flow can create more columns inside a box than is visually pleasing, so change it to one, two, three or four columns, depending on the size of the screen. Using media queries a small screens gets one column, tablets get two and computer monitors get three or more columns.

Multi-Columns Interactive

CSS Code View

Live Demo

What is “Fun?”

“I’ll know it when I see it.”

As designers, we get a lot of similarly elusive adjectives from clients, as they tell us what they want their sites to be: “The site needs to be ‘cool,’” “It should be ‘exciting,’” “I want it to ‘pop.’” When we ask them to clarify, the answer we get back sounds a lot like “I can’t tell you what it is, but I’ll know it when I see it.”

“Fun” is a particularly difficult concept to define. And we’re starting to hear it a lot more from clients as we design for different contexts of use.

So what’s a designer to do?

04 Grids and Whitespace

CSS Grid is revolutionary. Up to 2018, the exploration of web layout strategies has been along the lines of a word processor. You start at the top and create content vertically as elements stack like blocks, which is easy, and horizontally, by limiting the width of the elements so you can go from left to right. The activity of designing web pages as if one were designing in Microsoft Word has come to an end! CSS Grid is here! You create the grid and then populate it in any way and in any order you see fit, creating white space wherever you deem esthetically pleasing or communicatively correct.

Allow Massimo Vignelli to introduce grids.

Grids

For us Graphic Design is “organization of information.” There are other types of graphic design more concerned with illustration or of a narrative nature. Nothing could be more useful to reach our intention than the Grid. The grid represents the basic structure of our graphic design, it helps to organize the content, it provides consistency, it gives an orderly look and it projects a level of intellectual elegance that we like to express.

There are infinite kinds of grids but just one – the most appropriate – for any problem. Therefore, it becomes important to know which kind of grid is the most appropriate. The basic understanding is that the smaller the module of the grid the least helpful it could be. We could say that an empty page is a page with an infinitesimal small grid. Therefore, it is equivalent to not being there. Conversely, a page with a coarse grid is a very restricting grid offering too few alternatives. The secret is to find the proper kind of grid for the job at hand. Sometimes, in designing a grid we want to have the outside margins small enough to provide a certain tension between the edges of the page and the content. After that, we divide the page in a certain number of columns according to the content, three, two, four, five, six, etc. Columns provide only one kind of consistency but we also need to have a horizontal frame of reference to assure certain levels of continuity throughout the publication. Therefore, we will divide the page from top to bottom in a certain number of Modules, four, six, eight, or more, according to size and need. Once we have structured the page, we will begin to structure the information and place it in the grid in such a way that the clarity of the message will be enhanced by the placement of the text on the grid. There are infinite ways of doing this and that is why the grid is a useful tool, rather than a constricting device. However, one should learn to use it so as to retrieve the most advantageous results.

Vignelli’s cannon
The Vignelli Canon

Vignelli has plenty to say about grids, margins, columns, and modules in his book The Vignelli Canon (pages 40 to 53) He provides a clear illustration of how to use a grid. Grid for the web is similar enough, except it is not just an organization principle but a layout tool. You will learn to use the CSS grid by using it.

Massimo Vignelli concludes his Canon with the power of white space.

WHITE SPACE

I often say that in typography the white space is more important than the black of the type. The white space on the printed page is the correspondent of space in architecture. In both situations space is what qualifies the context. Naturally, the organization of information needs a structure to hold together, but one should not underestimate the importance of white space to better define the hierarchy of every component. White space, non only separates the different parts of the message but helps to position the message in the context of the page. Tight margins establish a tension between text, images and the edges of the page. Wider margins deflate the tension and bring about a certain level of serenity to the page. Tight type setting transforms words into lines just as loose type settings transform words in to dots. Decreasing or increasing the letter spacing (kearning) confers very distinctive character and expression to the words. All this is space manipulation and it is this device that is used in layouts to achieve a desired expression. The relationship between the size of type and the space around it is one of the most delicate and precious elements of a composition. I must say that the masterful handling of white space on a printed page is perhaps the most peculiar attribute of American graphic design. Just like space is the protagonist in Frank Lloyd Wright’s architecture. Somehow, it relates to the epic grandeur of the American landscapes.

For many artists white space is the essential element of the composition. It is the fundamental qualifier and protagonist of the image. Almost all the great American graphic designers have used white space as the significant silence to better hear their message loud and clear.

Such is indeed the power of the white space.

05 CSS3 Multicolumn Layout

CSS2.1 provided basic layout modes, from inline and block and tables to positioned layout, which is either based on normal flow or a relative position from that flow, or absolute and fixed positioning, which avoids the flow all together. Add floats and the ability to change the display mode of objects, and that was what designers had to create their pages.
CSS3 adds a number of layout modules, but most are still in the process. Check the Can I Use? website and make sure the properties are well supported before using. Some of these layout strategies are Positioned Floats, Exclusions, Grid Alignment/Grid Layout, Template Layout Module and Regions, which has recently been proposed by Adobe. These new CSS modules will significantly change the Layout and Design landscape for the better.

CSS3 Multiple Column Layout

This property is mostly supported with the exception of the break before, break inside and break after properties. Mozilla is not able to span columns and it is not supported on the older IE browsers, most significantly, IE 9.

It is easy enough to create multi-column layouts using the new CSS3 multiple columns property. The document flow runs though any number of columns inside a box. In the demo, you can change the property to show a number of columns, depending on the size of the screen. A good use of multiple columns is in media queries, where small screens get one column, tablets get two and computer monitors get three columns.

Multi-Columns Interactive

CSS Code View

Live Demo

What is “Fun?”

“I’ll know it when I see it.”

As designers, we get a lot of similarly elusive adjectives from clients, as they tell us what they want their sites to be: “The site needs to be ‘cool,’” “It should be ‘exciting,’” “I want it to ‘pop.’” When we ask them to clarify, the answer we get back sounds a lot like “I can’t tell you what it is, but I’ll know it when I see it.”

“Fun” is a particularly difficult concept to define. And we’re starting to hear it a lot more from clients as we design for different contexts of use.

So what’s a designer to do?

Flexible Box Layout Module

Where multiple columns is a one trick pony for layout, flex box is a serious problem solver. It automatically adjusts boxes to fit horizontally or vertically. It is almost ready for prime time. There are issues with Webkit but time will iron this out.

Flexbox is a module. That means it relies on a relationship, in this case, of a parent box and sibling boxes. Flex controls how the children behave as they align along the two axis. Depending on the direction, the main axis is horizontal or row, and the secondary axis is perpendicular to that.
flex axis demonstration

Flex-Box Interactive

CSS Code View

Live Demo

I’m Centered!

This box is both vertically and horizontally centered. Even if the text in this box changes to make it wider or taller, the box will still be centered. Go ahead, give it a try. Just click to edit the text.

Flex-Box Interactive

CSS Code View

Lorem ipsum
dolor
sit
amet
consectetur
adipiscing elit
nunc
enim
nunc
volutpat eget
aliquam
nec
accumsan rutrum
bacon
maecenasa
nunc
voldermere
it
las
quid
tostidos
gray

01 HTML5 Template Playground

The HTML and CSS PlayGround is live version of the HTML Template that contains the tags inside the tag of the HTML5 Template. Right-click (control-click)* on the code and choose Open Frame in New Window. Play and experiment until you understand the relation between the HTML content and CSS form.

* Chrome based browsers require the Open Frame extension.

04 Building A Website

Week 4
9/28

Responsive Design. The web is on display on iPhone and iPad screens to desktop computers. CSS media queries allow you to target each of these devices in one style sheet. Activity: Using media queries to target different devices.

Homework

1) Design midterm to be responsive and use media queries to target different devices. 2) Publish midterm for midterm grade. Read chapter 12. Due: The following week.

Materials For Responsive Design

Additional materials for this unit can be found by following these links:

Materials For Building a Website

Additional materials for this unit can be found by following these links (30 pages):

Materials for Fonts and Typography

Additional materials for this unit can be found by following these links (29 pages):

Goals

The goals of this unit are to:

  • Incorporate media queries into web design.
  • To design around the challenges that media queries create when layout out a page across dissimilar devices.

The future of the web is not necessarily tied to the browser window that you have been using. Chances are that it’ll be mobile. Spanning screens from large to small requires a complete separation between content and form, so that the content can be rearranged to fit the different viewports.

Outcomes

At the end of this unit, students will have:

  • Been prepared for a much more expansive web of the future
  • Incorporated media queries as the basis for future-proofing their own designs.
  • used the various layout strategies that CSS offers in conjunction with media queries.
  • Applied these skills to their Portfolio site.

Step-by-Step

15 Review homework and answer questions.
40 media queries
20 practice: media queries
10 break
70 Hands on in class: making the portfolio responsive

Talking Points

Topics covered in the reading:

Chapter 12: Style Sheets for Mobile to Desktop

  1. Mobile Strategies and Considerations 328
  2. Understanding and Implementing Media Queries 333
  3. Building a Page that Adapts with Media Queries 340

Current Practices

Responsive Web Design is all over the web. In its short existence, no big site has not been redesigned to take advantage of it, and many do it very well:

  • This Is Responsive
  • Mule Design Holiday Party
  • Caava Design
  • Frank Chimero
  • Blood, the Branding Agency
  • Women and Tech
  • Jeremy Holmes Studio
  • Adobe HTML
  • Disney
  • Edita’s Casting
  • Rich Brown
  • Etch

    News and External Resources

    Inspirational Links to help you explore in preparation for the final.

    1. Smashing Magazine’s Mobile Content Strategy article.
    2. Google’s Friendly Mobile Test. Does your site pass?
    3. Google’s Page Speed Test. This test (and recommendations on how to fix the problems) are a great way to make sure your site is as good as it can be.

    Definitions

    These are the terms that participants should be familiar with during this unit:

    Responsive Web Design article from Wikipedia

    Responsive Web Design (RWD) is an approach to web design in which a site is crafted to provide an optimal viewing experience—easy reading and navigation with a minimum of resizing, panning, and scrolling—across a wide range of devices (from desktop computer monitors to mobile phones).

  • 04 CSS Grid

    CSS Grid was finalized in the spring of 2017 and was available within a month on most browsers.

    Where Flexbox is for only one dimension, either horizontal or vertical, grid is for two dimensional layouts, both horizontal and vertical.

    CSS Grid and Flexbox are changing layout. It will take a while for the changes to settle in and for best practices to arise. Play around with ready made interactive examples. You will be required to create layouts using CSS grid and flex.

    There are many resources to better understand how css grids work.

    Mozilla Grids article is a great place to start.

    Rachel Andrew’s Grid by Example / Patterns is good too. She is a CSS grid ambassador and has various layouts prepared on CodePen. You can use them to start your layout.

    Smashing Magazine ran a CSS Grid contest and came up with some great examples. The demonstration has lots of cutting edge CSS features in addition to using grid. For other examples using CSS grid, check out this restaurant menu or a modern blog . Looking through the code will provide you with ideas on how to implement your own CSS grid.

    In the FireFox browser use the Inspect Element on the grid item and click on the grid features for visual aids in understanding how the grid is implemented. The other browsers have not followed, open up inspector and click to activate.

    Occupy only the cells of the grid you want to fill. Create white-space! Designers Rejoice!

    Grid introduces the fr unit which stands for fraction of available space.

    Jen Simmons, a designer advocate at Mozilla is a great resource, with examples and explanatory videos.

    CSS Tricks has a complete guide to CSS grid. It is well organized and clearly explained. It also has an interesting article: Hexagons and Beyond: Flexible, Responsive Grid Patterns, Sans Media Queries. A fully responsive hexagon grid made without media queries, JavaScript, or a ton of hacky CSS.

    See the Pen
    Responsive hexagon grid
    by Temani Afif (@t_afif)
    on CodePen.

    Multiple nested grids menu example does not need media queries Download code.

    CSS Grid Cheat Sheet reference is helpful to visually select the grid properties you want to use.

    CSS Grid

    basic concepts

    • The grid lines that define the grid: they can be horizontal or vertical, and they are numbered starting at 1.
    • The grid tracks, which are the rows (horizontal) or columns (vertical) defined in the grid.
    • The grid cells, the intersection of a row and a column.
    • A grid area, one or more adjacent grid cells that define a rectangle.
    Grid Box elements
    Grid Box elements

    CSS grid defines the behavior of the children of a parent block display: grid; or inline-block display: inline-grid; element. The parent element is intersected by invisible horizontal and vertical grid lines that form potential Grid Cells. Grid Tracts are spans that cover horizontal rows or vertical columns. Grid Areas are conjoined Grid Cells. Grid Gaps create space around grid lines. grid-gap: 50px 100px; is shorthand for 50 pixel column gap and 100px row gap.

    By default the grid lines are named from 1 to whatever both down and up. Negative numbers designate the order in reverse, starting from the far sides and counting back toward the near side (negative numbers are not shown in the figure above).

    Grid definitions position the content in Grid Child items on the grid. The grid is a flexible layout system designed to automatically fill out the space. It works in conjunction with flexbox in adapting layouts to available space.

    Defining The Grid: Intrinsic or Extrinsic

    The grid is intrinsic if you let the machine define the grid. Extrinsic grids are defined through CSS. Intrinsic grids automatically determine the content. Extrinsic grids determine the grid first, and then allows one to specify where the content goes through column and row properties. The following from the spec is an example of an extrinsic grid with four named areas: H, A, B, and F. The first column is sized to fit its contents (auto), and the second column takes up the remaining space (1fr). Rows default to auto (content-based) sizing; the last row is given a fixed size of 30px.