Reader small image

You're reading from  Responsive Web Design with HTML5 and CSS - Fourth Edition

Product typeBook
Published inSep 2022
Reading LevelIntermediate
PublisherPackt
ISBN-139781803242712
Edition4th Edition
Languages
Right arrow
Author (1)
Ben Frain
Ben Frain
author image
Ben Frain

Ben Frain has been a web designer/developer since 1996. He is currently employed as a UI-UX Technical Lead at bet365. Before the web, he worked as an underrated (and modest) TV actor and technology journalist, having graduated from Salford University with a degree in Media and Performance. He has written four equally underrated (his opinion) screenplays and still harbors the (fading) belief he might sell one. Outside of work, he enjoys simple pleasures: playing indoor football while his body and wife still allow it and wrestling with his two sons.
Read more about Ben Frain

Right arrow

Inline-flex

Flexbox has an inline variant: display: inline-flex;. Thanks to its beautiful centering abilities, you can do some wacky things with very little effort:

Graphical user interface, application  Description automatically generated

Figure 4.6: The inline equivalent of flex is the aptly named “inline-flex”

Here’s the markup:

<p>
    Here is a sentence with an
    <em class="InlineFlex">inline-flex</em>.
</p>

And, using the same basic styles as the previous examples for the fonts, font sizes, and colors, here is the CSS needed:

.InlineFlex {
    display: inline-flex;
    align-items: center;
    height: 120px;
    padding: 0 4px;
    background-color: indigo;
    text-decoration: none;
    border-radius: 3px;
    color: #ddd;
}

When items are set as inline-flex anonymously, which happens if their parent element is not set to display: flex, then they retain whitespace (which can often manifest as an unwanted gap between elements), just like inline-block or inline-table...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Responsive Web Design with HTML5 and CSS - Fourth Edition
Published in: Sep 2022Publisher: PacktISBN-13: 9781803242712

Author (1)

author image
Ben Frain

Ben Frain has been a web designer/developer since 1996. He is currently employed as a UI-UX Technical Lead at bet365. Before the web, he worked as an underrated (and modest) TV actor and technology journalist, having graduated from Salford University with a degree in Media and Performance. He has written four equally underrated (his opinion) screenplays and still harbors the (fading) belief he might sell one. Outside of work, he enjoys simple pleasures: playing indoor football while his body and wife still allow it and wrestling with his two sons.
Read more about Ben Frain