HTML Academy
flex-basis: 100% and flex-wrap
Flexbox, part 219/28
Back to the list of tasks
  • 1. Flex items and the block model
  • 2. Features of the margin property
  • 3. Alignment and margins
  • 4. The flow direction of the main axis and margins
  • 5. The initial main size of flex item, flex-basis
  • 6. Test: Cubism
  • 7. The item growth factor, flex-grow
  • 8. Growing items proportionally
  • 9. Calculating the total size with flex-grow
  • 10. The item shrinkage factor, flex-shrink
  • 11. Shrinking items proportionally
  • 12. Calculating the total size with flex-shrink
  • 13. flex-shrink and min-width
  • 14. Test: Mastering factors
  • 15. The flex shorthand property
  • 16. Multi-line flex containers and flex-shrink
  • 17. Multi-line flex containers and flex-grow
  • 18. flex-basis: 100% and flex-wrap
  • 19. The heading with description in flexboxes
  • 20. Heading with description, part 2
  • 21. Flexible menu with overflowing content
  • 22. Flexible menu with overflow, part 2
  • 23. Input fields with dynamic width
  • 24. The course card
  • 25. Course card, part 2
  • 26. Course card, part 3
  • 27. So many cards
  • 28. Test: Flexible flows
Heading with description, part 2
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

The heading with description in flexboxes

We are now finished with our review of the theoretical material, so let’s get down to the practical part. Let’s consider the examples of some real interface elements and specific cases where it would be convenient to use flexboxes.

A fairly common interface element is a block containing a heading and a small explanatory subheading on the same line. The heading is located at the beginning of the line, and the subheading is pushed to the right edge of the block.

If the text of the heading or subheading increases significantly in size, then it should not break the layout: the texts simply have to be arranged one on top of the other.

You cannot lay out an element with such flexible behavior using float or display: table. After all, we need the signature blocks to occupy the free space at the same time and to adjust their sizes depending on the text content, and the grid should be rebuilt if their contents overflow.

Only a flexbox with flex-grow will be able to help us do this.

For clarity, set a background color and frame for the text blocks, through you will remove them for the next assignment.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>The heading with description in flexboxes</title> <link href="course.css" rel="stylesheet"> <link href="style.css" rel="stylesheet"> </head> <body class="subtle"> <section class="card"> <h1 class="card-title"> <span class="card-title-main">Muffin against flexboxes</span> <span class="card-title-note">A coming-of-age story</span> </h1> <p>Over the course of his long career as a front-end web developer, Muffin has seen a lot of confusing solutions: the standard block model where the width is not exactly the width of the block, vertical margins that are assigned as percentages and that are for some reason not calculated on the basis of the parent’s height, but on the basis of its width, and many other strange of things.</p> <p>However, during the last month, he has become increasingly puzzled about a new method for laying out pages: flexboxes. He kept re-reading the specification only to be surprised every time: “Why is it so complicated? As though we didn’t already have enough regular tables!”</p> <p>But the pace of technological change is relentless, and Muffin, clutching his paw into a fist of resolve, could only try to keep up with these developments.</p> </section> </body> </html>
CSS
.card { margin-bottom: 20px; line-height: 1.3; } .card-title { margin-top: 0; } .card-title span { } .card-title-main { }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0
    1. For the spans inside the .card-title block, set the background color to #c8dcff and a solid frame that is 1px thick and with the color #999999.
    2. Then assign a flexbox layout for .card-title,
    3. and align the flex items to the end of the cross axis.
    4. Assign a growth factor of 1 to the .card-title-main block.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.