没有 CSS 的 html 文本样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21949198/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:00:05  来源:igfitidea点击:

Styling html text without CSS

csshtmltextstyles

提问by Samcfuchs

I would like to html code part of my tumblr page, but in the context, I can't add any css. Is there any way to format text size, font, color, etc. without using css? I looked at <font>tags but they don't seem to be supported in html5. Is there a workaround or tag that would do this for me?

我想对我的 tumblr 页面的 html 代码部分,但在上下文中,我无法添加任何 css。有没有办法在不使用 css 的情况下格式化文本大小、字体、颜色等?我查看了<font>标签,但 html5 似乎不支持它们。是否有解决方法或标签可以为我执行此操作?

Thanks for all your help

感谢你的帮助

采纳答案by Alexander

Add CSS as a style directly to the tag you want to format.

将 CSS 作为样式直接添加到要设置格式的标签中。

EX.

前任。

<p style="width:20px;height:20px;background-color:#ffcc00;">The contents go here</p>

<p style="width:20px;height:20px;background-color:#ffcc00;">The contents go here</p>

回答by Jukka K. Korpela

With HTML alone, without any CSS, you can set

单独使用 HTML,无需任何 CSS,您可以设置

  • font family with <font face=...>
  • font size with <font size=...>(though just to a few values)
  • text color with <font color=...>
  • italic typefact with <i>
  • bold typeface with <b>
  • superscripts with <sup>
  • subscripts with <sub>
  • underlining with <u>
  • forced line breaks with <br>
  • allowed direct line break points with <wbr>
  • allowed hyphenation (word division) points with &shy;
  • no line breaks with <nobr>
  • text alignment in some elements with alignattribute or (for vertical alignment) valignattribute
  • background color and/or image with bgcolorand backgroundattributes in bodyelement and in table-related elements
  • automatically scrolling text with <marquee>
  • 字体系列 <font face=...>
  • 字体大小<font size=...>(虽然只是几个值)
  • 文字颜色与 <font color=...>
  • 斜体字 <i>
  • 加粗字体 <b>
  • 上标 <sup>
  • 下标 <sub>
  • 下划线 <u>
  • 强制换行 <br>
  • 允许直接断点与 <wbr>
  • 允许的连字(分词)点 &shy;
  • 没有换行符 <nobr>
  • 某些具有align属性或(用于垂直对齐)valign属性的元素中的文本对齐方式
  • 背景颜色和/或图像,在元素和与表格相关的元素中具有bgcolorbackground属性body
  • 自动滚动文本 <marquee>

and some other formatting tools (it is somewhat debatable what belongs to text formatting).

和其他一些格式化工具(文本格式属于什么内容有些争议)。

Although HTML5 drafts declare many of these as “obsolete” and “nonconforming”, they also require or strongly recommend (depending on element) that browsers continue supporting them, with the exception of nobr(which is well supported by browsers, with no signs of getting dropped).

尽管 HTML5 草案将其中许多声明为“过时”和“不合格”,但它们也要求或强烈建议(取决于元素)浏览器继续支持它们,除了nobr(浏览器很好地支持,没有迹象表明掉了)。

(HTML5 is a draft specification. It does not “support” anything; browsers do. Specifications may require support, but that's just a normative statement, about how things should be.)

(HTML5 是一个草案规范。它不“支持”任何东西;浏览器支持。规范可能需要支持,但这只是一个规范性声明,关于事情应该如何。)

If you can in fact use CSS at least in styleattributes, then there are many more possibilities, though styling is then clumsy and limited.

如果您实际上至少可以在style属性中使用 CSS ,那么还有更多的可能性,尽管样式是笨拙和有限的。

回答by Michael Mulvey

CSS in a separate file may not be the answer but you may be able to include it in the head of the HTML file like so:

单独文件中的 CSS 可能不是答案,但您可以将其包含在 HTML 文件的头部,如下所示:

    <doctype HTML>
    <html>
    <head> <title>My title</title>
        <style>h1{
            color:red;
            font-size:20px;
    }
        </style>
    </head>
    <body><h1>My large text heading</h1>
     <script>alert("Hi , I'm in javascript inside the HTML File");</script>
    </body>
    </html>

That's the easiest way and by doing so the code is in all one place ,inside the head of the HTML file in a style tag and can be edited easily. FYI Javascript functions can be added by placing them inside a '<script >alert("Hi , I'm in javascript");</script>' tag like above HTML code shows.

这是最简单的方法,通过这样做,代码就在一个地方,在 HTML 文件的头部内的样式标签中,可以很容易地进行编辑。仅供参考 Javascript 函数可以通过将它们放置在 '<script >alert("Hi , I'm in javascript");</script>' 标签中来添加,如上面的 HTML 代码所示。

回答by Oak

Great Question,

好问题,

There are a couple ways that you could go about doing this. One way to go about doing this is by using inline css. Inline css looks like this: <p style="color:red">

有几种方法可以做到这一点。一种方法是使用内联 css。内联 css 看起来像这样:<p style="color:red">

The Second way about going this is by seeing if your template has advanced settings under the settings. There you can edit the css file and then reference it in the html!

第二种方法是查看您的模板是否在设置下具有高级设置。在那里您可以编辑 css 文件,然后在 html 中引用它!

The second way will save you tons of time and help your blog look nice!

第二种方法将为您节省大量时间并帮助您的博客看起来不错!

Your Welcome,

别客气,

Oak

橡木

回答by GURU

You may use the span style, div styles for styling the web page with out using cascading sheets.

您可以使用 span 样式、div 样式来设置网页样式,而无需使用级联表。

Ex:<span style="color:#abc123;"> NAME </span>

前任:<span style="color:#abc123;"> NAME </span>

回答by keno

You can also add <a href="thepagelink.html" style="text-decoration:none;"></a>This would remove the underline and any formatting on the link. You can then also add your own styling e.g <a href="thepagelink.html" style="text-decoration:none;" style="color: #07781C;"></a>

您还可以添加<a href="thepagelink.html" style="text-decoration:none;"></a>这将删除链接上的下划线和任何格式。然后,您还可以添加自己的样式,例如<a href="thepagelink.html" style="text-decoration:none;" style="color: #07781C;"></a>