I'm working on an accordion that uses Tailwind and Alpine.js (2.x) but I can't seem to get the transitions smooth, it's too janky.
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine#v2.x.x/dist/alpine.min.js"></script>
<ol class="max-w-sm p-4">
<li class="pb-6 mb-6 border-b" x-data="{isOpen : true }">
<h3 class="flex text-2xl mb-6" :class="{ 'mb-6': isOpen }">
<button class="text-left" type="button" #click="isOpen = !isOpen">
Heading 1
</button>
</h3>
<div x-show.transition.duration.300ms.origin.bottom="isOpen" #click.away="isOpen = false">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure rerum in tempore sit ducimus doloribus quod commodi eligendi ipsam porro non fugiat nisi eaque delectus harum aspernatur recusandae incidunt quasi.</p>
</div>
</li>
<li class="pb-6 mb-6 border-b" x-data="{isOpen : false }">
<h3 class="flex text-2xl mb-6" :class="{ 'mb-6': isOpen }">
<button class="text-left" type="button" #click="isOpen = !isOpen">
Heading 2
</button>
</h3>
<div x-show.transition.duration.300ms.origin.bottom="isOpen" #click.away="isOpen = false">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure rerum in tempore sit ducimus doloribus quod commodi eligendi ipsam porro non fugiat nisi eaque delectus harum aspernatur recusandae incidunt quasi.</p>
</div>
</li>
</ol>
Any tips on how to make it smoother?
Edit on 2022-01-06
Accordions (among other components) are now part of official AlpineJS documentation. Use them for perfect out of the box accordions.
Original answer
The main issue regarding smoothness is related to mb-6 not transitioning. A quick fix is proposed below (using mt-6 for the child).
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine#v2.x.x/dist/alpine.min.js"></script>
<ol class="max-w-sm p-4">
<li class="pb-6 mb-6 border-b" x-data="{isOpen : true }">
<h3 class="flex text-2xl">
<button class="text-left" type="button" #click="isOpen = !isOpen">
Heading 1
</button>
</h3>
<div class="mt-6" x-show.transition.duration.300ms.origin.bottom="isOpen" #click.away="isOpen = false">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure rerum in tempore sit ducimus doloribus quod commodi eligendi ipsam porro non fugiat nisi eaque delectus harum aspernatur recusandae incidunt quasi.</p>
</div>
</li>
<li class="pb-6 mb-6 border-b" x-data="{isOpen : false }">
<h3 class="flex text-2xl">
<button class="text-left" type="button" #click="isOpen = !isOpen">
Heading 2
</button>
</h3>
<div class="mt-6" x-show.transition.duration.300ms.origin.bottom="isOpen" #click.away="isOpen = false">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure rerum in tempore sit ducimus doloribus quod commodi eligendi ipsam porro non fugiat nisi eaque delectus harum aspernatur recusandae incidunt quasi.</p>
</div>
</li>
</ol>
However, the smoothness is still not great. To achieve something nice & cool, instead of using transition properties and x-show from AlpineJS, use Transition class and play with the max-height from Tailwind instead. You have a nice example here referenced in AlpineToolbox.
Related
New to Bootstrap and using version 5-2-0
In my layout I wanted to have the image of the cat take up one side and then have the content and form on the other size (content first then form underneath) but I can't get it to work.
<div class="grid">
<div class="g-col-6 g-start-1">
<img src="http://placekitten.com/g/200/300" alt="kitty kitty">
</div>
<div class="g-col-6 g-start-6">
<h1>Hello</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni natus reiciendis corrupti quasi sit, ipsam officia doloribus totam fuga pariatur aliquid! Molestias et sapiente iusto, perspiciatis similique rem ipsum dolores?</p>
</div>
<div class="g-col-6 g-start-6">form</div>
</div>
Codepen:
https://codepen.io/emmabbb/pen/ExRmgZE
This should do.
Code:
<div class="row">
<div class="col-6">
<img src="http://placekitten.com/g/200/300" alt="kitty kitty">
</div>
<div class="col-6">
<h1>Hello</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni natus reiciendis corrupti quasi sit, ipsam officia doloribus totam fuga pariatur aliquid! Molestias et sapiente iusto, perspiciatis similique rem ipsum dolores?</p>
<div>form</div>
</div>
</div>
In you're code, you were missing the stylesheet for https://getbootstrap.com/docs/5.2/assets/css/docs.css.
Also you need to start from g-start-7 (instead of g-start-6) as 1-6 is for the first column and 7-12 is for the second columns
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link href="https://getbootstrap.com/docs/5.2/assets/css/docs.css" rel="stylesheet">
<div class="grid">
<div class="g-col-6">
<img src="http://placekitten.com/g/200/300" alt="kitty kitty">
</div>
<div class="g-col-6 g-start-7">
<h1>Hello</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni natus reiciendis corrupti quasi sit, ipsam officia doloribus totam fuga pariatur aliquid! Molestias et sapiente iusto, perspiciatis similique rem ipsum dolores?</p>
</div>
<div class="g-col-6 g-start-7">form</div>
</div>
See more details here: https://getbootstrap.com/docs/5.2/layout/css-grid/#how-it-works
this is the default structure of two side by side divisions,
I want to keep the read more button at the bottom of the screen even the content is less.
<div class="row">
<div class="col-12"> Image </div>
<div class="col-12">
<h1>Lorem ipsum</h1>
<p>all the content which will be strecth to full height</p>
<a>Read more</a>
</div>
</div>
Also when i make row 100% heigth and align item : strecth, I am getting space between two columns.
As pointed by IvanS95, you can use Card Deck component of Bootstrap. If you really want to use the flexbox on your own probably below solution can be helpful.
The below solution uses Bootstrap 4.4.1
You can view the working code pen solution here
.image-style {
max-width: 100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container py-4">
<div class="row">
<div class="col-6 p-2 d-flex flex-column justify-content-start">
<img src="https://picsum.photos/500/250" class="image-style" />
<h4 class="px-2 mt-2">Lorem ipsum title</h4>
<p class="px-2">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
<p class="px-2">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus, fugit. Fugit iure qui expedita, necessitatibus beatae quaerat distinctio soluta quam ut enim doloremque mollitia ratione illo officiis, quibusdam fuga voluptate.
</p>
<p class="px-2">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quas architecto odit repudiandae libero ex, neque modi explicabo quia delectus qui natus officiis nihil autem sit alias ab odio quisquam. Perferendis?
</p>
Read more
</div>
<div class="col-6 p-2 d-flex flex-column justify-content-start">
<img src="https://picsum.photos/500/250" class="image-style" />
<h4 class="px-2 mt-2">Lorem ipsum title</h4>
<p class="px-2">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
<p class="px-2">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus, fugit. Fugit iure qui expedita, necessitatibus beatae quaerat distinctio soluta quam ut enim doloremque mollitia ratione illo officiis, quibusdam fuga voluptate.
</p>
Read more
</div>
</div>
</div>
In above html inside row there are two 6 unit wide columns that can sit side by side. Each column is converted to flex box using d-flex class, flex direction is set to column using flex-column class and using set the justify-content using justify-content-start class. Now, if I set margin-top to auto on read more button it will always stick to bottom.
To make sure the image width does not create problems I have set the image-style class on the image element which is defined as follows,
CSS
image-style {
max-width: 100%;
}
You can go with code that #Hiren suggested but you also don't need to use a flexbox if you don't want to. Here is an example of how you can achieve the wanted layout:
<div class="container">
<div class="row">
<div class="col-6">
<div class="card">
<img src="https://picsum.photos/500/250" class="image-style" />
<h4>Lorem ipsum title</h4>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
Read more
</div>
</div>
<div class="col-6">
<div class="card">
<img src="https://picsum.photos/500/250" class="image-style" />
<h4>Lorem ipsum title</h4>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
Read more
</div>
</div>
</div>
</div>
CSS:
.card {
position: relative;
height: 100%;
padding: 10px;
padding-bottom: 30px;
}
.read-more-button {
position: absolute;
left: 10px;
bottom: 15px;
}
As you can see, I added padding to the parent element (card) and an absolute position to the 'read more' button. This is how we did it when there was no flexbox.
Note that I still use the Bootstrap (which is flexbox).
Below is the code sample... the cards are ordered vertically and not sure how to order or display them horizontally...
I am trying to get the data from a database (data will be ordered based on date) and want to display the latest posts on the top row, not the first column
any help would be appreciated
<!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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
</head>
<style>
.cards-container {
column-break-inside: avoid;
}
.cards-container .card {
display: inline-block;
overflow: visible;
}
#media only screen and (min-width: 993px) {
.cards-container {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
}
}
</style>
<body>
<div class="container">
<div class="row">
<div class="col s12 cards-container">
<div class="card">
<div class="card-image">
<img src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
<span class="card-title">Card Title</span>
<a class="btn-floating halfway-fab waves-effect waves-light red"><i class="material-icons">add</i></a>
</div>
<div class="card-content">
<p>Test Card 1</p>
<br>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nisi, laborum corporis. Atque ducimus qui, suscipit eum impedit dolorum, architecto natus minima sapiente sunt veritatis itaque ad dolore. Et, ipsum sequi!</p>
</div>
</div>
<div class="card">
<div class="card-image">
<img src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
<span class="card-title">Card Title</span>
<a class="btn-floating halfway-fab waves-effect waves-light red"><i class="material-icons">add</i></a>
</div>
<div class="card-content">
<p>Test Card 2</p>
<br>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nisi, laborum corporis. Atque ducimus qui, suscipit eum impedit dolorum, architecto natus minima sapiente sunt veritatis itaque ad dolore. Et, ipsum sequi!</p>
</div>
</div>
<div class="card">
<div class="card-image">
<img src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
<span class="card-title">Card Title</span>
<a class="btn-floating halfway-fab waves-effect waves-light red"><i class="material-icons">add</i></a>
</div>
<div class="card-content">
<p>Test Card 3</p>
<br>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nisi, laborum corporis. Atque ducimus qui, suscipit eum impedit dolorum, architecto natus minima sapiente sunt veritatis itaque ad dolore. Et, ipsum sequi! Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla rerum ea, magni repellat corporis ab voluptates cumque aut quisquam exercitationem obcaecati itaque voluptatem, laborum saepe, eveniet eos doloremque atque! Cum.</p>
</div>
</div>
<div class="card">
<div class="card-image">
<img src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
<span class="card-title">Card Title</span>
<a class="btn-floating halfway-fab waves-effect waves-light red"><i class="material-icons">add</i></a>
</div>
<div class="card-content">
<p>Test Card 4</p>
<br>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nisi, laborum corporis. Atque ducimus qui, suscipit eum impedit dolorum, architecto natus minima sapiente sunt veritatis itaque ad dolore. Et, ipsum sequi!</p>
</div>
</div>
<div class="card">
<div class="card-image">
<img src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
<span class="card-title">Card Title</span>
<a class="btn-floating halfway-fab waves-effect waves-light red"><i class="material-icons">add</i></a>
</div>
<div class="card-content">
<p>Test Card 5</p>
<br>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nisi, laborum corporis. Atque ducimus qui, suscipit eum impedit dolorum, architecto natus minima sapiente sunt veritatis itaque ad dolore. Et, ipsum sequi!</p>
</div>
</div>
<div class="card">
<div class="card-image">
<img src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
<span class="card-title">Card Title</span>
<a class="btn-floating halfway-fab waves-effect waves-light red"><i class="material-icons">add</i></a>
</div>
<div class="card-content">
<p>Test Card 6</p>
<br>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nisi, laborum corporis. Atque ducimus qui, suscipit eum impedit dolorum, architecto natus minima sapiente sunt veritatis itaque ad dolore. Et, ipsum sequi! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Commodi deleniti sequi placeat ab molestias laborum error provident enim pariatur animi quos harum laudantium rerum veniam quisquam, eius nostrum molestiae facilis!</p>
</div>
</div>
</div>
</div>
</body>
</html>
<aside class="col-md-3 pull-left" style="display:table;position: absolute;height: 100%;">
<div class="row" style="display:table-cell;vertical-align: middle">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Panel 1</h3>
<span class="pull-right clickable"><i class="glyphicon glyphicon-chevron-up"></i></span>
</div>
<div class="panel-body" style="height:700px;overflow:scroll;">
<!--Panel content lorem Impsum Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod repudiandae adipisci ex officia numquam fugiat architecto voluptatum provident. Suscipit neque consectetur laudantium, doloremque fuga quaerat assumenda. Tempore laudantium quos reiciendis. Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe, quis! Odit quam, fugit voluptates beatae dolor quod, aliquam recusandae, nemo impedit aliquid distinctio ratione. Nostrum quae praesentium nemo dignissimos tenetur-->
<dl>
<dt>Music</dt>
<dd>weekend hobby classes</dd>
<hr>
<dt>Digital Marketting</dt>
<dd>Email-Social media,Analytics </dd>
<hr>
<dt>Java</dt>
<dd>Programming classes</dd>
<hr>
<dt>Music</dt>
<dd>weekend hobby classes</dd>
<hr>
<dt>Digital Marketting</dt>
<dd>Email-Social media,Analytics </dd>
<hr>
<dt>Java</dt>
<dd>Programming classes</dd>
<hr>
<dt>Music</dt>
<dd>weekend hobby classes</dd>
<hr>
<dt>Digital Marketting</dt>
<dd>Email-Social media,Analytics </dd>
<hr>
<dt>Java</dt>
<dd>Programming classes</dd>
<hr>
</div>
</div>
</div>
</aside>
you have given height: 700px for panel-body. try to give a little more content and replace overflow: scroll to overflow: auto;
I need to make text wrap around image with bootstrap 4 wihout floats, is it possible?
Here my code:
<article class="row single-post mt-5 no-gutters">
<div class="image-wrapper col-md-6">
<?php the_post_thumbnail(); ?>
</div>
<div class="single-post-content-wrapper p-3">
<?php the_content(); ?>
</div>
</article>
Here what I have now:
Here what I need to have:
I need to make text wrap around image with bootstrap 4 wihout floats, is it possible?
No, in this case, you must use the float-left class for the image. But you don't have to use any wrapper for the image. You can get rid of that wrapper div entirely and add your classes to the image.
Another thing you absolutely must do:
Put all of your content into Bootstrap columns because only Bootstrap columns may be the direct children of Bootstrap rows.
Here's a working code snippet (note: I left the image wrapper div in there but I recommend you get rid of it because that's totally unnecessary code. Add your classes directly to the image):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<article class="row single-post mt-5 no-gutters">
<div class="col-md-6">
<div class="image-wrapper float-left pr-3">
<img src="https://placeimg.com/150/150/animals" alt="">
</div>
<div class="single-post-content-wrapper p-3">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil ad, ex eaque fuga minus reprehenderit asperiores earum incidunt. Possimus maiores dolores voluptatum enim soluta omnis debitis quam ab nemo necessitatibus.
<br><br>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil ad, ex eaque fuga minus reprehenderit asperiores earum incidunt. Possimus maiores dolores voluptatum enim soluta omnis debitis quam ab nemo necessitatibus.
</div>
</div>
</article>
</div>
Updated for Bootstrap 5.0
<div class="container">
<article class="row mt-5 no-gutters">
<div class="col-md-6">
<div class="image-wrapper float-start pe-4 ">
<img src="https://placeimg.com/150/150/animals" alt="">
</div>
<div class="single-post-content-wrapper p-3">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil ad, ex eaque fuga minus reprehenderit asperiores earum incidunt. Possimus maiores dolores voluptatum enim soluta omnis debitis quam ab nemo necessitatibus.
<br><br>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil ad, ex eaque fuga minus reprehenderit asperiores earum incidunt. Possimus maiores dolores voluptatum enim soluta omnis debitis quam ab nemo necessitatibus.
</div>
</div>
</article>
<div class="row">
<div class="col-lg-2 col-12">
<div class="icon mb-4 text-center"><i class="fa fa-github"></i></div>
</div>
<div class="col-10">
<h4 class="h4">Title</h4>
<p class="text-muted">Some text here</p>
</div>
I have used this in bootstrap 4.
Why don't you use something like this:
<div class="container">
<img src="img/example.png" align="left" width="50%">
<p>Text here</p>
</div>
Simpe
align="left"
will do the job!