TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A couple CSS tricks for HTML Dialog elements

163 pointsby surprisetalk4 months ago

10 comments

hk13374 months ago
datalist is one I stumbled upon and blew me away. <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Element&#x2F;datalist" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Element&#x2F;da...</a><p>It&#x27;s not a replacement for select as you still need an input to tie it to but it seems to handle filtering a list of options nicely.<p>Also, if you have two selects with the same list in it, you can do it once with datalist and have two inputs, say a list of clients with client_a and client_b for inputs.<p>I don&#x27;t quite care for how it displays the value, like if you put the ID as the value and the client name in the option element, you can filter by the ID or the name but the input will show the ID only.
评论 #42701925 未加载
评论 #42699951 未加载
评论 #42704968 未加载
评论 #42700485 未加载
评论 #42746146 未加载
vintagedave4 months ago
The trick to prevent scrolling by setting overflow: hidden unfortunately results in visual page jumping for me.<p>The reason is I have macOS set up to always show scroll bars, instead of hiding them. At least one browser (I forget which, but I test on Safari, Firefox and Chrome) doesn’t have a disabled scroll bar but removes it altogether. This makes the page wider and causes it to reflow and move.<p>Does anyone know how to keep the scroll bar onscreen, just not enabled?
评论 #42698531 未加载
评论 #42666118 未加载
rado4 months ago
Freezing the page isn&#x27;t so simple, as overflow: hidden messes up things like the sticky header on that page. I had so much trouble with it, I decided to just let users scroll and hide the modal during scrolling: <a href="https:&#x2F;&#x2F;radogado.github.io&#x2F;n-modal&#x2F;" rel="nofollow">https:&#x2F;&#x2F;radogado.github.io&#x2F;n-modal&#x2F;</a>
评论 #42700394 未加载
simonw4 months ago
This is a neat piece of modern CSS:<p><pre><code> body:has(dialog[open]) { overflow: hidden; } </code></pre> <a href="https:&#x2F;&#x2F;caniuse.com&#x2F;css-has" rel="nofollow">https:&#x2F;&#x2F;caniuse.com&#x2F;css-has</a> confirms the has() selector has had widespread browser support since December 2023.
评论 #42699891 未加载
评论 #42698757 未加载
评论 #42700423 未加载
cmgriffing4 months ago
Be careful using:<p><pre><code> dialog::backdrop { backdrop-filter: blur(2px); } </code></pre> If there is frequently updating content on the page like a video, it can kill CPU performance. Restream does this and it punishes my M3 macbook air.<p>It seems you can use the transform3d trick to kick it to the GPU to help fix it.
评论 #42705112 未加载
dimaor4 months ago
Is it weird that I expected the post to actually have running examples?
评论 #42705593 未加载
Alifatisk4 months ago
A demo of each trick would be nice to see
starikovs4 months ago
Thanks for the article!<p>I remember I had a hard time trying to stretch dialog to full screen for mobile devices, but it actually didn&#x27;t want to work. The code was something like this:<p>dialog { position: absolute; top: 10px; right: 10px; bottom: 10px; left: 10px; }
评论 #42699608 未加载
评论 #42701535 未加载
nashashmi4 months ago
OT: I really want to see marquee tag have native UI scrolling via CSS property. The many websites that use this horizontal scrolling layout with JS makes me want to cry.
burgerzzz4 months ago
160 likes for this?