内嵌元素中的块级元素 [英] Block Level Elements inside Inline elements

查看:147
本文介绍了内嵌元素中的块级元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

W3C Validator告诉我,我不能把块级元素放在内联元素中。有意义...



但是如果我使用CSS将块级元素更改为内联元素怎么办?



如果我使用CSS将内联元素转换为块级元素(当在另一个内联元素中时),如果是什么呢?



'/ p>

(我不是真的这么做,我只是想知道最佳实践)

解决方案

在HTML规范中定义为块元素的元素与定义为 display的元素不同:



这意味着:即使你说< p style =display: inline;> Lorem ...< / p> < p> 仍然是HTML眼中的块元素。



HTML,CSS和JavaScript如果使用正确,则说明相互间有松耦合,并且不应该依赖于另一个,没有一个不应该使其他人(或整个系统)失败。


The W3C Validator tells me I can't put block-level elements inside inline elements. Makes sense...

but what if I'm using CSS to change that block-level element into an inline element?

And what if I'm using CSS to convert an inline element into a block-level element (when inside another inline element)?

The Validator doesn't pick up on this obviously, but is it wrong?

(I'm not actually doing this, I'm just wondering about best-practice)

解决方案

An element defined as a block element in the HTML specification is not the same as a element defined as display: block; in CSS.

With this I mean: Even if you say <p style="display: inline;">Lorem...</p>. The <p> will still be a block element in the eyes of HTML.

HTML, CSS and JavaScript if used right is said to have loose coupling toward each other and that one should not be dependent of another and that the absence of one should not make the others (or the system as whole) fail.

这篇关于内嵌元素中的块级元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