Styling the Cards
Self Service Design Training Exercises Exercise 12

Styling the Cards

We still need to style the cards and make sure they link to the right content.

What we want to achieve

For the cards, we will implement the following requirements:

This will transform the cards from this:

Unstyled cards

to this:

Styled cards

Initial Style

First add the following CSS to the Homepage CSS field:

Exercise 12.1

By now, you should know how this will change the styling of the cards.

Center the Text in the Cards

We will start by centering the text in the cards. You have the choice now to use the standard css text-align property or to use the Bootstrap Text Utility.

Exercise:

Using standard css, you will modify the Homepage CSS:

Exercise 12.2

Using the Bootstrap Text Utility, you will add the text-center class to the row containing the cards in the Homepage HTML:

Exercise 12.3

We prefer the Bootstrap solution, because it allows you to make text formatting responsive, e.g. text-sm-center will only center the text on viewports sized SM (small) or wider.

Adding the Icons

Throughout the Xurrent application, an icon font is used to display icons. An icon font is just like a regular font (such as Arial or Times New Roman), only it contains icons instead of letters. Icon fonts have several advantages over using images, some of which are: Xurrent has created a complete library of icons that you can use in your Self Service Design. You can find them in the Xurrent icon library. Look up the Inbox icon and use the Element Inspector of the Developer Tools to inspect the HTML. It looks like this:

<i class="ii icon-inbox"></i>

Exercise:

Modify the card elements in the Homepage HTML:

Exercise 12.4

And modify the Homepage CSS:

Exercise 12.5

A font is a collection of characters. The font in the Xurrent system is called ‘itrp-icons’. itrp is the technical name of the Xurrent system (it still refers to the original branding that was used when the Xurrent system was built). Each character (and in this case each icon) has a unique number or identifier within the font.
To fully understand how this works, open the Self Service Portal and inspect the Inbox icon.The relevant parts of the CSS look like this:
Xurrent Fonts - How It Works The :before part of the second rule is called a pseudo-element. It is used to insert some content inside the element with the class icon-inbox. In this case, we insert the 58112th character of the itrp-icons font, which happens to look like an inbox.

Link the Cards

The user will expect to open the Inbox when she clicks on the Inbox Card. So we need to turn the entire card into a link, so that clicking anywhere on the card brings you to the correct self service page. In HTML this means that we need to turn the div.card elements in a.card elements according to the HTML Links syntax.

Exercise:

Modify the card elements in the Homepage HTML:

Exercise 12.6

When you test the linked cards, you will see that the cards’ color turned into blue. That’s the standard color for <a .>... </a> elements. To have our grey color again, you will need to apply CSS rules for the color and border-color properties of the cards. But you must take into account CSS Specificity, the algorithm by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied. The basic principle is that by indicating one or more elements before the element you’re selecting, the rule becomes more specific and gets higher priority.

Exercise:

Adjust the card CSS from this:

Exercise 12.7

to this:

Exercise 12.8

Highlight on Hover

Next, when you hover over the cards with the mouse,

Unhovered card

we want it to turn into this:

Hovered card

We can make use of the CSS Pseudo-classes. A pseudo-class is used to specify a special state of an element and based on that state, style it. It can be used to:

The syntax is straightforward:

selector:pseudo-class { property:value; }

The hover pseudo-class is one of the available pseudo-classes. To set the background color of a div element in blue when you hover over it, you can style it with:

div:hover { background-color: blue; }

Exercise:

Add this css snippet to the Homepage CSS:

Exercise 12.9

Highlight Counts Higher than 0

Finally, we want to highlight counts higher than 0, by making the number blue and bold: Blue counter

How could we do this? It seems we have to apply a CSS rule based on the text inside a HTML element: If the text is not 0, make it blue and bold. Unfortunately this is not possible with CSS: CSS is based on HTML elements and classes. Could we somehow encode the necessary information in the class attribute?

This is indeed possible: the text that displays the counter inside the card body is rendered with a widget. We could use the same widget to build our own class attribute count-. For the Inbox card this would become:

A dynamic class with a widget

For the css rule to be only applied when the counter is not zero, we can use the CSS ‘:not’ Selector.

Exercise:

Modify the card elements in the Homepage HTML:

Exercise 12.10

And this is the css snippet to style when the counter is not zero:

Exercise 12.11

Next Exercise