6 Creating a profile card

 

This chapter covers

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

In this chapter we will create a profile card. In web designs, cards are a visual element that contains information on a single topic. We are going to apply this concept to someone’s profile information, essentially creating a digital business card. This type of layout can often be seen on social media or blog sites to give readers a quick overview of who authored the content. It will sometimes have links to a detailed profile page or opportunities to interact with the person the profile belongs to.

By the end of the chapter, our profile card will look as follows (Figure 6.1):

Figure 6.1 Final Output

To create this layout, we will do a lot of work revolving around positioning, specifically leveraging flexbox to help us align and center elements. We will also look at how to make a rectangular image fit into a circle without distorting the image.

Let’s dive right in and take a look at our starting HTML (Listing 6.1) which can be found in the gitbub repo at https://github.com/michaelgearon/Tiny-CSS-Projects/tree/main/chapter-06.

We have a div with a class of card which contains all of the elements being presented in the profile card. To set our blog post information we use a description list.

6.1 CSS custom properties

6.2 Full height backgrounds

6.3 Styling and centering the card using flexbox

6.3.1 Using flexbox to center elements

6.4 Styling and positioning the profile picture

6.4.1 Object-fit

6.4.2 Negative margins

6.5 Background size and positioning

6.6 Styling the content

6.6.1 Styling the name and job title

6.6.2 Space-around and gap

6.6.3 Flex-basis and flex-shrink

6.6.4 Flex-direction

6.6.5 Styling the paragraph

6.6.6 Flex-wrap

6.6.7 Styling the actions

6.7 Summary