我的公司正在建立一个网站,我们遇到了一些JavaScript库无法替换的问题.我们决定将我们的HTML放入W3C验证器,它告诉我们在<div>标签内部<button>标记是非法的.
<button class="button" type="submit">
<div class="buttonNormalLargeLeft"><!--#--></div>
<div class="buttonNormalLargeCenter">Search Flights</div>
<div class="buttonNormalLargeRight"><!--#--></div>
</button>
Run Code Online (Sandbox Code Playgroud)
结果是:
Line 287, Column 46: Element div not allowed as child of element button in this context. (Suppressing further errors from this subtree.)
Run Code Online (Sandbox Code Playgroud)
编辑:澄清我们在这里要做的事情.我们想制作一个不依赖圆角的按钮box-radius.我们在button元素中制作了3个div,每个div都有自己的精灵,使其看起来呈圆形,并允许不同的宽度.其他资源表明按钮元素是为希望按钮包含子元素(如图像)的用户创建的,但div由于某种原因似乎无效.
为什么按钮元素中不允许使用div?
这个问题的理想解决方案是什么?
EDIT2:
为什么不使用输入?因为输入不能具有所需的布局
为什么不使用div?因为没有JavaScript的用户将无法提交表单.
我使用webkit/mozilla边框半径和框阴影CSS属性,但我希望CSS验证(它目前没有).有没有办法让它验证?
我创建了一个网页(http://www.snow4life.yum.pl),它在firefox,chrome等中正确呈现.当然,愚蠢的IE复杂的东西,因为它自动进入怪癖模式,即使doctype正确设置和网站通过w3验证(有一个错误,错过了一些char,但文件已在十六进制编辑器中清除).如何阻止ie进入怪癖模式?有什么办法吗?
我想要一个程序以递归方式查找给定目录和JSLints中的所有*.js,*.html和*.css文件,并且W3C分别验证它们并打印出找到的所有错误.另外,它单独使用JSLints和CSS验证嵌入在html文件中的脚本和样式标记内的任何内容.我还希望这可以使用W3C工具验证其他不太常见的Web内容.这些工具还应该具有为JSLint传递通用JavaScript框架的选项(例如,它应该可以与最新的JQuery一起使用).哪里可以买到这样的工具?
这个问题的灵感有点被这个问题,其中最upvoted答案利用HTML 5,这当然似乎是一个很好的方法给我推荐的功能,但它让我好奇利用总体未来的规范功能.
HTML 5提供了许多很好的改进,其中许多可以在不引起当前浏览器问题的情况下使用.
一些例子:
// new, simple HTML5 doctype (puts browsers in standards mode)
<!doctype HTML>
// new input types, for easy, generic client side validation
<input type="email" name="emailAddress"/>
<input type="number" name="userid"/>
<input type="date" name="dateOfBirth"/>
// new "required" attribute indicates that a field is required
<input type="text" name="userName" required="true"/>
// new 'data-' prefixed attributes
// for easy insertion of js-accessible metadata in dynamic pages
<div data-price="33.23">
<!-- -->
</div>
<button data-item-id="93024">Add Item</button>
Run Code Online (Sandbox Code Playgroud)
其中许多新功能旨在使浏览器能够自动验证表单,并为其提供更好的输入(例如日期选择器).有些只是方便,似乎是为未来做好准备的好方法.
它们目前在当前浏览器中并没有破坏任何东西(据我所知),它们允许干净,通用的客户端代码.
但是,即使它们在HTML 5中都有效,它们也不适用于HTML 4,此时HTML …
为了理解W3C验证是否可以帮助更好的DOM渲染,或者它是否只是HTML编码的标准,我尝试验证主要网站,但所有这些都失败了一些错误.
以下是典型示例:
google.com 36个错误,2个警告
facebook.com 42个错误
youtube.com 91错误,3警告
yahoo.com 212错误,8警告
amazon.com 510错误,138警告
当主要网站似乎没有花足够时间进行W3C验证时,是否需要花时间为中小型网站这样做?
我正在通过W3C验证服务运行我的网站.我收到以下HTML的错误消息:
<section class="about">
<article>
<header>
<h1>Mission</h1>
</header>
<div class="content">
<p>bla bla bla</p>
</div>
<aside>
<img src='/images/logo-hse-250x250.png' />
</aside>
</article>
</section>
Run Code Online (Sandbox Code Playgroud)
W3C验证错误是:
考虑仅将
h1元素用作顶级标题(所有h1元素都被许多屏幕阅读器和其他工具视为顶级标题).Run Code Online (Sandbox Code Playgroud)<h1>Mission</h1>
我认为HTML5允许h1在页面上使用多个标签.并且该h1标签可以在article元素内部使用.
有没有人知道为什么W3C没有验证这个HTML?
我\xe2\x80\x99m 试图理解为什么某些 HTML 属性未通过 W3C 验证。我在真实的代码库中遇到了这个问题,但这里\xe2\x80\x99s是一个最小的复制:
\n<!DOCTYPE html><html lang="en"><head><title>a</title></head><body>\n\n<img alt="1" src="\xe2\xad\x90">\n<img alt="2" src="/\xe2\xad\x90">\n<img alt="3" src="/a\xe2\xad\x90">\n<img alt="4" src="/a/\xe2\xad\x90">\n<img alt="5" src="">\n<img alt="6" src="/"> <!-- Only this is invalid. -->\n<img alt="7" src="/a">\n<img alt="8" src="/a/">\n\n</body></html>\nRun Code Online (Sandbox Code Playgroud)\nW3C 验证器仅报告一个错误,影响第六张图像:
\n\n\n\n
\n- \n
错误:元素
\n/属性值错误:路径段中存在非法字符:不允许。srcimg?Run Code Online (Sandbox Code Playgroud)\n<img alt="6" src="/">\n
为什么只有这个有问题,其他的没有?\xe2\x80\x99 有什么不同?
\n我似乎找不到任何详细说明支持iframe属性"allowfullscreen"的网站.例如,CanIUse.com似乎没有它的列表.
有没有人有Chrome,Safari,IE和Firefox的支持信息?
<!DOCTYPE html>
...
<style scoped>
/* css */
</style>
Run Code Online (Sandbox Code Playgroud)
w3.org验证器给了我这个错误:
Line 883, Column 17: Element style not allowed as child of element body in this context.
(Suppressing further errors from this subtree.)
<style scoped>...
Contexts in which element style may be used:
If the scoped attribute is absent: where metadata content is expected.
If the scoped attribute is absent: in a noscript element that is a child of a head element.
If the scoped attribute is present: where flow content …Run Code Online (Sandbox Code Playgroud) w3c-validation ×10
html ×6
css ×4
html5 ×4
css3 ×1
dom ×1
emoji ×1
iframe ×1
javascript ×1
jslint ×1
quirks-mode ×1
url-parsing ×1
w3c ×1
xhtml ×1