ウェブ学のすすめ

Study of Web Design & Programing

実践課題【CSS20】擬似クラス(9)〜横ナビ〜

課題

【CSS20】

  • 以下の画像と同じように表示させるCSSを記述しなさい
  • 擬似クラスで指定
  • 幅は適宜設定

引用元:CSS18〜21横ナビ - Webデザインの勉強|忘筌

解答

擬似クラス(9)〜横ナビ〜 - jsdo.it - share JavaScript, HTML5 and CSS

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>擬似リンク(9)</title>
<style type="text/css">
* {
    margin: 0;
    padding: 0;
}
body {
    font-family:
	"Hiragino Kaku Gothic Pro",
	"ヒラギノ角ゴ Pro W3",
	Meiryo, 
	"メイリオ", 
	Osaka, 
	"MS P Gothic", 
	"MS Pゴシック", 
	sans-serif;
}
.nav {
    width: 900px;
    height: auto;
    margin: 20px 0 0 20px;
    padding-right: 20px;
}
.nav ul {
    list-style-type: none;
    width: 900px;
    height: auto;
    border-left: 1px solid #fff;
    overflow: auto;
    background-color: #22952d;	
}
.nav li {
    font-size: 1em;
    font-weight: bold;
    text-align: center;
    width: 148px;
    height: auto;
    float: left;
    display: inline;
    border-right: 1px solid #fff;
}
.nav li a {
    padding: 10px 0;
    display: block;
    text-decoration: none;
}
.nav li a:link, .nav li a:visited {
    color: #fff;
    background-color: #22952d;	
}
.nav li a:hover {
    color: #fff;
    background-color: #04c864;
}
</style>
</head>
<body>
<div class="nav">
<ul>
<li><a href="#">メニューのリンク1</a></li>
<li><a href="#">メニューのリンク2</a></li>
<li><a href="#">メニューのリンク3</a></li>
<li><a href="#">メニューのリンク4</a></li>
<li><a href="#">メニューのリンク5</a></li>
</ul>
</div>
</body>
</html>