即使我复制并粘贴了代码,我的字体和文本大小类也不起作用



在我的网站上,我有一个名为class='q'的更改字体和文本大小的类。 即使我从主页复制并粘贴它,该类也无法正常工作,因为它是所有页面的菜单栏。所有其他类都有效,但这个类不行,为什么?

th.q {
	font-family: avenir;
	font-size: 25px;
}
<BODY>
	<TABLE class='a' border='0' width='100%'>
	<TR height='20%'>
		<TH class='q'><a class="hover">About</a></TH>
		<TH class='q'><a>Products</a></TH>
		<TH class='q'><a>Pricing</a></TH>
		<TH class='q'><a>Contact</a></TH>
	</TR>
	</TABLE>

(参考你的答案:(

不幸的是,为多个元素提供相同的id会使您的 HTML 无效。如果#font选择器足以解决问题,您应该能够改为为<table>提供一个id并选择其<th>后代:

#navigation th {
font-size: 25px;
}
<TABLE id='navigation' class='a' border='0' width='100%'>
<TR height='20%'>
<TH><a class="hover">About</a></TH>
<TH><a>Products</a></TH>
<TH><a>Pricing</a></TH>
<TH><a>Contact</a></TH>
</TR>
</TABLE>

此外,borderwidthheight属性应该在 CSS 中,而不是 HTML 中:

#navigation th {
font-size: 25px;
}
#navigation {
border: none;
width: 100%;
}
#navigation tr {
height: 20%;
}
<TABLE id='navigation' class='a'>
<TR>
<TH><a class="hover">About</a></TH>
<TH><a>Products</a></TH>
<TH><a>Pricing</a></TH>
<TH><a>Contact</a></TH>
</TR>
</TABLE>

当然,无论如何,您不应该使用表格进行布局。

由于没有其他方法有效,我使用了 Ids 来修复它。

.HTML

<BODY>
<TABLE  class='a' border='0' width='100%'>
<TR height='20%'>
<TH id='font'><a class="hover">About</a></TH>
<TH id='font'><a>Products</a></TH>
<TH id='font'><a>Pricing</a></TH>
<TH id='font'><a>Contact</a></TH>
</TR>
</TABLE>

.CSS

#font {
font-family: avenir;
font-size: 25px;
}

最新更新