标签上的宽度未定义

问题描述 投票:0回答:1

我正在创建一个菜单,我的元素的宽度不起作用。

    width = 100/numMenus-1;
            alert(width) // I have 4 menu items so I get 24 here
        document.write('<span class=menuBar style="TEXT-ALIGN:center;width:' + width + '%;"'); 
        document.write('onmouseout=dTimeout=setTimeout("hideMenus(' + theMenu.num + ')",200) ');
        document.write('onMouseOver=dTimeout=setTimeout("showMenus(' + theMenu.num + ')",200) ');
        document.write('id=menuHeading' + theMenu.num + '>');
        document.write(theMenu.name);
        document.write('</span>');
            alert(menuHeading0);// I get [object HTMLSpanElement]
            alert(menuHeading0.width); // I get undefined.  

和菜单项都聚集在包含它们的中心。类“menuBar”不包含宽度,仅包含颜色和字体大小。

html width
1个回答
0
投票

宽度不会影响内联元素。在跨度上设置display:inline-block;,你应该开展业务。

<span style="width:300px;background:red">Inline</span>
<span style="width:300px;display:inline-block;background:yellow;">Inline Block</span>
© www.soinside.com 2019 - 2024. All rights reserved.