将每个单词的第一个 H1 字母放大并为单个 H1 着色

发布于 2024-10-17 08:10:04 字数 502 浏览 3 评论 0原文

我有一个包含 5 个单词的 h1 行,我只想增加第三个、第四个和第五个首字母的大小,给它们添加下划线,然后将它们设置为不同的颜色。

我已经完成了,但是 WC3 说我的代码对于大小、下划线和颜色的每种情况下的所有属性和元素都无效。

以下是在浏览器中有效但无法验证的内容:

欢迎使用
M< /u>y <字体大小=120% 颜色=红色>Fvourite Website

这是我唯一的错误(总共 15 个)在这个设计上。

请任何人协助使用 HTML 和/或 CSS 来修复此问题,以便其验证。

我尝试过尺寸和颜色的变化,虽然它们在浏览器中工作,但它们不会验证。

谢谢 :)

I've got a h1 line of 5 words and I want to increase the size of the 3rd, 4th and 5th initial letters only, underline them and then make them a different color.

I've done it but WC3 says my code is invalid on all attributes and elements in each case of size, underlining and color.

Here's what works in the browsers but won't validate:

<p><h1>Welcome to <br /><font size="120%" color=Red><u>M</u></font>y <font size=120% color=Red><u>F</u></font>vourite
<font size=120% color=Red><u>W</u></font>ebsite</h1></p>

It's giving me my only errors (15 in all) on this design.

Please can anyone assist with the HTML and or CSS to fix this so that it validates.

I have tried variations for size and color and though they work in the browsers, they will not validate.

Thank you :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

萌梦深 2024-10-24 08:10:04

它们不会验证,因为字体标签很久以前就被弃用了,因此它的所有参数都被弃用了,

您可以在CSS中使用它:

h1 {
margin:5px;
}
#title span {
font-size: 1.2em;
color: #c13636;
text-decoration: underline;
}

并将要突出显示的单词包装在span标签中:

<span>TEST</span>

应用于您的代码:

<h1 id="title">Welcome to <br /><span>M</span>y <span>F</span>avourite <span>W</span>ebsite</h1>

演示:

http://jsfiddle.net/Mutant_Tractor/SBbcu/

They won't validate cause the font tag was deprecated long ago, and thus all of its parameters,

You can use this in CSS:

h1 {
margin:5px;
}
#title span {
font-size: 1.2em;
color: #c13636;
text-decoration: underline;
}

And wrap the word to be highlighted in span tags:

<span>TEST</span>

Applied to your code:

<h1 id="title">Welcome to <br /><span>M</span>y <span>F</span>avourite <span>W</span>ebsite</h1>

Demo:

http://jsfiddle.net/Mutant_Tractor/SBbcu/

暮倦 2024-10-24 08:10:04
<font></font> and <u></u>

已弃用。使用应用了 CSS 的

<font></font> and <u></u>

are deprecated. Use a <span></span> with CSS applied to it.

浮华 2024-10-24 08:10:04

使用带有 style 属性的 span 元素,如下所示:

<span style="font-size: 120%; color: red; text-decoration: underline;">M</span>

或者,为各种组合定义 CSS 类并使用它们。

Use a span element with a style attribute, as in:

<span style="font-size: 120%; color: red; text-decoration: underline;">M</span>

Alternatively, define CSS classes for the various combinations and use those instead.

野侃 2024-10-24 08:10:04

因此,作为摘要

  • 不能包含在

  • 不要使用
  • HTML 用于标记,CSS 用于样式

使用“纯”HTML/CSS,您有多种可能性来实现您的目标正在追赶。这是几个变化。您可能应该将 class 属性添加到 span 元素,但为了简洁起见,我在这里省略了它们。

HTML 文件:

<h1>Welcome to <span>M</span>y <span>F</span>vourite <span>W</span>ebsite</h1>

CSS 文件:

h1 span {
  font-size: 120%;
  color: red;
  text-decoration: underline;
}

HTML 文件:

<h1>Welcome to <span>My</span> <span>Favourite</span> <span>Website</span></h1>

CSS 文件:

h1 span:first-letter {
  font-size: 1.2em;
  color: red;
  text-decoration: underline;
}

So, as a summary

  • can't have inside a
  • don't use <font> or <u>
  • HTML is for markup, CSS for styling

With "pure" HTML/CSS you have multiple possibilities to achieve what you're after. Here are couple variations. You probably should add class attributes to span elements but I've omitted them here for brevity.

HTML file:

<h1>Welcome to <span>M</span>y <span>F</span>vourite <span>W</span>ebsite</h1>

CSS file:

h1 span {
  font-size: 120%;
  color: red;
  text-decoration: underline;
}

HTML file:

<h1>Welcome to <span>My</span> <span>Favourite</span> <span>Website</span></h1>

CSS file:

h1 span:first-letter {
  font-size: 1.2em;
  color: red;
  text-decoration: underline;
}
情绪失控 2024-10-24 08:10:04

您有一些无效标签

我会做这样的事情来验证和清理你的代码:

<style>
    .big {
         font-size: 1.2em;
    }

    .red {
         color: red;
    }
</style>

<h2>Welcome to</h2>
<h1>
    <span class="big red">M</span>y 
    <span class="big red">F</span>avorite 
    <span class="big red">W</span>ebsite
</h1>

甚至:

<style>
    h1 span:first-letter {
        font-size: 1.2em;
        color: red;
    }
</style>

<h2>Welcome to</h2>
<h1>
    <span>My</span>
    <span>Favorite</span> 
    <span>Website</span>
</h1>

You have some invalid tags <font> and <u>.

I would do something like this to validate and clean up your code:

<style>
    .big {
         font-size: 1.2em;
    }

    .red {
         color: red;
    }
</style>

<h2>Welcome to</h2>
<h1>
    <span class="big red">M</span>y 
    <span class="big red">F</span>avorite 
    <span class="big red">W</span>ebsite
</h1>

or even:

<style>
    h1 span:first-letter {
        font-size: 1.2em;
        color: red;
    }
</style>

<h2>Welcome to</h2>
<h1>
    <span>My</span>
    <span>Favorite</span> 
    <span>Website</span>
</h1>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文