2013-04-24 70 views
0

我有問題來設置我的XUL按鈕的寬度。我有這樣的代碼:爲什麼忽略XUL按鈕的寬度屬性?

<button label="Ok" width="16" maxwidth="16" height="16" maxheight="16"/> 

通過與該代碼,我的整個窗口的大小發生變化,不僅是按鈕。

當我寫:

<button label="Ok" width="16" height="16"/> 

只有高度變化。這是爲什麼?

回答

1

XUL使用flexible box model進行定位。 widthheight屬性定義元素的固有大小,而不是它們顯示的大小。您的按鈕顯然位於一個垂直框中(不一定是實際的vbox element,而是具有orient="vertical"的任何元素)。默認情況下,一個盒子的align attribute被認爲具有價值stretch - 這樣一個垂直框會一直在水平方向拉伸它裏面的元素:

<vbox> 
    <!-- this button is stretched horizontally to match the width of its container --> 
    <button label="Ok" width="16" height="16"/> 
</vbox> 

您可以明確地設置align屬性來避免這種情況:

<vbox align="center"> 
    <!-- this button is centered inside its container --> 
    <button label="Ok" width="16" height="16"/> 
</vbox>