亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄
A concise review of dialog and ::backdrop
dialog in practice
Conclusion
Andy Clarke
首頁(yè) web前端 css教學(xué) 通過(guò)HTML對(duì)話獲得創(chuàng)意

通過(guò)HTML對(duì)話獲得創(chuàng)意

Jun 04, 2025 am 09:17 AM

Getting Creative With HTML Dialog

Love them or hate them, whether you're displaying an alert, a message, or a newsletter subscription prompt, dialog boxes draw attention to specific content without redirecting users to another page. Historically, dialog boxes relied on a combination of div elements, ARIA attributes, and JavaScript. However, the introduction of the HTML dialog element has made them more accessible and versatile in numerous ways.

So, how can you enhance the design of dialog boxes beyond the standard look provided by frameworks and templates? How can you tailor them to align with a brand's visual identity and contribute to telling its narrative? Here's how I approach it using CSS with ::backdrop, backdrop-filter, and animations.

As mentioned earlier, Emmy-award-winning game composer Mike Worth engaged me to craft a highly graphic design. Mike adores '90s animation, and he challenged me to incorporate its retro aesthetic without creating a cliché. Nevertheless, I had to achieve this retro vibe while ensuring accessibility, performance, responsiveness, and semantic integrity.

A concise review of dialog and ::backdrop

Let's quickly recap.

Note: Although I primarily refer to "dialog boxes" throughout, the HTML element is spelled dialog.

The dialog element is an HTML component designed for implementing modal and non-modal dialog boxes in applications and website interfaces. It comes equipped with built-in features such as closing the box using the Esc key, focus trapping to keep interaction within the box, show and hide methods, and a ::backdrop pseudo-element for styling the overlay of the box.

The HTML structure is straightforward:

<code><dialog><h2>Stay updated</h2>

  Close
</dialog></code>

By default, this type of dialog box is hidden, but adding the open attribute makes it visible upon loading the page:

<code><dialog open=""><h2>Stay updated</h2>

  Close
</dialog></code>

I can't envision many uses for non-modal dialogs that are open by default, so typically, I require a button to open a dialog box:

<code><dialog></dialog>
Stay updated</code>

And a touch of JavaScript to open the modal:

<code>const dialog = document.querySelector("dialog");
const showButton = document.querySelector("dialog + button");
showButton.addEventListener("click", () => {
  dialog.showModal();
});</code>

Closing a dialog box also requires JavaScript:

<code>const closeButton = document.querySelector("dialog button");
closeButton.addEventListener("click", () => {
  dialog.close();
});</code>

If the dialog contains a form with method="dialog," it can close automatically on submission without JavaScript:

<code><dialog>

    Submit

</dialog></code>

The dialog element was created to be accessible right out of the box. It traps focus, supports the Esc key, and behaves like a proper modal. To aid screen readers in announcing dialog boxes correctly, you should include an aria-labelledby attribute. This informs assistive technology where to locate the dialog box's title so it can be read aloud when the modal opens.

<code><dialog aria-labelledby="dialog-title"><h2>Stay updated</h2>

</dialog></code>

Most tutorials I've encountered offer minimal styling for dialog and ::backdrop, which might explain why so many dialog boxes only feature basic border radii and a box-shadow.

I believe every element in a design—regardless of its size or frequency of appearance—is an opportunity to showcase a brand and narrate its offerings or services. I recognize that certain moments during a user's journey through a design can be enhanced by paying extra attention to detail, making their experience more memorable.

Dialog boxes are just one such moment, and Mike Worth's design provides ample chances to reflect his brand or connect directly with someone's position in Mike's story. For instance, styling a newsletter subscription dialog to match the scrolls in his news section.

Alternatively, making the form modal on his error pages resemble a comic-book speech bubble.

dialog in practice

Mike's dropdown navigation menu appears like an ancient stone tablet.

I aimed to extend this look to his dialog boxes with a three-dimensional tablet and a jungle leaf-filled backdrop.

This dialog includes a newsletter subscription form with an email input and a submit button:

<code><dialog><h2>Stay informed</h2>

    <label data-visibility="hidden" for="email">Email address</label>

    Submit

  x
</dialog></code>

I began by setting dimensions for the dialog and adding the SVG stone tablet background image:

<code>dialog {
  width: 420px;
  height: 480px;
  background-color: transparent;
  background-image: url("dialog.svg");
  background-repeat: no-repeat;
  background-size: contain;
}</code>

Next, I applied the leafy green background image to the dialog's generated backdrop using the ::backdrop pseudo-element selector:

