min-width

設定元素的最小寬度。

語法

{ min-width: sMinWidth }

可能的值

sMinWidth

指定元素寬度下限的變數:

length

浮點數,後面接著絕對單位指示項 ( cmmminptpc ) 或相對單位指示項 ( emexpx )。

如需支援之長度單位的詳細資訊,請參閱 長度單位參照

percentage

整數後面接著百分比符號 (%),用來指定包含區塊高度的百分比,以作為元素最大高度使用。如果沒有明確設定包含區塊的高度,元素就不具備最大高度,而且 max-height 屬性會被解譯為 0% 。如需有關包含區塊以及如何計算其高度的詳細資訊,請參閱 Cascading Style Sheets (CSS), Level 2, Revision 1 (CSS2.1) (階層式樣式表 (CSS) 層級 2 修訂 1 (CSS2.1)) Ee371243.xtlink_newWindow(zh-tw,Expression.40).png 規格。

此屬性沒有預設值。這不是繼承屬性。

備註

min-widthmax-width 屬性會套用至浮動與以絕對方式定位的區塊層級元素及內嵌區塊元素,也會套用至某些內建控制項。它們不會套用至非取代的內嵌元素,例如表格列和列/欄群組 (「取代的」元素具有內建尺寸,例如 IMG 元素或 TEXTAREA 元素)。

此屬性只有在精確 !DOCTYPE 下才會啟用。

範例

下列範例顯示如何使用 min-widthmax-width 屬性來限制 DIV 元素的寬度。只有使用 Microsoft Internet Explorer 7 或更新版本才能檢視此範例:

<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Strict//EN">
<html>
<head><style>
.width {
    width:50%;
    min-width:200px;
    max-width:400px;
    background:#eee;
}
.content {
    border :1px solid #c00;
    padding:5px;
}
</style>
</head>
<body>
<div class="width">
<div class="content">
        <h2>{min-width:200px; max-width:400px}</h2>
        <p>This div has a width of 50%. Resize the window
         to grow and shrink the div from max to min width.<br/><br/>
         The outer div controls the width of the inner "content" div.
         Note that the div height increases to accomodate the flow of text.</p>
</div>
</div>
</body>
</html>

標準資訊

您可以在 Cascading Style Sheets (CSS), Level 2 (CSS2) (階層式樣式表 (CSS) 層級 2 (CSS2)) Ee371243.xtlink_newWindow(zh-tw,Expression.40).png 找到此屬性的定義。

適用範圍

a, abbr, acronym, b, bdo, big, blockquote, body, button, caption, center, cite, code, custom, dd, defaults, del, dfn, div, dl, dt, em, embed, fieldset, font, form, frameset, frame, hn, i, iframe, img, input type=button, input type=checkbox, input type=file, input type=image, input type=password, input type=radio, input type=reset, input type=submit, input type=text, ins, li, object, ol, p, q, s, span, sub, table, td, th, tt, u, ul, var, xmp

另請參閱

概念

max-width