Languages
[Edit]
EN

CSS - sticky list details on the right side

9 points
Created by:
AnnLen
1876

In this short article we would like to show how to create using only pure CSS, list with sticky details that are always visible and scrollable with the web page.

Simple example: 

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>
    
    body {
      	margin: 0;
    	max-height: 300px;
    }

    div.container {
      	/* nothing here ... */
    }
    
    div.list {
      	margin: 0 50% 0 0;  /* <------------ required              */
    }
    
    div.details {
        margin: 0 0 0 50%;  /* <------------ required              */
    	position: -webkit-sticky;  /* <----- required (for WebKit) */
        position: sticky;  /* <------------- required              */
        bottom: 0;  /* <-------------------- required              */
      	background: silver;
        min-height: 100vh;  /* <------------ required              */
    }

  </style>
</head>
<body>
  <div style="container">
    <div class="list">  <!-- <--------------- list must be placed as first  -->
                        <!--                                                -->
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
      Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />  Item ...<br />
    </div>
    <div class="details">  <!-- ----------- details must be placed as last  -->
                           <!--                                             -->
      Details ...<br> Details ...<br> Details ...<br> Details ...<br> Details ...<br>
      Details ...<br> Details ...<br> Details ...<br> Details ...<br> Details ...<br>
      Details ...<br> Details ...<br> Details ...<br> Details ...<br> Details ...<br>
      Details ...<br> Details ...<br> Details ...<br> Details ...<br> Details ...<br>
      Details ...<br> Details ...<br> Details ...<br> Details ...<br> Details ...<br>
      Details ...<br> Details ...<br> Details ...<br> Details ...<br> Details ...<br>
      Details ...<br> Details ...<br> Details ...<br> Details ...<br> Details ...<br>
      Details ...<br> Details ...<br> Details ...<br> Details ...<br> Details ...<br>
    </div>
  </div>
</body>
</html>

 

Hey 👋
Would you like to know what we do?
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.