HTML中的样式宽度与宽度属性 [英] style width vs width attribute in HTML

查看:220
本文介绍了HTML中的样式宽度与宽度属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到上一篇文章类似于我的问题 HTML5画布样式高度与属性高度

但是在那篇文章中,没有明确的信息说明哪一个会起作用,有什么区别?

I saw last post similar to my question HTML5 canvas style height vs attribute height
But in that post, there was no clear information regarding which one will work and what is the difference?

我试过以下示例:

<html>
    <head>
    </head>
      <body>
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
        <script src="jquery-1.11.1.js"></script>
        <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
        <script src="script.js"></script>

        <div>
             <select style="width: 200px" width="200px">
                   <option value="Test1"> Test1 </option>
                   <option value="Test2"> Test2 </option>
                   <option value="Test3"> Test3</option>
                   <option value="Test4"> Test4 </option>
                   <option value="Test5"> Test5 </option>
             </select>
        </div>
     </body>
 </html>        

但在上面的例子中,如果放 style =width:200px width =200px,未见同样的结果。

But in above example, if put either style="width: 200px" or width="200px", same result is not seen.

问题:

1)为什么 style =width:200px width =200px 没有给出相同的结果?

2) width =200px width =200之间有什么区别?

Question:
1) why are style="width: 200px and width="200px not giving same result?
2) what is the difference between width="200px" or width="200"?

有些人可以帮助我清除这些基础知识吗?

Can some help me to clear these basics?

推荐答案

width 属性无效http://www.w3.org/TR/REC-html40/interact/forms.html#edef-SELECTrel =nofollow> 选择 元件。更重要的是,这种限制是由浏览器强加的:它们忽略了属性。 (很久以前,Netscape 4支持它,它在1995年到期的HTML 3.0草案中有所描述。一些遗留代码,甚至是遗留的编码实践,可能反映这些事情!)

The width attribute is invalid in a select element. What matters more, this restriction is imposed by browsers: they ignore the attribute. (Long time ago, Netscape 4 supported it, and it was described in the HTML 3.0 draft, which expired in 1995. Some legacy code, maybe even legacy coding practices, may still reflect such things!)

所以答案很简单:它们不同,所以HTML中的 width 属性没有效果(因此该元素采用了它默认宽度),而CSS中的 width 属性以普通的CSS方式工作。

So answer is simple: they differ so that the width attribute in HTML has no effect (so the element takes its default width), whereas the width property in CSS works in the normal CSS way.

width 属性不是HTML中的一般属性:它允许某些元素集并为它们单独定义。

The width attribute is not a general attribute in HTML: it is allowed for a certain set of elements and defined individually for them.

这篇关于HTML中的样式宽度与宽度属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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