首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery .css线-高度不工作

Jquery .css线-高度不工作
EN

Stack Overflow用户
提问于 2017-01-30 05:07:24
回答 3查看 985关注 0票数 0

我试图为以"drop_“开头的所有元素设置Jquery”行高“css值。当我运行相同的代码将“行高”替换为“字体大小”时,它将正确更新,但无法获得要更新的“行高”。有什么主意吗?

代码语言:javascript
复制
$.each($('[id^=drop_]'), function(index, value) {
 alert($(this).css("line-height"));
 $(this).css("line-height", "3.5px");
 alert($(this).css("line-height"));
}); 
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-01-30 06:22:05

尝尝这个

代码语言:javascript
复制
jQuery.each(jQuery('[id^=drop_]'), function(index, value) {
	 alert(jQuery(this).css("line-height"));
	 jQuery(this).css("line-height", "35px");
	 alert(jQuery(this).css("line-height"));
});
代码语言:javascript
复制
p { line-hieght: 10px; }
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<p id="drop_first">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p id="drop_second">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p id="drop_third">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p id="drop_fourth">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p id="drop_fifth">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>

票数 1
EN

Stack Overflow用户

发布于 2017-01-30 06:09:49

  • 定义行高的推荐方法是使用一个数字值,称为“无单位”线高。数字值可以是任何数字,包括基于十进制的数字,如本页第一个代码示例中所使用的那样。
  • 由于子元素将继承原始数字值而不是计算值,因此建议使用Unitless行高度。这样,子元素可以根据其计算的字体大小计算它们的行高,而不是从父元素继承更需要重写的任意值。

对于line-height属性值,

  • 百分比、px和em值可能导致不良的遗传行为,可能不应该使用。更可取的做法是使用无单位数值(例如1.5)。
  • 当该值以百分比形式提供时,它与元素本身的字体大小有关。

就像这样,

代码语言:javascript
复制
$.each($('[id^=drop_]'), function(index, value) {
 alert($(this).css("line-height"));
 $(this).css("line-height", "3.5");
 alert($(this).css("line-height"));
}); 

备注:,当我们将值作为一个无单位的数字提供时,它将乘以元素的字体大小来计算线框的高度。

参考文献

票数 1
EN

Stack Overflow用户

发布于 2017-01-30 05:27:14

代码语言:javascript
复制
$('.div > p').css('line-height', '3.5px');

请张贴你的HTML。或者相应地更改.div > p部件。这个应该能正常工作。

你所拥有的,对我也很好。如果它不适用于您,请尝试用我的代码更新它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41929325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档