JSFiddle - React, Tailwind, and code Playground

by anhkarppinen

HTML

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<!DOCTYPE html>
<html>

  <head>
    <title>Announcement bar Bootstrap style</title>
  </head>

  <body>
    <div class="alert alert-primary alert-dismissible fade show announcement-top-bar" role="alert">
      <p class="d-none d-md-block">This is the content of the announcement bar <a href="#" target="_blank" class="btn btn-primary">Click here</a></p>
      <p class="d-block d-md-none">This is the content of the announcement bar <a href="#" target="_blank">Click here</a></p>
      <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
      </button>
    </div>
    <section>
      <h1>This is heading one</h1>
      <article>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</article>
      <h2>This is heading two</h2>
      <article>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have...

CSS

section {
  padding: 20px;
}

.announcement-top-bar {
  position: -webkit-sticky;
  position: -moz-sticky;
  position: -ms-sticky;
  position: -o-sticky;
  position: sticky;
  top: 0;
}

.announcement-top-bar p {
  margin: 0;
}

.announcement-top-bar.alert-dismissible .close {
  top: 50%;
  transform: translateY(-55%);
}