From 7090254658174563a43334f31d307e05eb7568fa Mon Sep 17 00:00:00 2001 From: Sli Date: Mon, 2 Jun 2025 23:27:25 +0200 Subject: [PATCH] Refactor navbar css and use details instead of div for better semantics --- core/static/core/navbar.scss | 101 +++++++++++++------------- core/templates/core/base.jinja | 14 +++- core/templates/core/base/navbar.jinja | 32 ++++---- 3 files changed, 77 insertions(+), 70 deletions(-) diff --git a/core/static/core/navbar.scss b/core/static/core/navbar.scss index 9c9bf4df..bdf67d04 100644 --- a/core/static/core/navbar.scss +++ b/core/static/core/navbar.scss @@ -13,9 +13,18 @@ nav.navbar { align-items: flex-start; gap: 0; margin: .2em; + + >.content[mobile-display="hidden"] { + display: none; + } + + >.content[mobile-display="revealed"] { + display: block; + } } - > .expand-button { + + >.expand-button { background-color: transparent; display: none; position: relative; @@ -27,7 +36,7 @@ nav.navbar { align-items: center; margin: 0; - > i { + >i { font-size: 1.5em; color: white; } @@ -37,17 +46,17 @@ nav.navbar { } } - > .content { - @media (min-width: 500px) {display: flex; + >.content { + @media (min-width: 500px) { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; - display: flex !important; + display: flex; } - > .menu, - > .link { + >.menu, + >.link { box-sizing: border-box; width: 130px; height: 52px; @@ -64,76 +73,64 @@ nav.navbar { &:last-child { border-radius: 0 0 .6em .6em; - > .content { + >.content { box-shadow: 3px 3px 3px 0 #dfdfdf; } } } } - > .menu > .head, - > .link { + >.menu>.head, + >.link { color: white; - padding: 10px 20px; - box-sizing: border-box; + } + >.menu>summary, + >.link { @media (max-width: 500px) { padding: 10px; } } + >.link { + padding: 10px 20px; + box-sizing: border-box; + } + + .link:hover, .menu:hover { background-color: rgba(0, 0, 0, .2); } - > .menu > .head, - > .link { - color: white; - padding: 10px 20px; - box-sizing: border-box; + details.menu { + cursor: pointer; + user-select: none; + z-index: 10; + align-items: center; + display: inline-block; - @media (max-width: 500px) { - padding: 10px; + summary { + list-style: none; + + display: flex; + align-items: center; + height: 100%; + padding-left: 20px; + padding-right: 20px; } - } - .link:hover, - .menu:hover { - background-color: rgba(0, 0, 0, .2); - } - - > .menu:hover > .content, - > .menu > .head:hover + .content, - > .menu > .content:hover { - display: flex; - } - - > .menu { - display: flex; - position: relative; - - > .content { - z-index: 10; + summary::-webkit-details-marker { display: none; - position: absolute; - top: 100%; - background-color: white; - margin: 0; + } + + ul.content { list-style-type: none; - width: 130px; box-shadow: 3px 3px 3px 0 #dfdfdf; - flex-direction: column; + background: white; + margin: 0; - @media (max-width: 500px) { - position: absolute; - flex-direction: row; - flex-wrap: wrap; - width: 100%; - box-shadow: inset 3px 3px 3px 0 #dfdfdf; - } - - > li > a { + >li>a { display: flex; padding: 15px 20px; diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index 6479e833..8000b1fa 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -122,10 +122,20 @@ {% block script %}