Q. can i include CSS in a HTML document without creating a .css file?

starryme 2019. 04. 24. 조회수 444


Can I include CSS in a HTML document without creating a .css file?

is it possible?

공유하고 보상받기 ♥︎
댓글 0

2개의 답변이 있습니다.

질문자 채택
idolpia 답변자인증
프리랜서 2019. 04. 24 21%의 채택

Yes, it's possible!

Example 1)

<!DOCTYPE html>
<html>
<body>
  <h1 style="background-color:Red;">Red</h1>
  <h1 style="background-color:Green;">Green</h1>
  <h1 style="background-color:Blue;">Blue</h1>
</body>
</html>

Example 2)

<!DOCTYPE html>
<html>
<head>
  <style>
      h1 {color:red;}
      p  {color:blue;}
  </style>
</head>

<body>
    <h1> 제목입니다 / headline color is red</h1>
    <p> 글자가 파란색으로 나와요 /  text color is blue</p>
</body>
</html>
댓글 0
큐레이터 채택
프알못 답변자인증
익스트림 QA팀 2019. 04. 24 79%의 채택

Sure you can!

<html>
 <head>
  <title>bla bla bla ~</title>
  <link rel="stylesheet" href="(path of file below)" />
 </head>
 <body>
  <p>Hello World!</p>
 </body>
</html>
body
{
    background: #000000;
}

h1
{
    color: #FFFFFF;
}

Separating css file is good habit. but if you really really hate to separate into multiple files...

<html>
 <head>
  <title>bla bla bla ~</title>
  <style>
    body
    {
        background: #000000;
    }

    h1
    {
        color: #FFFFFF;
    }
  </style>
 </head>
 <body>
  <p>Hello World!</p>
 </body>
</html>

You can combine it using style tag, but not recommended.

댓글 0