Computer >> 컴퓨터 >  >> 프로그램 작성 >> CSS

CSS를 사용하여 요소의 텍스트 색상 설정

<시간/>

CSS color 속성은 요소의 텍스트 색상을 변경하는 데 사용됩니다. 표준 색상 이름, rgb(), rgba(), hsl(), hsla() 및 16진수 값으로 값을 지정할 수 있습니다.

구문

CSS 색상 속성의 구문은 다음과 같습니다. -

Selector {
   color: /*value*/
}

다음 예는 CSS 색상 속성을 보여줍니다 -

예시

<!DOCTYPE html>
<html>
<head>
<style>
div {
   height: 50px;
   width: 50px;
   float: right;
   color: white;
   background-color: #2f5587;
}
p {
   color: rgba(225,5,135,0.7);
   border: 2px solid #16c618;
   box-shadow: 0 7px 0 5px hsl(90, 60%, 70%);
}
</style>
</head>
<body>
<h2>Example Heading</h2>
<div>This is it</div>
<p>Demo text is visible here.</p>
</body>
</html>

출력

이것은 다음 출력을 제공합니다 -

CSS를 사용하여 요소의 텍스트 색상 설정

예시

<!DOCTYPE html>
<html>
<head>
<style>
li:nth-of-type(even) {
   color: dodgerblue;
   border: 6px groove #16c618;
   padding: 4px;
   box-shadow: inset -100px 0 5px red;
}
</style>
</head>
<body>
<h2>Learn Servlets</h2>
<ul>
<li>Java Servlets are programs that run on a Web or Application server.</li>
<li>Java Servlets often serve the same purpose as programs implemented using the CGI.</li>
<li>Servlets are platform-independent because they are written in Java.
</li>
</ul>
</body>
</html>

출력

이것은 다음 출력을 제공합니다 -

CSS를 사용하여 요소의 텍스트 색상 설정