Tailwind css Popover example with Dynamic Position and Content and full customization - web2tailwind.com
Web2tailwind.com

Output

Code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://unpkg.com/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
	<script src="https://unpkg.com/[email protected]/dist/tippy-bundle.umd.js"></script>
    <link href="https://unpkg.com/[email protected]^1.0/dist/tailwind.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>
    <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro|Roboto&display=swap" rel="stylesheet">
</head>
<style>
.tippy-box[data-theme~='tomato'] {
  background-color: white;
}
.tippy-box[data-theme~='tomato'][data-placement^='top'] > .tippy-arrow::before {
  border-top-color: white;
}
.tippy-box[data-theme~='white'][data-placement^='bottom'] > .tippy-arrow::before {
  border-bottom-color: white;
}
.tippy-box[data-theme~='tomato'][data-placement^='left'] > .tippy-arrow::before {
  border-left-color: white;
}
.tippy-box[data-theme~='tomato'][data-placement^='right'] > .tippy-arrow::before {
  border-right-color: white;
}
.tippy-content{
  padding:0 !important;
}
</style>
<body style="font-family:Roboto">
    <div class="flex justify-center items-center h-screen bg-gray-200 md:-mx-4">
        <button type="button" data-template='one' data-placement="right" class="bg-blue-600 text-gray-200 rounded hover:bg-blue-500 px-4 py-2 focus:outline-none">Primary</button>
		<button type="button" data-template='one' data-placement="bottom" class="bg-gray-600 text-gray-100 rounded hover:bg-gray-500 px-4 py-2 focus:outline-none">Secondary</button>
		<button type="button" data-template='one' data-placement="top" class="bg-green-500 text-gray-100 rounded hover:bg-green-400 px-4 py-2 focus:outline-none">Success</button>
		<button type="button" data-template='one' data-placement="left" class="bg-red-500 text-gray-200 rounded hover:bg-red-400 px-4 py-2 focus:outline-none">Danger</button>
        <div style="display: none;">
          <div id="one">
            <div class="bg-white shadow-l">
            <div class="px-3 py-2 font-bold text-gray-700 bg-gray-100">Popover title</div>
            <div class="px-3 py-3 text-gray-600">And here's some amazing content. It's very engaging. Right?</div>
          </div>
        </div>
        </div>
    </div>
<script>
  
	const instances = tippy('button', {
      content(reference) {
        const id = reference.getAttribute('data-template');
        const template = document.getElementById(id);
        return template.innerHTML;
      },
       onMount(instance) {
          instance.popperInstance.setOptions({
            placement :instance.reference.getAttribute('data-placement')
          });
      },
      allowHTML: true,
      theme: 'white',
      trigger: 'click', 
    });
</script>
</body>

</html>
© 2019 - 2020 Web2tailwind.com