Html CSS 样式特定链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6428783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS Style a specific link
提问by Gage
Scenario:I am in the process of creating a website for the company I work for. I need to follow their visual style guide so I'm creating a CSS file for the website.
场景:我正在为我工作的公司创建一个网站。我需要遵循他们的视觉风格指南,所以我正在为网站创建一个 CSS 文件。
Question:All the "more" links need to be in 11pt font while the body is in 12pt. Is there a way to specify that if the link is "more" that it will be styled in 11pt?
问题:所有“更多”链接都需要使用 11pt 字体,而正文使用 12pt。有没有办法指定如果链接“更多”,它将在 11pt 中设置样式?
Edit: Is there anyway to do this without using a class? Based off the text instead?
编辑:有没有办法在不使用类的情况下做到这一点?而是基于文本?
Summary: I need to style specific links but I would not like to use classes to style them, maybe text instead?
摘要: 我需要为特定链接设置样式,但我不想使用类来设置它们的样式,也许是文本?
回答by Nick Radford
HTML
HTML
<a href="whatever.html" class="more">More</a>
CSS
CSS
body {
font-size: 12px;
}
a.more {
font-size: 11px;
}
回答by James T Snell
"Can you give those links CSS classes?"
“你能给那些链接提供 CSS 类吗?”
So, you could use something like:
所以,你可以使用类似的东西:
<a class="more-link" href="http://clownlovers.com">MORE</a>
And thus you could style those with CSS along the lines of:
因此,您可以按照以下方式使用 CSS 设置样式:
a.more-link {
font-size:11px;
}
If you can't do that, then I think you could write a little javascript program to go through and change any such links to the font you want. That's kind of minimal to implement, but I think that's an ugly hack, particularly since on slower machines, you may even initially see the default font appear until js runs and shifts things.
如果您不能这样做,那么我认为您可以编写一个小 javascript 程序来完成并将任何此类链接更改为您想要的字体。这有点难以实现,但我认为这是一个丑陋的黑客,特别是因为在较慢的机器上,您甚至可能最初看到默认字体出现,直到 js 运行并改变事物。
回答by Anish
specify a class for more link. for eg...
为更多链接指定一个类。例如...
<a href="#" class="link">more</a>
In CSS:
在 CSS 中:
Use..
用..
body
{
font-weight:13pt;
}
a.link
{
font-weight:11pt;
}
回答by Kyle
There isn't a way for CSS to sift through content like that, but could use jQuery to find all anchors that have the word "more" in it and change it based on that:
CSS 没有办法筛选这样的内容,但可以使用 jQuery 找到所有包含“更多”一词的锚点,并根据它进行更改:
$("a:contains('more')").css("font-size", "11pt");
Not a CSS solution, but this is pretty much the only way you could do what you are asking for. Example for you here.
不是 CSS 解决方案,但这几乎是您可以做您所要求的唯一方法。在这里为您举例。