首页 > 解决方案 > 即使我复制并粘贴了代码,我的字体和文本大小类也不起作用

问题描述

在我的网站上,我有一个更改字体和文本大小的类,名为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>

标签: htmlcss

解决方案


(参考你的回答:)

不幸的是,为多个元素提供相同的内容id会使您的 HTML 无效。如果#font选择器足以解决问题,您应该能够改为提供<table>anid并选择其<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>

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


推荐阅读