简体   繁体   English

如何将 CSS 和 HTML 代码放在同一个文件中?

[英]How can I put CSS and HTML code in the same file?

I'm a profane in CSS, I don't know anything about it.我是 CSS 的亵渎者,我对此一无所知。 I need to put HTML code and the CSS formatting for it in the same string object for an iPhone program.我需要将 HTML 代码和它的 CSS 格式放在 iPhone 程序的同一个字符串对象中。

I have the HTML code and the CSS code, but I don't know how to mix them together.我有 HTML 代码和 CSS 代码,但我不知道如何将它们混合在一起。 Could you help me?你可以帮帮我吗?

The HTML code: HTML代码:

<html>
<head>
    <link type="text/css" href="./exemple.css" rel="stylesheet" media="all" />
</head>
<body>
    <p>
    <span class="title">La super bonne</span>
    <span class="author">proposée par Jérém</span>
    </p>
</body>
</html>

The CSS styles: CSS样式:

.title {
    color: blue;
    text-decoration: bold;
    text-size: 1em;
}

.author {
    color: gray;
}
<html>
<head>
    <style type="text/css">
    .title {
        color: blue;
        text-decoration: bold;
        text-size: 1em;
    }

    .author {
        color: gray;
    }
    </style>
</head>
<body>
    <p>
    <span class="title">La super bonne</span>
    <span class="author">proposée par Jérém</span>
    </p>
</body>
</html>

On a side note, it would have been much easier to just do this .在一个侧面说明,这本来是容易只是做这个

You can include CSS styles in an html document with <style></style> tags.您可以使用<style></style>标签在 html 文档中包含 CSS 样式。

Example:例子:

<style>
  .myClass { background: #f00; }

  .myOtherClass { font-size: 12px; }
</style>

Is this what you're looking for?这是你要找的吗? You place you CSS between style tags in the HTML document header.您将 CSS 放在 HTML 文档标题中的style标记之间。 I'm guessing for iPhone it's webkit so it should work.我猜 iPhone 是 webkit,所以它应该可以工作。

<html>
<head>
    <style type="text/css">
    .title { color: blue; text-decoration: bold; text-size: 1em; }
    .author { color: gray; }
    </style>
</head>
<body>
    <p>
    <span class="title">La super bonne</span>
    <span class="author">proposée par Jérém</span>
    </p>
</body>
</html>

Or also you can do something like this.或者你也可以做这样的事情。

<div style="background=#aeaeae; float: right">

</div>

We can add any CSS inside the style attribute of HTML tags.我们可以在 HTML 标签的style属性中添加任何 CSS。

There's a style tag, so you could do something like this:有一个样式标签,所以你可以做这样的事情:

<style type="text/css">
  .title 
  {
    color: blue;
    text-decoration: bold;
    text-size: 1em;
  }
</style>

两个选项: 1,添加 css inline like style="background:black" 或者 2. 在头部包含 css 作为样式标记块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM