A HTML and CSS code snippet post which shows you how to create a CSS Grid based layout to make floating list title headings. Sourced under a permissive license.

CSS Grid based layout – floating list title headings

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<div class="container">
<div class="floating-stack">
<dl>
<dt>A</dt>
<dd>Algeria</dd>
<dd>Angola</dd>
<dt>B</dt>
<dd>Benin</dd>
<dd>Botswana</dd>
<dd>Burkina Faso</dd>
<dd>Burundi</dd>
<dt>C</dt>
<dd>Cabo Verde</dd>
<dd>Cameroon</dd>
<dd>Central African Republic</dd>
<dd>Chad</dd>
<dd>Comoros</dd>
<dd>Congo, Democratic Republic of the</dd>
<dd>Congo, Republic of the</dd>
<dd>Cote d'Ivoire</dd>
<dt>D</dt>
<dd>Djibouti</dd>
<dt>E</dt>
<dd>Egypt</dd>
<dd>Equatorial Guinea</dd>
<dd>Eritrea</dd>
<dd>Eswatini (formerly Swaziland)</dd>
<dd>Ethiopia</dd>
</dl>
</div>
</div>
<style>
.container {
display: grid;
place-items: center;
min-height: 400px;
}
.floating-stack {
background: #455A64;
color: #fff;
height: 80vh;
width: 320px;
border-radius: 1rem;
overflow-y: auto;
}
.floating-stack > dl {
margin: 0 0 1rem;
display: grid;
grid-template-columns: 2.5rem 1fr;
align-items: center;
}
.floating-stack dt {
position: sticky;
top: 0.5rem;
left: 0.5rem;
font-weight: bold;
background: #263238;
color: #cfd8dc;
height: 2rem;
width: 2rem;
border-radius: 50%;
padding: 0.25rem 1rem;
grid-column: 1;
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
.floating-stack dd {
grid-column: 2;
margin: 0;
padding: 0.75rem;
}
.floating-stack > dl:first-of-type > dd:first-of-type {
margin-top: 0.25rem;
}
</style>
<div class="container"> <div class="floating-stack"> <dl> <dt>A</dt> <dd>Algeria</dd> <dd>Angola</dd> <dt>B</dt> <dd>Benin</dd> <dd>Botswana</dd> <dd>Burkina Faso</dd> <dd>Burundi</dd> <dt>C</dt> <dd>Cabo Verde</dd> <dd>Cameroon</dd> <dd>Central African Republic</dd> <dd>Chad</dd> <dd>Comoros</dd> <dd>Congo, Democratic Republic of the</dd> <dd>Congo, Republic of the</dd> <dd>Cote d'Ivoire</dd> <dt>D</dt> <dd>Djibouti</dd> <dt>E</dt> <dd>Egypt</dd> <dd>Equatorial Guinea</dd> <dd>Eritrea</dd> <dd>Eswatini (formerly Swaziland)</dd> <dd>Ethiopia</dd> </dl> </div> </div> <style> .container { display: grid; place-items: center; min-height: 400px; } .floating-stack { background: #455A64; color: #fff; height: 80vh; width: 320px; border-radius: 1rem; overflow-y: auto; } .floating-stack > dl { margin: 0 0 1rem; display: grid; grid-template-columns: 2.5rem 1fr; align-items: center; } .floating-stack dt { position: sticky; top: 0.5rem; left: 0.5rem; font-weight: bold; background: #263238; color: #cfd8dc; height: 2rem; width: 2rem; border-radius: 50%; padding: 0.25rem 1rem; grid-column: 1; display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box; } .floating-stack dd { grid-column: 2; margin: 0; padding: 0.75rem; } .floating-stack > dl:first-of-type > dd:first-of-type { margin-top: 0.25rem; } </style>
<div class="container">
  <div class="floating-stack">
    <dl>
      <dt>A</dt>
      <dd>Algeria</dd>
      <dd>Angola</dd>

      <dt>B</dt>
      <dd>Benin</dd>
      <dd>Botswana</dd>
      <dd>Burkina Faso</dd>
      <dd>Burundi</dd>

      <dt>C</dt>
      <dd>Cabo Verde</dd>
      <dd>Cameroon</dd>
      <dd>Central African Republic</dd>
      <dd>Chad</dd>
      <dd>Comoros</dd>
      <dd>Congo, Democratic Republic of the</dd>
      <dd>Congo, Republic of the</dd>
      <dd>Cote d'Ivoire</dd>

      <dt>D</dt>
      <dd>Djibouti</dd>

      <dt>E</dt>
      <dd>Egypt</dd>
      <dd>Equatorial Guinea</dd>
      <dd>Eritrea</dd>
      <dd>Eswatini (formerly Swaziland)</dd>
      <dd>Ethiopia</dd>
    </dl>
  </div>
</div>
<style>
.container {
  display: grid;
  place-items: center;
  min-height: 400px;
}

.floating-stack {
  background: #455A64;
  color: #fff;
  height: 80vh;
  width: 320px;
  border-radius: 1rem;
  overflow-y: auto;
}

.floating-stack > dl {
  margin: 0 0 1rem;
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  align-items: center;
}

.floating-stack dt {
  position: sticky;
  top: 0.5rem;
  left: 0.5rem;
  font-weight: bold;
  background: #263238;
  color: #cfd8dc;
  height: 2rem;
  width: 2rem;
  border-radius: 50%;
  padding: 0.25rem 1rem;
  grid-column: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.floating-stack dd {
  grid-column: 2;
  margin: 0;
  padding: 0.75rem;
}

.floating-stack > dl:first-of-type > dd:first-of-type {
  margin-top: 0.25rem;
}
</style>

Tags: CSS, HTML, CSS Grid, grid-template-columns, css floating sections, css floating headings, list title headings

Image: Unsplash license 

CC BY 4.0 added intro and tags – 30 Seconds of Code