javascript - 更改相对于旧行高值的行高属性

标签 javascript css space

是否有任何解决方案可以改变 line-height 相对于 line-height 的旧值并减少或增加它?

(我的目标是在 android 的 webView 中增加或减少行高,但我知道我可以用一些 css 或 javascript 做到这一点,所以问题标签是 javascript 和 css。)

最佳答案

嗯,是的。

// 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>

关于javascript - 更改相对于旧行高值的行高属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44207615/

相关文章:

javascript - 如何将 mysql 的 datediff 与 sequelizejs 一起使用

javascript - 页面加载后在 React 中加载第三方 iframe,使 iframe 不影响 PageSpeed 得分

javascript - 将数据存储在 req 与 res 中

javascript - 如何删除存储在本地存储中的特定项目?

javascript - 需要在 Grid 元素中显示手形光标

html - 字体在 Firefox 上看起来很模糊

javascript - 推荐部分的 HTML 问题

Java Space Invaders Game Rapid Fire 作弊触发游戏获胜过早

c# - 如何在没有分配字母的情况下获得磁盘卷上的可用空间?

javascript - js在输入文本框时取消空格键