css – HTML aside标签:可以用于表单错误消息吗?

前端之家收集整理的这篇文章主要介绍了css – HTML aside标签:可以用于表单错误消息吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我有一个表单,我将有与每个输入/元素相关的错误消息.
我已经为< aside>提出了这个用法.标记并想知道人们的想法:
<section class="fieldrow" id="rowJobTitle">

        <label for="txtJobTitle" id="lblJobTitle">
            <span>Job title:</span>
        </label>

        <input type="text" id="txtJobTitle" name="txtJobTitle">

        <aside id="errJobTitle" class="errormessage">
            <span role="alert">Please tell us your job title.</span>
        </aside>

    </section>

然后我将使用CSS来显示或隐藏< aside>用一点JS来改变这个错误.

我知道我可以使用跨度,并完成它,但是span标签没有语义值,而且我读过的所有(简短和模糊)信息< aside>似乎说这没有问题,但是我希望我能得到一些确认,或者之前尝试过这个的人,并找到了一个很好的理由.

谢谢,Si.

解决方法

<旁边>所有主流浏览器都支持tag.

然而,有可能更优雅的方式来做到这一点,并且<旁边>你的意思并不是特别的语义. From the HTML5 specs

The aside element represents a section of a page that consists of
content that is tangentially related to the content around the aside
element,and which could be considered separate from that content.
Such sections are often represented as sidebars in printed typography.

您的错误内容并没有真正分开,因此这是一个相当不合适的选择.

您应该看看Twitter Bootstrap如何进行内联表单错误.

总而言之,这是语义学,因此本质上是主观的.如果它对你有意义并且它有效,为什么不使用它呢?

编辑

在阅读Rob的链接后,< aside>看起来比我想象的更不合适.由于< aside>不是< input>的子元素,解析器没有理由认为它与< input>相关.我会在这种情况下避免使用它.

MDN为此提供了一些用例,而您的用例不适合:

they often contains side explanation like a glossary definition,more loosely related stuff like advertisements,the biography of the author,or in web-applications,profile information or related blog links.

原文链接:https://www.f2er.com/css/214679.html

猜你在找的CSS相关文章