是否有任何解决方案可以相对于行高的旧值更改行高并减少或增加它?
(我的目标是在android中增加或减少webView中的行高,但我知道我可以用一些css或javascript来做这个问题标签是javascript和css。)
答案 0 :(得分:2)
呃,是的。
// Get a reference to the element to be changed
var theP = document.querySelector("p");
// Set up a click event handler for the button
document.querySelector("button").addEventListener("click", function(){
// Get the numeric portion of the current line-height property
var h = parseInt(window.getComputedStyle(theP, null).lineHeight);
// Set the new value to twice the old value and add the unit back on to the string
theP.style.lineHeight = (h * 2) + "px";
});
p { line-height:10px; }
<button>Double the line height</button>
<p>The quick brown fox jumped over the lazy dog.<br>But, when he did, the dog bit his tail</p>