目录

max-width

描述 (Description)

max-width属性用于设置元素宽度的上限。

可能的值 (Possible Values)

  • length - 任何长度单位。 元素的宽度值永远不会超过此距离。

  • percentage - 将元素的宽度限制为最多包含块的宽度的百分比。

  • none - 元素的宽度没有限制。

适用于 (Applies to)

除了未替换的内联元素和表元素之外的所有HTML元素。

DOM语法 (DOM Syntax)

object.style.maxWidth = "50px"

例子 (Example)

这是一个例子 -

<html>
   <head>
   </head>
   <body>
      <p style = "max-width:100px; height:200px; border:1px solid red; padding:5px; margin:10px;">
         This paragraph is 200px high and max width is 100px
         This paragraph is 200px high and max width is 100px
         This paragraph is 200px high and max width is 100px
         This paragraph is 200px high and max width is 100px
         This paragraph is 200px high and max width is 100px
      </p>
      <img alt = "logo" src = "/images/css.gif" width = "95" height = "84" />
   </body>
</html>

这将产生以下结果 -

新页面打开
↑回到顶部↑
WIKI教程 @2018