如何在css中获得div的宽度:100%-1px

时间:2012-12-28 03:14:02

标签: html width

有没有办法计算CSS的宽度?我想做宽度1px小于100%宽度。 有width:100%-1px;等属性吗?

1 个答案:

答案 0 :(得分: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就像起始编号。