Style Link
- 링크는 CSS 속성(예 : color : font-family, background 등)을 사용하여 스타일을 지정할 수 있다.
- Link에 text-decoration(구분선), background-color(배경색)을 지정할 수 있다.
- 링크 상태는 다음과 같다.
- a:link - 방문하지 않은 정상적인 링크
- a:visited - 사용자가 방문한 링크
- a:hover - 사용자가 마우스를 위에 올려놓았을 때의 링크
- a:active - 클릭하는 순간의 링크
- [주의사항 1] a:hover는 반드시 a:link 및 a:visited 뒤에 와야 한다.
- [주의사항 2] a:active는 반드시 a:hover 뒤에 와야 한다.
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: hotpink;
}
/* selected link */
a:active {
color: blue;
}
Link Button
- 여러 CSS 속성을 결합하여 링크를 상자 혹은 버튼으로 표시하는 예시
<!DOCTYPE html>
<html>
<head>
<style>
a:link, a:visited {
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: red;
}
</style>
</head>
<body>
<h2>Link Button</h2>
<p>A link styled as a button:</p>
<a href="default.asp" target="_blank">This is a link</a>
</body>
</html>
Link Button
A link styled as a button:
This is a link
하이퍼링크에 다른 스타일을 추가하는 실습 예제
<!DOCTYPE html>
<html>
<head>
<style>
a.one:link {color:#ff0000;}
a.one:visited {color:#0000ff;}
a.one:hover {color:#ffcc00;}
a.two:link {color:#ff0000;}
a.two:visited {color:#0000ff;}
a.two:hover {font-size:150%;}
a.three:link {color:#ff0000;}
a.three:visited {color:#0000ff;}
a.three:hover {background:#66ff66;}
a.four:link {color:#ff0000;}
a.four:visited {color:#0000ff;}
a.four:hover {font-family:monospace;}
a.five:link {color:#ff0000;text-decoration:none;}
a.five:visited {color:#0000ff;text-decoration:none;}
a.five:hover {text-decoration:underline;}
</style>
</head>
<body>
<h2>Styling Links</h2>
<p>Mouse over the links and watch them change layout:</p>
<p><b><a class="one" href="default.asp" target="_blank">This link changes color</a></b></p>
<p><b><a class="two" href="default.asp" target="_blank">This link changes font-size</a></b></p>
<p><b><a class="three" href="default.asp" target="_blank">This link changes background-color</a></b></p>
<p><b><a class="four" href="default.asp" target="_blank">This link changes font-family</a></b></p>
<p><b><a class="five" href="default.asp" target="_blank">This link changes text-decoration</a></b></p>
</body>
</html>
링크 상자 혹은 버튼을 만드는 방법의 또 다른 실습 예제
<!DOCTYPE html>
<html>
<head>
<style>
a:link, a:visited {
background-color: white;
color: black;
border: 2px solid green;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: green;
color: white;
}
</style>
</head>
<body>
<h2>Link Button</h2>
<a href="default.asp" target="_blank">This is a link</a>
</body>
</html>
다양한 유형의 커서를 보여주는 실습 예제
<!DOCTYPE html>
<html>
<body>
<h2>The cursor Property</h2>
<p>Mouse over the words to change the cursor.</p>
<span style="cursor:auto">auto</span><br>
<span style="cursor:crosshair">crosshair</span><br>
<span style="cursor:default">default</span><br>
<span style="cursor:e-resize">e-resize</span><br>
<span style="cursor:help">help</span><br>
<span style="cursor:move">move</span><br>
<span style="cursor:n-resize">n-resize</span><br>
<span style="cursor:ne-resize">ne-resize</span><br>
<span style="cursor:nw-resize">nw-resize</span><br>
<span style="cursor:pointer">pointer</span><br>
<span style="cursor:progress">progress</span><br>
<span style="cursor:s-resize">s-resize</span><br>
<span style="cursor:se-resize">se-resize</span><br>
<span style="cursor:sw-resize">sw-resize</span><br>
<span style="cursor:text">text</span><br>
<span style="cursor:w-resize">w-resize</span><br>
<span style="cursor:wait">wait</span><br>
</body>
</html>
CSS Link 실습 코드
<!DOCTYPE html>
<html>
<head>
<style>
/* unvisited link 방문전색상*/
a:link {
color: red;
}
/* visited link 방문후 색상*/
a:visited {
color: green;
}
/* mouse over link 마우스 올렸을 때 색상*/
a:hover {
color: hotpink;
}
/* selected link 마우스로 링크를 선택해서 드래그했을 때 색상 */
a:active {
color: blue;
}
</style>
</head>
<body>
<h2>Styling a link depending on state</h2>
<p><b><a href="default.asp" target="_blank">This is a link</a></b></p>
<p><b>Note:</b> a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective.</p>
<p><b>Note:</b> a:active MUST come after a:hover in the CSS definition in order to be effective.</p>
</body>
</html>
Styling a link depending on state
Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective.
Note: a:active MUST come after a:hover in the CSS definition in order to be effective.
'Devlopment > HTML & CSS' 카테고리의 다른 글
[CSS] 레이아웃 속성 - Layout Display (0) | 2024.01.07 |
---|---|
[CSS] 표(Tables) 생성 및 속성 실습 (0) | 2024.01.07 |
[CSS] 텍스트 서식 (Text) (0) | 2024.01.07 |
[CSS] Box Model - 박스 모델(Margin, Border, Padding, Content) (1) | 2024.01.05 |
[CSS] Backgrounds - 배경색 설정 (0) | 2024.01.05 |