0

有没有办法在 CSS 中计算宽度?我想制作一个宽度小于 100% 宽度的 1px 。有没有类似的财产width:100%-1px;

4

1 回答 1

0

试试这个 JavaScript 片段:

elem = document.getElementById('div');
pElem = elem.parentNode;
pPadding = pElem.style.padding || pElem.style.paddingLeft + pElem.style.paddingRight || 0;
pBorder = pElem.style.borderWidth || pElem.style.borderLeftWidth + pElem.style.borderRightWidth || 0;    
elem.style.width = ( pElem.offsetWidth - pPadding - pBorder - 4 ) + "px";

编辑:重要的是要注意在这个脚本中,3 = 0、4 = 1、5 = 2、6 = 3 等等......所以 3 就像起始数字一样。

于 2012-12-28T03:18:44.687 回答