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-color);

CSS Code View

What is the difference between CSS variables and preprocessor variables?

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 spring 2017 and was available within a month on most major browsers. Where Flexbox handles one dimension at a time — either a row or a column — Grid handles both simultaneously, giving you direct control over the horizontal and vertical structure of a layout in a single system.
    Use Flexbox when you have a set of items and want the browser to figure out how to distribute them. Use Grid when you already know the structure and want to place things precisely within it. In practice, you will use both together: Grid for the page-level skeleton, Flexbox for the components that live inside it.
    For quick reference use the CSS Grid Cheat Sheet. For a deeper introduction, Mozilla’s Grid article is the best starting point. Rachel Andrew’s Grid by Example collects ready-to-use patterns on CodePen. CSS Tricks has a complete reference guide. When debugging, open Firefox’s inspector, click on any grid element, and activate the grid overlay — it draws the lines directly on the page.

    Grid Terminology
    Grid lines are the invisible horizontal and vertical dividers that define the grid. They are numbered starting at 1 from the top-left. Negative numbers count inward from the far edge: -1 is always the last line.
    Grid tracks are the rows and columns between two adjacent grid lines.
    Grid cells are the individual intersections of a row track and a column track — the smallest unit of the grid.
    Grid areas are one or more adjacent cells forming a rectangle. An area can span multiple rows and columns.
    Grid gaps are the gutters between tracks. gap: 50px 100px; sets a 50px row gap and a 100px column gap. If both values are equal, use a single value: gap: 20px;.

    Grid Container (parent)
    CSS Grid controls are set on the parent element, which becomes the grid container. All direct children of the container become grid items and are placed on the grid automatically unless you specify otherwise.
    DISPLAY
    Initiate the parent as a grid container with display: grid; for a block-level container, or display: inline-grid; for an inline-level container. As with Flexbox, only direct children are affected.
    GRID-TEMPLATE-COLUMNS and GRID-TEMPLATE-ROWS
    These two properties define the track structure of the grid. The values you provide are a track list — a space-separated sequence of sizes, one per track. The spaces between the values implicitly define the grid lines.

    .grid-container {
    display: grid;
    grid-template-columns: 200px 1fr 2fr;
    grid-template-rows: auto 100px;
    gap: 20px;
    }

    Track sizes can be fixed lengths, percentages, or fractions of available space using the fr unit. 1fr means one share of the remaining space. grid-template-columns: 1fr 2fr 1fr; gives you three columns where the middle one is twice the width of the outer two.
    THE FR UNIT
    The fr unit is Grid’s native way of distributing space proportionally. It operates on the remaining space after fixed and percentage values are resolved. grid-template-columns: 200px 1fr; gives the first column a fixed 200px and the second column everything that remains.
    REPEAT()
    When a track pattern repeats, use repeat() to avoid writing it out by hand. The first argument is the repeat count, the second is the track definition to repeat.

    /* Fixed repeat: four equal columns */
    grid-template-columns: repeat(4, 1fr);

    /* Auto-fill: as many 150px columns as fit */
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));

    /* Auto-fit: same as auto-fill but collapses empty tracks */
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));

    auto-fill and auto-fit are the key to responsive grids without media queries. The grid creates as many columns as fit at the minimum size, and grows them to fill available space. The difference shows when there are fewer items than columns: auto-fill keeps the empty tracks, auto-fit collapses them so the existing items can expand.
    NAMED LINES
    Grid lines can be named by inserting square brackets between track values. Names make placement code more readable and less dependent on counting line numbers.

    grid-template-columns: [sidebar-start] 200px [sidebar-end content-start] 1fr [content-end];

    A line can have more than one name, separated by spaces inside the brackets.
    GRID-TEMPLATE-AREAS
    Grid areas let you assign names to regions of the grid and then place items by name rather than by line numbers. This makes the layout intent immediately legible from the CSS.

    .grid-container {
    display: grid;
    grid-template-columns: 200px 1fr 200px;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
    “header header header”
    “sidebar content aside”
    “footer footer footer”;
    }

    header { grid-area: header; }
    .sidebar { grid-area: sidebar; }
    main { grid-area: content; }
    aside { grid-area: aside; }
    footer { grid-area: footer; }

    Each string in grid-template-areas represents a row. Each word within the string represents a cell. An empty cell is denoted by a period .. Every named area must form a rectangle — L-shapes are not valid.
    JUSTIFY-CONTENT and ALIGN-CONTENT
    These properties control how the entire grid is positioned within the container when the grid is smaller than its container. justify-content operates on the inline (horizontal) axis, align-content on the block (vertical) axis. Values are the same as Flexbox: start, center, end, space-between, space-around, space-evenly.
    JUSTIFY-ITEMS and ALIGN-ITEMS
    These set the default alignment of all grid items within their cells. justify-items aligns items horizontally within the cell, align-items aligns them vertically. The default for both is stretch, which is why grid items fill their cells unless you specify otherwise. Other values: start, center, end.

    #areas {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    grid-template-areas:
    “header header header header”
    “sidebar content content aside”
    “footer footer footer footer”;
    gap: 10px 20px;
    justify-items: stretch;
    align-items: stretch;
    }

    LIVE DEMO
    header / sidebar / content / aside / footer

    Intrinsic and Extrinsic Sizing
    Grid tracks can be sized either by the container (extrinsic) or by their content (intrinsic).
    Extrinsic sizing uses values like fixed lengths, percentages, and fr. The container defines the track size and the content must conform. grid-template-columns: 200px 1fr 2fr; is fully extrinsic.
    Intrinsic sizing uses auto, min-content, max-content, or fit-content(). The content defines its preferred size and the grid adapts. grid-template-columns: max-content auto; gives the first column exactly the width of its widest item.
    The power of Grid is that you can combine both in a single definition. grid-template-columns: max-content 1fr minmax(150px, 25%); gives you a content-fitted first column, a flexible middle, and a constrained third. minmax() takes a minimum and maximum and lets the track size negotiate between them.

    Subgrid
    A grid nested inside another grid has no connection to the parent grid’s line structure. Columns and rows in the child are independent and cannot be made to align with the parent. Subgrid solves this.
    Setting grid-template-columns: subgrid; on a child element tells it to inherit the parent’s column tracks across whatever span the child occupies. The child does not define new tracks — it participates in the parent’s.

    .parent {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: 1rem;
    }

    .child {
    grid-column: 1 / -1; /* span all columns */
    display: grid;
    grid-template-columns: subgrid; /* inherit parent’s columns */
    }

    Without subgrid, card components in a grid will have internal elements — headings, body text, footers — that cannot be made to align across cards without either JavaScript or fragile fixed values. Subgrid makes that alignment automatic and responsive.

    Grid Item (children)
    Grid items are the direct children of the grid container. By default they flow into the grid sequentially, filling cells left to right and top to bottom. Any or all of them can be placed and sized explicitly using item-level properties.
    GRID-COLUMN and GRID-ROW
    Place an item by specifying which grid lines it should start and end on. grid-column: 2 / 4; spans from column line 2 to column line 4, occupying two column tracks. Use span as shorthand: grid-column: 2 / span 2; means the same thing. Use named lines if you defined them: grid-column: sidebar-start / content-end;.
    GRID-AREA
    grid-area is shorthand for all four placement values at once: grid-row-start / grid-column-start / grid-row-end / grid-column-end. When using grid-template-areas, grid-area is also how you assign an item to a named area by name.
    ORDER
    As in Flexbox, order changes the visual position of an item relative to its auto-flow position without changing the HTML. Default is 0. Negative values move an item earlier, positive values move it later. Use with caution — it disconnects visual order from DOM order, which breaks keyboard navigation and screen reader sequence.
    JUSTIFY-SELF and ALIGN-SELF
    Override the container’s justify-items and align-items for a single item. Useful for exceptions: a single item that should be centered while the rest stretch. Values: start, center, end, stretch.

    .grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    align-items: stretch;
    }

    .grid-container div:nth-child(1) {
    grid-column: span 2;
    }

    .grid-container div:nth-child(3) {
    justify-self: center;
    align-self: end;
    }

    .grid-container div:nth-child(4) {
    grid-row: span 2;
    }

    LIVE DEMO
    Box spanning two columns / single box / centered and bottom-aligned box / box spanning two rows

    Page Layout Demonstration
    The Holy Grail layout — header, three-column body with sidebar and aside, footer — was the white whale of CSS layout for a decade. It required floats, negative margins, and a careful ordering of columns in the HTML to make the main content column appear first for screen readers. With Grid it is a dozen lines.

    .holy-grail {
    display: grid;
    grid-template-columns: 200px 1fr 200px;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
    “header header header”
    “sidebar content aside”
    “footer footer footer”;
    min-height: 100vh;
    gap: 20px;
    }

    header { grid-area: header; }
    nav { grid-area: sidebar; }
    main { grid-area: content; }
    aside { grid-area: aside; }
    footer { grid-area: footer; }

    @media (max-width: 600px) {
    .holy-grail {
    grid-template-columns: 1fr;
    grid-template-areas:
    “header”
    “content”
    “sidebar”
    “aside”
    “footer”;
    }
    }

    The HTML order can now match reading order — header, main content, navigation, aside, footer — independent of the visual layout. The responsive version requires only a redefined grid-template-areas in the media query. No floats, no clearing, no negative margins.

    01 Design Fundamentals

    All communication is in need of design. While Parsons teaches the visual literacy required for your area of concentration, communication and web design share fundamentals that make for a good product.

    Empathize

    THE HEART OF DESIGN

    Designers work to solve others’ problems but the most insightful and innovative design work begins with empathy. Slip on your users’ shoes and seek to gain understanding with an open mind. You’ll be surprised what deep needs and insights you can uncover.

    Define

    REFRAME THE PROBLEM

    A single image of the earth from the moon shifted the course of environmental history. A new point of view on a design problem can shift your perspective just as much. Learning to reframe your point of view based on insights from your users can be a powerful design tool.

    Ideate

    BEYOND BASIC BRAINSTORMS

    Ideation early in the design process helps teams get aligned and find potential solutions to investigate. While most teams use some form of ideation, design thinking can lend new structure and spark the brainstorming process.

    Prototype

    GET SMARTER, FASTER

    The smartest design teams build prototypes throughout the design process. Rather than discover issues after the expense and time spent on building a complete product, challenge assumptions and solve disagreements through iterative prototyping.

    Test

    EARLY AND OFTEN

    Prototyping forms a key step in solid product design, but the best design teams go a step further and test their products with real users. Observing how your end user approaches your product gives you the most important feedback of all.