6 Creating a profile card

 

This chapter covers

  • Using CSS custom properties
  • Creating a background using radial-gradient
  • Setting image size
  • Positioning elements using a flexbox

In this chapter, we’ll create a profile card. In web design, a card is a visual element that contains information on a single topic. We’re going to apply this concept to someone’s profile information, essentially creating a digital business card. This type of layout is often used on social media and blog sites to give readers an overview of who wrote the content. It sometimes has links to a detailed profile page or opportunities to interact with the person to whom the profile belongs.

To create the layout, we’ll do a lot of work revolving around positioning, specifically, using the CSS Flexbox Layout Module to align and center elements. We’ll also look at how to make a rectangular image fit into a circle without distorting the image. By the end of the chapter, our profile card will look like figure 6.1.

Figure 6.1 Final output

6.1 Starting the project

Let’s dive right in and take a look at our starting HTML (listing 6.1), which you can find in the GitHub repository at http://mng.bz/5197 or on CodePen at https://codepen .io/michaelgearon/pen/NWyByWN. We have a <div> with a class of card that contains all the elements being presented in the profile card. To set our blog post information, we’ll use a description list. Our technologies (CSS, HTML, and so on) are presented in a list.

6.2 Setting CSS custom properties

6.3 Creating full-height backgrounds

6.4 Styling and centering the card using Flexbox

6.5 Styling and positioning the profile picture

6.5.1 The object-fit property

6.5.2 Negative margins

6.6 Setting the background size and position

6.7 Styling the content

6.7.1 Name and job title

6.7.2 The space-around and gap properties