<code>dialog::backdrop {
  background-image: url("backdrop.svg");
  background-size: cover;
}</code>

To ensure clarity for anyone completing Mike's form regarding the validity of their email address, I combined :has and :valid CSS pseudo-class selectors to alter the submit button's color from gray to green:

<code>dialog:has(input:valid) button {
  background-color: #7e8943;
  color: #fff;
}</code>

Additionally, I wanted this interaction to reflect Mike's playful nature. Thus, I modified the dialog background image and applied a rubber band animation to the box when a valid email address is entered:

<code>dialog:has(input:valid) {
  background-image: url("dialog-valid.svg");
  animation: rubberBand 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes rubberBand {
  from { transform: scale3d(1, 1, 1); }
  30% { transform: scale3d(1.25, 0.75, 1); }
  40% { transform: scale3d(0.75, 1.25, 1); }
  50% { transform: scale3d(1.15, 0.85, 1); }
  65% { transform: scale3d(0.95, 1.05, 1); }
  75% { transform: scale3d(1.05, 0.95, 1); }
  to { transform: scale3d(1, 1, 1); }
}</code>

Tip: Daniel Eden's Animate.css library is an excellent resource for "Just-add-water CSS animations" like the rubber band effect used here.

Modifying how an element appears when it holds a valid input is a fantastic way to introduce interactions that are both enjoyable and beneficial for the user.

This combination of :has and :valid selectors can even extend to the ::backdrop pseudo-class, altering the backdrop's background image:

<code>dialog:has(input:valid)::backdrop {
  background-image: url("backdrop-valid.svg");
}</code>

Give it a try:

Conclusion

We frequently view dialog boxes as functional components, mere interruptions, but nothing more. However, when treated as opportunities for self-expression, even the smallest aspects of a design can influence a product or website's character.

The HTML dialog element, with its inherent behaviors and styling capabilities, presents opportunities for branding and creative storytelling. There's no reason a dialog box can't stand out as much as the rest of your design.

Andy Clarke

Frequently hailed as one of the founders of web design, Andy Clarke has played a pivotal role in advancing web design boundaries and is renowned for his innovative and visually striking designs. His work has motivated countless designers to explore the full potential of product and website design.

Andy has authored several industry-leading books, including 'Transcending CSS,' 'Hardboiled Web Design,' and 'Art Direction for the Web.' He has also collaborated with businesses of all sizes and industries to meet their objectives through design.

Visit Andy's studio, Stuff & Nonsense, and check out his Contract Killer, the popular web design contract template trusted by thousands of web designers and developers.

以上是通過(guò)HTML對(duì)話獲得創(chuàng)意的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁(yè)開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

熱門話題

Laravel 教程
1597
29
PHP教程
1488
72
CSS教程,用於創(chuàng)建加載旋轉(zhuǎn)器和動(dòng)畫 CSS教程,用於創(chuàng)建加載旋轉(zhuǎn)器和動(dòng)畫 Jul 07, 2025 am 12:07 AM

創(chuàng)建CSS加載旋轉(zhuǎn)器的方法有三種:1.使用邊框的基本旋轉(zhuǎn)器,通過(guò)HTML和CSS實(shí)現(xiàn)簡(jiǎn)單動(dòng)畫;2.使用多個(gè)點(diǎn)的自定義旋轉(zhuǎn)器,通過(guò)不同延遲時(shí)間實(shí)現(xiàn)跳動(dòng)效果;3.在按鈕中添加旋轉(zhuǎn)器,通過(guò)JavaScript切換類來(lái)顯示加載狀態(tài)。每種方法都強(qiáng)調(diào)了設(shè)計(jì)細(xì)節(jié)如顏色、大小、可訪問性和性能優(yōu)化的重要性,以提升用戶體驗(yàn)。

解決CSS瀏覽器兼容性問題和前綴 解決CSS瀏覽器兼容性問題和前綴 Jul 07, 2025 am 01:44 AM

處理CSS瀏覽器兼容性和前綴問題需理解瀏覽器支持差異並合理使用廠商前綴。 1.了解常見問題如Flexbox、Grid支持不一,position:sticky失效,動(dòng)畫表現(xiàn)不同;2.查閱CanIuse確認(rèn)特性支持情況;3.正確使用-webkit-、-moz-、-ms-、-o-等廠商前綴;4.推薦使用Autoprefixer自動(dòng)添加前綴;5.安裝PostCSS並配置browserslist指定目標(biāo)瀏覽器;6.構(gòu)建時(shí)自動(dòng)處理兼容性;7.老項(xiàng)目可用Modernizr檢測(cè)特性;8.不必追求所有瀏覽器一致,確

顯示:內(nèi)聯(lián),顯示:塊和顯示:內(nèi)聯(lián)塊之間有什麼區(qū)別? 顯示:內(nèi)聯(lián),顯示:塊和顯示:內(nèi)聯(lián)塊之間有什麼區(qū)別? Jul 11, 2025 am 03:25 AM

Themaindifferencesbetweendisplay:inline,block,andinline-blockinHTML/CSSarelayoutbehavior,spaceusage,andstylingcontrol.1.Inlineelementsflowwithtext,don’tstartonnewlines,ignorewidth/height,andonlyapplyhorizo????ntalpadding/margins—idealforinlinetextstyling

造型與CSS不同訪問的鏈接 造型與CSS不同訪問的鏈接 Jul 11, 2025 am 03:26 AM

設(shè)置訪問過(guò)鏈接的樣式能提升用戶體驗(yàn),尤其在內(nèi)容密集型網(wǎng)站中幫助用戶更好導(dǎo)航。 1.使用CSS的:visited偽類可定義已訪問鏈接樣式,如顏色變化;2.注意瀏覽器出於隱私限制僅允許修改部分屬性;3.顏色選擇應(yīng)與整體風(fēng)格協(xié)調(diào),避免突兀;4.移動(dòng)端可能不顯示該效果,建議結(jié)合其他視覺提示如icon輔助標(biāo)識(shí)。

使用CSS剪輯路徑創(chuàng)建自定義形狀 使用CSS剪輯路徑創(chuàng)建自定義形狀 Jul 09, 2025 am 01:29 AM

使用CSS的clip-path屬性可以裁剪元素為自定義形狀,如三角形、圓形缺口、多邊形等,無(wú)需依賴圖片或SVG。其優(yōu)勢(shì)包括:1.支持circle、ellipse、polygon等多種基本形狀;2.可響應(yīng)式調(diào)整,適配移動(dòng)端;3.易於動(dòng)畫化,可結(jié)合hover或JavaScript實(shí)現(xiàn)動(dòng)態(tài)效果;4.不影響佈局流,僅裁剪顯示區(qū)域。常見用法如圓形裁剪clip-path:circle(50pxatcenter)和三角形裁剪clip-path:polygon(50%0%,1000%,00%)。注意

CSS繪畫API是什麼? CSS繪畫API是什麼? Jul 04, 2025 am 02:16 AM

thecsspaintingapienablesdemimageGenerationinCsssingJavascript.1.developersCreateApaintWorkletClassWithaPaint()method.2.theyregisteritviaregisterpaint()。 3.thecustompAntFunctionSthenusitySthenusedisthenusedisthenusedIncerspropertieslikeBacknockforg-image-image.thisallows.thisallowsforderforderynamecvis

如何使用CSS創(chuàng)建響應(yīng)式圖像? 如何使用CSS創(chuàng)建響應(yīng)式圖像? Jul 15, 2025 am 01:10 AM

要使用CSS創(chuàng)建響應(yīng)式圖片,主要可通過(guò)以下方法實(shí)現(xiàn):1.使用max-width:100%和height:auto讓圖片在保持比例的同時(shí)自適應(yīng)容器寬度;2.結(jié)合HTML的srcset和sizes屬性智能加載適配不同屏幕的圖片源;3.利用object-fit和object-position控製圖片裁剪與焦點(diǎn)展示。這些方法共同確保圖片在不同設(shè)備上清晰、美觀地呈現(xiàn)。

什麼是常見的CSS瀏覽器不一致? 什麼是常見的CSS瀏覽器不一致? Jul 26, 2025 am 07:04 AM

不同瀏覽器對(duì)CSS解析存在差異,導(dǎo)致顯示效果不一致,主要包括默認(rèn)樣式差異、盒模型計(jì)算方式、Flexbox和Grid佈局支持程度及某些CSS屬性行為不一致。 1.默認(rèn)樣式處理不一致,解決方法是使用CSSReset或Normalize.css統(tǒng)一初始樣式;2.舊版IE的盒模型計(jì)算方式不同,建議統(tǒng)一使用box-sizing:border-box;3.Flexbox和Grid在邊緣情況或舊版本中表現(xiàn)有差異,應(yīng)多測(cè)試並使用Autoprefixer;4.某些CSS屬性行為不一致,需查閱CanIuse並提供降級(jí)

See all articles