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

时间:2022-05-19 20:32:03

I'm a profane in CSS, I don't know anything about it. I need to put HTML code and the CSS formatting for it in the same string object for an iPhone program.

我是CSS的*者,我对它一无所知。我需要为iPhone程序将HTML代码和CSS格式放在同一个字符串对象中。

I have the HTML code and the CSS code, but I don't know how to mix them together. Could you help me?

我有HTML代码和CSS代码,但我不知道如何将它们混合在一起。你能帮我吗?

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;
}

6 个解决方案

#1


77  

<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.

顺便说一句,这样做会容易得多。

#2


4  

You can include CSS styles in an html document with <style></style> tags.

您可以在带有标签的html文档中包含CSS样式。

Example:

例子:

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

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

#3


3  

Is this what you're looking for? You place you CSS between style tags in the HTML document header. I'm guessing for iPhone it's webkit so it should work.

这就是你要找的吗?在HTML文档头中的样式标签之间放置CSS。我猜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>

#4


2  

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标签的样式属性中添加任何CSS。

#5


0  

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>

#6


0  

Two options: 1, add css inline like style="background:black" Or 2. In the head include the css as a style tag block.

两个选项:1,添加css内联样式="背景:黑色"或2。在head中包含css作为样式标记块。

#1


77  

<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.

顺便说一句,这样做会容易得多。

#2


4  

You can include CSS styles in an html document with <style></style> tags.

您可以在带有标签的html文档中包含CSS样式。

Example:

例子:

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

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

#3


3  

Is this what you're looking for? You place you CSS between style tags in the HTML document header. I'm guessing for iPhone it's webkit so it should work.

这就是你要找的吗?在HTML文档头中的样式标签之间放置CSS。我猜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>

#4


2  

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标签的样式属性中添加任何CSS。

#5


0  

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>

#6


0  

Two options: 1, add css inline like style="background:black" Or 2. In the head include the css as a style tag block.

两个选项:1,添加css内联样式="背景:黑色"或2。在head中包含css作为样式标记块。