如何获得DIV子元素的computputedstyle?
抱歉,ESL的单词选择。我要获得的是与Div相邻(?)或相关(?)的H3的GetComputedStyle,该DIV具有特定类(主题),而H3则没有。
这是CSS的一个示例:
.mainBook
{
position: absolute;
}
.mainBook h3
{
line-height: 120px;
}
我知道如何获得主本书的ComcomputedStyle:
const element = document.querySelector('.mainBook');
const style = getComputedStyle(element);
// and then if I want: style.getPropertyValue("nameOfProperty")
这是HTML:
<div class="mainBook">
<h3>Title</h3>
</div>
不确定这是否有帮助,但是:
const element = document.querySelector('.mainBook');
const style = getComputedStyle(element);
// and then if I want: style.getPropertyValue("line-height");
// How do I getComputedStyle the h3?
.mainBook
{
position: absolute;
}
.mainBook h3
{
line-height: 120px;
}
<div class="mainBook">
<h3>Title</h3>
</div>
但是有什么方法可以做同样的事情,但是对于H3?
谢谢!
Sorry in advance for the ESL choice of words. What I'm trying to get is the getComputedStyle of an h3 that's adjacent (?) or related (?) to a div which has a specific class (mainBook), while the h3 hasn't got any.
Here's an example of the CSS:
.mainBook
{
position: absolute;
}
.mainBook h3
{
line-height: 120px;
}
I know how to getComputedStyle of mainBook:
const element = document.querySelector('.mainBook');
const style = getComputedStyle(element);
// and then if I want: style.getPropertyValue("nameOfProperty")
Here's the HTML:
<div class="mainBook">
<h3>Title</h3>
</div>
Not sure if this helps but:
const element = document.querySelector('.mainBook');
const style = getComputedStyle(element);
// and then if I want: style.getPropertyValue("line-height");
// How do I getComputedStyle the h3?
.mainBook
{
position: absolute;
}
.mainBook h3
{
line-height: 120px;
}
<div class="mainBook">
<h3>Title</h3>
</div>
But is there any way to do the same but for h3?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 您可以获取
h3
元素,并从
compulatedStyle
获取其lineHeight
,如下所示:2) 您还可以从
mainBook
元素获取h3
元素,如下所示:1) You can get
h3
element asand get its
lineHeight
fromcomputedStyle
as:2) You can also get
h3
element frommainBook
element as: