Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active January 25, 2021 09:35
Show Gist options
  • Save acidtone/1ff8aabed305f862c10f1ff6b8908a04 to your computer and use it in GitHub Desktop.
Save acidtone/1ff8aabed305f862c10f1ff6b8908a04 to your computer and use it in GitHub Desktop.
Header: logo and title

Header: Horizontal banner with logo and site 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">
  <h1>Lucifer: The Demon Puppy</h1>
</header>

img and h1 are the Flex items.

Background material

  1. HTML:
  2. CSS Selectors:
  3. Flexbox:

See also

<header class="container">
<img src="https://picsum.photos/id/237/150" alt="Puppy logo">
<h1>Lucifer: The Demon Puppy</h1>
</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