Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active January 25, 2021 09:37
Show Gist options
  • Save acidtone/01415edde8f9405f32d3e5bc19fb25f9 to your computer and use it in GitHub Desktop.
Save acidtone/01415edde8f9405f32d3e5bc19fb25f9 to your computer and use it in GitHub Desktop.
Header: logo, title and sub-title

Header: Horizontal banner with logo, site title and sub-title

This gist builds upon a simpler gist that does not have a sub-title.

  1. Create a flex container:

    .container {
      display: flex;
    }
  2. Use justify-content to control how items are horizontally positioned (when in row direction):

    .container {
      justify-content: center;
    }
  3. Flexbox alignment (up-down when in the row direction) defaults to stretch, which breaks image aspect ratio. Use align-items to centre the items instead:

    .container {
      align-items: center;
    }

Assumptions

Simple html page header:

<header class="container">
  <img src="https://picsum.photos/id/237/150" alt="Puppy logo">
  <div>
    <h1>Lucifer</h1>
    <h2>The Demon Puppy</h2>
  </div>
</header>

img and div are the Flex items. h1 and h2 are not included in the Flex context and are regular block elements.

Background material

  1. HTML:
  2. CSS Selectors:
  3. Flexbox:
<header class="container">
<img src="https://picsum.photos/id/237/150" alt="Puppy logo">
<div>
<h1>Lucifer</h1>
<h2>The Demon Puppy</h2>
</div>
</header>
/* Objective: Create a horizontal logo/heading banner */
.container {
display: flex;
justify-content: center;
align-items: center;
}
/*********************/
/* Additional styles */
/*********************/
/* Make it pretty */
body {
margin: 0;
font-size: 24px;
font-variant: small-caps;
font-family: Trebuchet MS, Helvetica, sans-serif;
letter-spacing: 0.2em;
text-align: center;
}
header {
padding: 1rem;
}
header > * {
margin: 1rem;
}
img {
border-radius: 50%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment