SkyoceanHome
Home
Privacy
ダウンロード
SkyShop
Updated Information
チュートリアルコード集
References
記事編集
日付
ジャンルのカテゴリ―名
名前を選択して下さい。
Contexts
Controllers
Databases
Htmls
JavaScripts
Models
MVCTutorials
Others
Styles
Views
タイトル
内容の要旨
<p data-bm="71" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 4px; padding: revert; -webkit-line-clamp: revert; color: rgba(0, 0, 0, 0.8); font-family: roboto, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;" data-pasted="true">了解です。<br>前回の階層ドロップダウンメニュー実装例を、さらに <strong style="font-weight: 700;">実務向けの強化版</strong> に改良します。<br>今回は <strong style="font-weight: 700;">Bootstrap 5</strong> をベースに、<strong style="font-weight: 700;">多階層対応 + アクティブ強調 + アイコン対応 + ホバー展開 + アニメーション</strong> を組み込みます。</p><h2 data-bm="72" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">1. モデル(自己参照型 + アイコン + 表示順)</h2><pre data-priority="2" data-bm="73" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; color: rgba(0, 0, 0, 0.8); font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-bm="82" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 249, 254);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: normal !important; font-variant: normal !important; font-weight: 400 !important; font-stretch: 100% !important; line-height: 18px; font-family: roboto, helvetica, sans-serif !important; font-optical-sizing: auto !important; font-size-adjust: none !important; font-kerning: auto !important; font-feature-settings: normal !important; font-variation-settings: normal !important; font-language-override: normal !important; font-size: 16px; display: inline-block; color: rgb(11, 73, 127);">Csharp</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px roboto, helvetica, sans-serif; background-color: rgb(225, 240, 253); border: 1px solid rgba(0, 0, 0, 0); display: grid; grid-auto-flow: column; align-items: center; cursor: pointer; color: rgb(0, 0, 0) !important; text-decoration: none !important; border-radius: 9999px; block-size: 28px; gap: 2px; padding-inline: 10px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; max-inline-size: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: clip; max-block-size: calc(1lh); padding-inline: 2px;">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;"><span style="color: rgb(106, 115, 125);">// Models/MenuItem.cs</span> <span style="color: rgb(215, 58, 73);">using</span> System.Collections.Generic; <span style="color: rgb(215, 58, 73);">namespace</span> <span style="color: rgb(111, 66, 193);">YourApp.Models</span> { <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(215, 58, 73);">class</span> <span style="color: rgb(111, 66, 193);">MenuItem</span> { <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">int</span> Id { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">string</span> Title { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">string</span> Url { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">int</span>? ParentId { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">int</span> DisplayOrder { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(106, 115, 125);">// 表示順</span> <span style="color: rgb(215, 58, 73);">public</span> List<MenuItem> Children { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } = <span style="color: rgb(215, 58, 73);">new</span>(); <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">bool</span> IsActive { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">string</span> IconClass { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } } } </code></pre><h2 data-bm="74" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">2. コントローラー(階層構築 + アクティブ判定 + 並び替え)</h2><pre data-priority="2" data-bm="75" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; color: rgba(0, 0, 0, 0.8); font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-bm="83" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 249, 254);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: normal !important; font-variant: normal !important; font-weight: 400 !important; font-stretch: 100% !important; line-height: 18px; font-family: roboto, helvetica, sans-serif !important; font-optical-sizing: auto !important; font-size-adjust: none !important; font-kerning: auto !important; font-feature-settings: normal !important; font-variation-settings: normal !important; font-language-override: normal !important; font-size: 16px; display: inline-block; color: rgb(11, 73, 127);">Csharp</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px roboto, helvetica, sans-serif; background-color: rgb(225, 240, 253); border: 1px solid rgba(0, 0, 0, 0); display: grid; grid-auto-flow: column; align-items: center; cursor: pointer; color: rgb(0, 0, 0) !important; text-decoration: none !important; border-radius: 9999px; block-size: 28px; gap: 2px; padding-inline: 10px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; max-inline-size: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: clip; max-block-size: calc(1lh); padding-inline: 2px;">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;"><span style="color: rgb(106, 115, 125);">// Controllers/MenuController.cs</span> <span style="color: rgb(215, 58, 73);">using</span> Microsoft.AspNetCore.Mvc; <span style="color: rgb(215, 58, 73);">using</span> YourApp.Models; <span style="color: rgb(215, 58, 73);">using</span> System.Collections.Generic; <span style="color: rgb(215, 58, 73);">using</span> System.Linq; <span style="color: rgb(215, 58, 73);">namespace</span> <span style="color: rgb(111, 66, 193);">YourApp.Controllers</span> { <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(215, 58, 73);">class</span> <span style="color: rgb(111, 66, 193);">MenuController</span> : <span style="color: rgb(111, 66, 193);">Controller</span> { <span style="color: rgb(215, 58, 73);">public</span> IActionResult <span style="color: rgb(111, 66, 193);">Index</span>() { <span style="color: rgb(215, 58, 73);">var</span> flatMenu = <span style="color: rgb(215, 58, 73);">new</span> List<MenuItem> { <span style="color: rgb(215, 58, 73);">new</span> MenuItem { Id = <span style="color: rgb(0, 92, 197);">1</span>, Title = <span style="color: rgb(3, 47, 98);">"ホーム"</span>, Url = <span style="color: rgb(3, 47, 98);">"/"</span>, IconClass = <span style="color: rgb(3, 47, 98);">"fa fa-home"</span>, DisplayOrder = <span style="color: rgb(0, 92, 197);">1</span> }, <span style="color: rgb(215, 58, 73);">new</span> MenuItem { Id = <span style="color: rgb(0, 92, 197);">2</span>, Title = <span style="color: rgb(3, 47, 98);">"製品"</span>, Url = <span style="color: rgb(3, 47, 98);">"/products"</span>, IconClass = <span style="color: rgb(3, 47, 98);">"fa fa-box"</span>, DisplayOrder = <span style="color: rgb(0, 92, 197);">2</span> }, <span style="color: rgb(215, 58, 73);">new</span> MenuItem { Id = <span style="color: rgb(0, 92, 197);">3</span>, Title = <span style="color: rgb(3, 47, 98);">"サービス"</span>, Url = <span style="color: rgb(3, 47, 98);">"/services"</span>, IconClass = <span style="color: rgb(3, 47, 98);">"fa fa-cogs"</span>, DisplayOrder = <span style="color: rgb(0, 92, 197);">3</span> }, <span style="color: rgb(215, 58, 73);">new</span> MenuItem { Id = <span style="color: rgb(0, 92, 197);">4</span>, Title = <span style="color: rgb(3, 47, 98);">"製品A"</span>, Url = <span style="color: rgb(3, 47, 98);">"/products/a"</span>, ParentId = <span style="color: rgb(0, 92, 197);">2</span>, DisplayOrder = <span style="color: rgb(0, 92, 197);">1</span> }, <span style="color: rgb(215, 58, 73);">new</span> MenuItem { Id = <span style="color: rgb(0, 92, 197);">5</span>, Title = <span style="color: rgb(3, 47, 98);">"製品B"</span>, Url = <span style="color: rgb(3, 47, 98);">"/products/b"</span>, ParentId = <span style="color: rgb(0, 92, 197);">2</span>, DisplayOrder = <span style="color: rgb(0, 92, 197);">2</span> }, <span style="color: rgb(215, 58, 73);">new</span> MenuItem { Id = <span style="color: rgb(0, 92, 197);">6</span>, Title = <span style="color: rgb(3, 47, 98);">"サービスX"</span>, Url = <span style="color: rgb(3, 47, 98);">"/services/x"</span>, ParentId = <span style="color: rgb(0, 92, 197);">3</span>, DisplayOrder = <span style="color: rgb(0, 92, 197);">1</span> }, <span style="color: rgb(215, 58, 73);">new</span> MenuItem { Id = <span style="color: rgb(0, 92, 197);">7</span>, Title = <span style="color: rgb(3, 47, 98);">"サービスY"</span>, Url = <span style="color: rgb(3, 47, 98);">"/services/y"</span>, ParentId = <span style="color: rgb(0, 92, 197);">3</span>, DisplayOrder = <span style="color: rgb(0, 92, 197);">2</span> }, <span style="color: rgb(215, 58, 73);">new</span> MenuItem { Id = <span style="color: rgb(0, 92, 197);">8</span>, Title = <span style="color: rgb(3, 47, 98);">"製品B詳細"</span>, Url = <span style="color: rgb(3, 47, 98);">"/products/b/detail"</span>, ParentId = <span style="color: rgb(0, 92, 197);">5</span>, DisplayOrder = <span style="color: rgb(0, 92, 197);">1</span> } }; <span style="color: rgb(215, 58, 73);">var</span> menuTree = BuildTree(flatMenu); MarkActiveMenu(menuTree, HttpContext.Request.Path); <span style="color: rgb(215, 58, 73);">return</span> View(menuTree.OrderBy(m => m.DisplayOrder).ToList()); } <span style="color: rgb(215, 58, 73);">private</span> List<MenuItem> <span style="color: rgb(111, 66, 193);">BuildTree</span>(List<MenuItem> items) { <span style="color: rgb(215, 58, 73);">var</span> lookup = items.ToDictionary(x => x.Id); <span style="color: rgb(215, 58, 73);">var</span> roots = <span style="color: rgb(215, 58, 73);">new</span> List<MenuItem>(); <span style="color: rgb(215, 58, 73);">foreach</span> (<span style="color: rgb(215, 58, 73);">var</span> item <span style="color: rgb(215, 58, 73);">in</span> items.OrderBy(i => i.DisplayOrder)) { <span style="color: rgb(215, 58, 73);">if</span> (item.ParentId.HasValue && lookup.ContainsKey(item.ParentId.Value)) { lookup[item.ParentId.Value].Children.Add(item); lookup[item.ParentId.Value].Children = lookup[item.ParentId.Value].Children.OrderBy(c => c.DisplayOrder).ToList(); } <span style="color: rgb(215, 58, 73);">else</span> { roots.Add(item); } } <span style="color: rgb(215, 58, 73);">return</span> roots; } <span style="color: rgb(215, 58, 73);">private</span> <span style="color: rgb(227, 98, 9);">bool</span> <span style="color: rgb(111, 66, 193);">MarkActiveMenu</span>(List<MenuItem> menuItems, <span style="color: rgb(227, 98, 9);">string</span> currentPath) { <span style="color: rgb(227, 98, 9);">bool</span> found = <span style="color: rgb(0, 92, 197);">false</span>; <span style="color: rgb(215, 58, 73);">foreach</span> (<span style="color: rgb(215, 58, 73);">var</span> item <span style="color: rgb(215, 58, 73);">in</span> menuItems) { <span style="color: rgb(215, 58, 73);">if</span> (item.Url?.Equals(currentPath, System.StringComparison.OrdinalIgnoreCase) == <span style="color: rgb(0, 92, 197);">true</span>) { item.IsActive = <span style="color: rgb(0, 92, 197);">true</span>; found = <span style="color: rgb(0, 92, 197);">true</span>; } <span style="color: rgb(215, 58, 73);">else</span> <span style="color: rgb(215, 58, 73);">if</span> (item.Children.Any() && MarkActiveMenu(item.Children, currentPath)) { item.IsActive = <span style="color: rgb(0, 92, 197);">true</span>; found = <span style="color: rgb(0, 92, 197);">true</span>; } } <span style="color: rgb(215, 58, 73);">return</span> found; } } } </code></pre><h2 data-bm="76" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">3. メインビュー(Bootstrap + 多階層CSS + ホバー展開 + アニメーション)</h2><pre data-priority="2" data-bm="77" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; color: rgba(0, 0, 0, 0.8); font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-bm="84" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 249, 254);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: normal !important; font-variant: normal !important; font-weight: 400 !important; font-stretch: 100% !important; line-height: 18px; font-family: roboto, helvetica, sans-serif !important; font-optical-sizing: auto !important; font-size-adjust: none !important; font-kerning: auto !important; font-feature-settings: normal !important; font-variation-settings: normal !important; font-language-override: normal !important; font-size: 16px; display: inline-block; color: rgb(11, 73, 127);">Html</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px roboto, helvetica, sans-serif; background-color: rgb(225, 240, 253); border: 1px solid rgba(0, 0, 0, 0); display: grid; grid-auto-flow: column; align-items: center; cursor: pointer; color: rgb(0, 0, 0) !important; text-decoration: none !important; border-radius: 9999px; block-size: 28px; gap: 2px; padding-inline: 10px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; max-inline-size: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: clip; max-block-size: calc(1lh); padding-inline: 2px;">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;">@model List<<span style="color: rgb(34, 134, 58);">YourApp.Models.MenuItem</span>> <<span style="color: rgb(34, 134, 58);">link</span> <span style="color: rgb(0, 92, 197);">rel</span>=<span style="color: rgb(3, 47, 98);">"stylesheet"</span> <span style="color: rgb(0, 92, 197);">href</span>=<span style="color: rgb(3, 47, 98);">"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"</span>> <<span style="color: rgb(34, 134, 58);">link</span> <span style="color: rgb(0, 92, 197);">rel</span>=<span style="color: rgb(3, 47, 98);">"stylesheet"</span> <span style="color: rgb(0, 92, 197);">href</span>=<span style="color: rgb(3, 47, 98);">"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"</span>> <<span style="color: rgb(34, 134, 58);">style</span>> <span style="color: rgb(0, 92, 197);">.dropdown-submenu</span> { <span style="color: rgb(0, 92, 197);">position</span>: relative; } <span style="color: rgb(0, 92, 197);">.dropdown-submenu</span> > <span style="color: rgb(0, 92, 197);">.dropdown-menu</span> { <span style="color: rgb(0, 92, 197);">top</span>: <span style="color: rgb(0, 92, 197);">0</span>; <span style="color: rgb(0, 92, 197);">left</span>: <span style="color: rgb(0, 92, 197);">100%</span>; <span style="color: rgb(0, 92, 197);">margin-top</span>: -<span style="color: rgb(0, 92, 197);">0.125rem</span>; } <span style="color: rgb(106, 115, 125);">/* アクティブ強調 */</span> <span style="color: rgb(0, 92, 197);">.nav-link</span><span style="color: rgb(0, 92, 197);">.active</span>, <span style="color: rgb(0, 92, 197);">.dropdown-item</span><span style="color: rgb(0, 92, 197);">.active</span> { <span style="color: rgb(0, 92, 197);">background-color</span>: <span style="color: rgb(0, 92, 197);">#0d6efd</span>; <span style="color: rgb(0, 92, 197);">color</span>: <span style="color: rgb(0, 92, 197);">#fff</span> <span style="color: rgb(0, 92, 197);">!important</span>; } <span style="color: rgb(106, 115, 125);">/* ホバー展開 */</span> <span style="color: rgb(0, 92, 197);">.navbar-nav</span> <span style="color: rgb(34, 134, 58);">li</span><span style="color: rgb(34, 134, 58);">:hover</span> > <span style="color: rgb(0, 92, 197);">.dropdown-menu</span> { <span style="color: rgb(0, 92, 197);">display</span>: block; } <span style="color: rgb(106, 115, 125);">/* アニメーション */</span> <span style="color: rgb(0, 92, 197);">.dropdown-menu</span> { <span style="color: rgb(0, 92, 197);">display</span>: none; <span style="color: rgb(0, 92, 197);">opacity</span>: <span style="color: rgb(0, 92, 197);">0</span>; <span style="color: rgb(0, 92, 197);">transition</span>: opacity <span style="color: rgb(0, 92, 197);">0.3s</span> ease; } <span style="color: rgb(0, 92, 197);">.navbar-nav</span> <span style="color: rgb(34, 134, 58);">li</span><span style="color: rgb(34, 134, 58);">:hover</span> > <span style="color: rgb(0, 92, 197);">.dropdown-menu</span> { <span style="color: rgb(0, 92, 197);">display</span>: block; <span style="color: rgb(0, 92, 197);">opacity</span>: <span style="color: rgb(0, 92, 197);">1</span>; } </<span style="color: rgb(34, 134, 58);">style</span>> <<span style="color: rgb(34, 134, 58);">nav</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"navbar navbar-expand-lg navbar-light bg-light"</span>> <<span style="color: rgb(34, 134, 58);">div</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"container-fluid"</span>> <<span style="color: rgb(34, 134, 58);">ul</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"navbar-nav"</span>> @foreach (var item in Model) { @Html.Partial("_MenuItemPartial", item) } </<span style="color: rgb(34, 134, 58);">ul</span>> </<span style="color: rgb(34, 134, 58);">div</span>> </<span style="color: rgb(34, 134, 58);">nav</span>> <<span style="color: rgb(34, 134, 58);">script</span> <span style="color: rgb(0, 92, 197);">src</span>=<span style="color: rgb(3, 47, 98);">"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"</span>></<span style="color: rgb(34, 134, 58);">script</span>> </code></pre><h2 data-bm="78" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">4. 再帰的部分ビュー(アイコン + アクティブ + 並び順)</h2><pre data-priority="2" data-bm="79" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; color: rgba(0, 0, 0, 0.8); font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-bm="85" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 249, 254);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: normal !important; font-variant: normal !important; font-weight: 400 !important; font-stretch: 100% !important; line-height: 18px; font-family: roboto, helvetica, sans-serif !important; font-optical-sizing: auto !important; font-size-adjust: none !important; font-kerning: auto !important; font-feature-settings: normal !important; font-variation-settings: normal !important; font-language-override: normal !important; font-size: 16px; display: inline-block; color: rgb(11, 73, 127);">Html</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px roboto, helvetica, sans-serif; background-color: rgb(225, 240, 253); border: 1px solid rgba(0, 0, 0, 0); display: grid; grid-auto-flow: column; align-items: center; cursor: pointer; color: rgb(0, 0, 0) !important; text-decoration: none !important; border-radius: 9999px; block-size: 28px; gap: 2px; padding-inline: 10px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; max-inline-size: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: clip; max-block-size: calc(1lh); padding-inline: 2px;">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;">@model YourApp.Models.MenuItem @if (Model.Children.Any()) { <<span style="color: rgb(34, 134, 58);">li</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"nav-item dropdown @(Model.ParentId != null ? "</span><span style="color: rgb(0, 92, 197);">dropdown-submenu</span>" <span style="color: rgb(0, 92, 197);">:</span> "")"> <<span style="color: rgb(34, 134, 58);">a</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"nav-link dropdown-toggle @(Model.IsActive ? "</span><span style="color: rgb(0, 92, 197);">active</span>" <span style="color: rgb(0, 92, 197);">:</span> "")" <span style="color: rgb(0, 92, 197);">href</span>=<span style="color: rgb(3, 47, 98);">"@Model.Url"</span> <span style="color: rgb(0, 92, 197);">role</span>=<span style="color: rgb(3, 47, 98);">"button"</span> <span style="color: rgb(0, 92, 197);">data-bs-toggle</span>=<span style="color: rgb(3, 47, 98);">"dropdown"</span> <span style="color: rgb(0, 92, 197);">aria-expanded</span>=<span style="color: rgb(3, 47, 98);">"false"</span>> @if (!string.IsNullOrEmpty(Model.IconClass)) { <<span style="color: rgb(34, 134, 58);">i</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"@Model.IconClass"</span>></<span style="color: rgb(34, 134, 58);">i</span>> } @Model.Title </<span style="color: rgb(34, 134, 58);">a</span>> <<span style="color: rgb(34, 134, 58);">ul</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"dropdown-menu"</span>> @foreach (var child in Model.Children.OrderBy(c => c.DisplayOrder)) { @Html.Partial("_MenuItemPartial", child) } </<span style="color: rgb(34, 134, 58);">ul</span>> </<span style="color: rgb(34, 134, 58);">li</span>> } else { <<span style="color: rgb(34, 134, 58);">li</span>> <<span style="color: rgb(34, 134, 58);">a</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"dropdown-item @(Model.IsActive ? "</span><span style="color: rgb(0, 92, 197);">active</span>" <span style="color: rgb(0, 92, 197);">:</span> "")" <span style="color: rgb(0, 92, 197);">href</span>=<span style="color: rgb(3, 47, 98);">"@Model.Url"</span>> @if (!string.IsNullOrEmpty(Model.IconClass)) { <<span style="color: rgb(34, 134, 58);">i</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"@Model.IconClass"</span>></<span style="color: rgb(34, 134, 58);">i</span>> } @Model.Title </<span style="color: rgb(34, 134, 58);">a</span>> </<span style="color: rgb(34, 134, 58);">li</span>> } </code></pre><h2 data-bm="80" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">改良点</h2><ol data-bm="81" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; color: rgba(0, 0, 0, 0.8); font-family: roboto, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;"><strong style="font-weight: 700;">表示順制御</strong><br><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);">DisplayOrder</code> プロパティでメニューの並び順を管理。</li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;"><strong style="font-weight: 700;">アイコン対応</strong><br>Font Awesome を利用して視覚的にわかりやすく。</li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;"><strong style="font-weight: 700;">ホバー展開 + アニメーション</strong><br>マウスオーバー時にフェードインするようにCSS</li></ol><p data-f-id="pbf" style="text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;">Powered by <a href="https://www.froala.com/wysiwyg-editor?pb=1" title="Froala Editor">Froala Editor</a></p>
コピーする
添付画像
画像を変更
Back to List
//検索文:Editor内でHTMLコードをコピーさせる