html 语义 / css
样式设计时遇到了一个小问题,所以我停下来考虑我的语义标记。这就是我现在的状态。
H1 - site logo
H2 - page title - eg: contact page
H3 - title of each shop
H4 - Description title
现在是我不确定的部分: H4 - 重复并用于,
1) "Open Close" title
2) "Services" title
3) "Location" title
4) "Ratings" title
5) "Comments" title
1到5都是信息标题,如你所见,我目前每个商店有6个H4元素, 2 3 4 和 5 具有相同的样式,1 具有不同的样式,描述标题的 H4 也具有不同的样式。
一种方法是使用 H6,但“打开关闭”的 H5 字体较小,这意味着 H5 会比 H6 小。我宁愿编辑元素来改进代码的语义,而不是简单地围绕当前代码设计样式。谢谢
ran into a slight problem when styling so I have stopped to think about my semantic markup. This is my current state.
H1 - site logo
H2 - page title - eg: contact page
H3 - title of each shop
H4 - Description title
Now comes the part am unsure of:
H4 - repeated and used for,
1) "Open Close" title
2) "Services" title
3) "Location" title
4) "Ratings" title
5) "Comments" title
1 to 5 are all headers for information, as you can see I currently have 6 H4 elements per shop,
2 3 4 and 5 have the same styling, 1 has a different styling and H4 for description title also has a different styling.
One way is using upto H6 but the H5 for "Open Close" is smaller in font-size which means H5 would be smaller than H6. Rather than simply just style around the current code, I would rather edit the elements to improve the semantics of my code. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您愿意进入 HTML5 领域,您可以将内容放入
中,如下所示:
使用
将允许您重用
元素在语义上。If you are willing to move into HTML5 territory, you could drop things into
<hgroup>
like so:Using
<hgroup>
will allow you to reuse your<h>
elements semantically.我想当你考虑语义时,你仍然对表示考虑太多。
您应该将设计过程分为两个阶段。首先,您只考虑语义 - 您可能会尝试不观看浏览器中的页面。查看原始 HTML 代码,并思考代码是否看起来不错。
在 HTML5 中,有
和
标签。使用它们将您的内容分组,并在每个部分中放置一个
标签。这在语义上会很好。
如果您使用 HTML4,则可以使用
来标记部分,并使用
..
作为标题,但仍然不要考虑字体大小!
完成之后,您可能会开始考虑 演示。为每个部分分配一个类,并根据标题所在的部分定义标题。示例:
然后您可以根据需要自由设置标题样式,使用 CSS 选择器的全部功能(在适当的情况下)。
“items”类可能应该以不同的方式命名,但我不确定“shop”部分的各部分的目的是什么。它只是作为示例给出的,因为您可以安全地完全省略该类,并且您仍然可以使用正确的选择器来设置它们的样式:
I suppose that while you consider semantic, you still think too much about presentation.
You should split the design process into two phases. In the first, you think about semantics ONLY - you may event try to NOT watch the pages in the browser. Look at the raw HTML code, and think whether the code looks good.
In HTML5 you have
<section>
and<article>
tags. Use them to group your contents into sections, and in each section place a<h1>
tag. This will be semantically good.In case you use HTML4, you might use
<div class="...">
to mark sections, and use<h1>
..<h6>
as the headers, but still do not think about the font size yet!After you have done that, you may start thinking about presentation. Assign a class to each section, and define the headers according to the section the header is in. An example:
And then you are free to style the headers as you wish, using the full power of CSS selectors where appropriate.
The class "items" should be probably named differently, but I am not sure what is the purpose of the sections of the "shop" section. It was given just as an example, because you can safely omit the class at all, and you still may style them using the proper selectors:
你可以使用CSS来设置各种标题的样式,这样你就可以有诸如
etc之
类的东西。然后在css中你可以有
etc。(这使得h2标签的尺寸更大!)
You can use CSS to style the various headers, so you can have something like
etc.
Then in css you can have
etc. (which makes the h2 tags of a larger size!)
如果您关心 SEO,则应使用
H1
作为页面标题。检查H1 标签、SEO 和语义If you care about SEO,
H1
should be used for page title. Check H1 tags, SEO and semantics您可以为字体大小创建类,例如
CSS。
类似地,您可以为不同的页面制作具有不同 ID 的不同包装器。然后使用 ID 来设置元素的样式。
对于标题,您可以创建一个类
.desc
(或您喜欢的任何其他内容)。然后你可以有div
像#services
$about-us
#contact
现在你可以专门设计你的 < code>h4 元素,通过向其添加类
.desc
来实现。HTMLCSS
You can create classes for the font sizes, say -
CSS
Similarly, you can make different wrappers with distinct ID's for your different pages. And then use there ID's to style the elements.
For the headers you can make a class
.desc
(or anything else that you like). Then you can havediv
s like#services
$about-us
#contact
Now you can specifically style your
h4
element by adding a class.desc
to it.HTML
CSS