0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

カードの中にアコーディオンを表示したい

Posted at

カードの中にアコーディオンを表示したい

そのまんまですがカードの中にアコーディオンを作って表示するようにしてみました。

<html>
<head>
<meta content-type="UTF-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", () => {
	document.querySelectorAll('div.accordion-hover a').forEach(e => {
		e.addEventListener('mouseover', (e) => {
			if(e.srcElement.getAttribute('aria-expanded') === 'false') {
				e.srcElement.click();
			}
		});
	});
});
</script>
</style>
</head>
<body>
<div class="container-fluid">
	<h2>カードの中にアコーディオンを設定したい</h2>
	<div class="card">
		<div class="card-header"><h6>カードの見出し</h6></div>
		<div class="card-body p-0">
			<div class="accordion accordion-hover" id="accordion" role="tablist" aria-multiselectable="true">
				<div role="tab" id="list1">
					<a href="#list1items" class="d-block" data-toggle="collapse" role="button" aria-expanded="false" aria-controls="list1items">リスト1</a>
					<div id="list1items" class="collapse" role="tabpanel" aria-labelledby="list1" data-parent="#accordion">
						<div class="row no-gutters">
							<div class="col"></div>
							<div class="col"><a href="javascript:alert('1');">リスト1のアイテム1</a></div>
							<div class="col"><a href="javascript:alert('2');">リスト1のアイテム2</a></div>
						</div>
					</div>
				</div>
				<div role="tab" id="list2">
					<a href="#list2items" class="d-block" data-toggle="collapse" role="button" aria-expanded="false" aria-controls="list2items">リスト2</a>
					<div id="list2items" class="collapse" role="tabpanel" aria-labelledby="list2" data-parent="#accordion">
						<div>リスト2のアイテム</div>
						<div>リスト2のアイテム2</div>
					</div>
				</div>
				<div role="tab" id="list3">
					<a href="#list3items" class="d-block" data-toggle="collapse" role="button" aria-expanded="false" aria-controls="list3items">リスト3</a>
					<div id="list3items" class="collapse" role="tabpanel" aria-labelledby="list3" data-parent="#accordion">
						<div>リスト3のアイテム</div>
						<div>リスト3のアイテム2</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<div>
</body>
</html>

これだけです。。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?