<div class="cp_navi01">
<ul>
<li><a href="#home" class="active">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</div>
.cp_navi01 ul {
width: 200px;/*メニューの幅*/
margin: 0;
padding: 0;
list-style-type: none;
background-color: #eeeeee;
}
.cp_navi01 li a {
display: block;
padding: 8px 16px;
text-decoration: none;
color: #000000;
transition: all .3s;
}
.cp_navi01 li {
text-align: center;
}
.cp_navi01 li:last-child {
border-bottom: none;
}
.cp_navi01 li a.active {
color: #ffffff;
background-color: #da3c41;
}
.cp_navi01 li a:hover:not(.active) {
color: #ffffff;
background-color: #1b2538;
}
<div class="cp_navi02">
<ul>
<li><a href="#home" class="active">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</div>
.cp_navi02 ul {
display: flex;
flex-flow: row;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1b2538;
}
.cp_navi02 li {
border-right: 1px solid #bbbbbb;
}
/*最後の項目のみ右に寄せる*/
.cp_navi02 li:last-child {
border-right: none;
margin-left: auto;
}
.cp_navi02 li a {
display: block;
color: #ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: all .3s;
}
.cp_navi02 li a:hover:not(.active) {
background-color: #a9bce2;
}
.cp_navi02 .active {
background-color: #da3c41;
}
<div class="cp_navi06">
<ul>
<li><a href="#">Home</a></li>
<li>
<a href="#" class="caret">Products</a>
<ul>
<li><a href="#cat">cat</a></li>
<li><a href="#dog">dog</a></li>
<li><a href="#rabbit">rabbit</a></li>
</ul>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Help</a></li>
</ul>
</div>
.cp_navi06 {
background-color: #ffffff;
border: 1px solid #dedede;
border-radius: 4px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: #888888;
display: block;
margin: 1em auto;
overflow: hidden;
width: 100%;
}
.cp_navi06 ul {
display: flex;
margin: 0;
padding: 0;
}
.cp_navi06 ul li {
list-style-type: none;
transition: all 0.3s;
}
.cp_navi06 ul li a.caret {
display: flex;
align-items: center;
}
.cp_navi06 ul li a.caret::after {
content: '';
background: #aaaaaa;
width: 10px;
height: 5px;
clip-path: polygon(50% 100%, 0 0, 100% 0);
transition: color 0.1s linear;
}
.cp_navi06 ul li a {
color: #aaaaaa;
display: block;
line-height: 56px;
padding: 0 10px;
text-decoration: none;
}
.cp_navi06 ul li:hover {
background-color: rgb(218, 60, 65);
}
.cp_navi06 ul li:hover a {
color: #ffffff;
}
.cp_navi06 ul li:hover a.caret::after {
background: #ffffff;
}
/*下層に隠れたメニューの動き*/
.cp_navi06 ul li ul {
background-color: rgb(218, 60, 65);
border-top: 0;
border-radius: 0 0 4px 4px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
display: none;
margin: 0;
opacity: 0;
position: absolute;
width: 165px;
visibility: hidden;
transition: all 0.3s;
}
.cp_navi06 ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
.cp_navi06 ul li ul li {
border-radius: 0 0 4px 4px;
}
.cp_navi06 ul li ul li a {
color: #ffffff;
}
.cp_navi06 ul li ul li:hover a {
background-color: rgba( 255, 255, 255, 0.1);
}
<div class="cp_navi03">
<ul class="sidenav">
<li><a href="#home" class="active">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</div>
.cp_navi03 ul.sidenav {
position: relative;
display: flex;
flex-direction: column;
width: 200px;
height: auto;
margin: 0;
padding: 0;
background: #f1f1f1;
list-style-type: none;
}
.cp_navi03 ul.sidenav li a {
display: block;
color: #000000;
padding: 15px;
text-decoration: none;
}
.cp_navi03 ul.sidenav li a.active {
background: #da3c41;
color: #ffffff;
}
/*.active以外のhoverの動き*/
.cp_navi03 ul.sidenav li a:hover:not(.active) {
background-color: #1b2538;
color: #ffffff;
}
@media screen and (max-width: 900px) {
.cp_navi03 ul.sidenav {
flex-direction: row;
width: 100%;
}
}
@media screen and (max-width: 480px) {
.cp_navi03 ul.sidenav {
flex-direction: column;
text-align: center;
}
}
<div class="cp_navi04">
<ul class="topnav">
<li><a href="#home" class="active">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</div>
.cp_navi04 ul.topnav {
position: relative;
display: flex;
flex-direction: row;
width: 100%;
height: auto;
margin: 0;
padding: 0;
background: #1b2538;
list-style-type: none;
}
.cp_navi04 ul.topnav li a {
display: block;
padding: 14px 16px;
text-decoration: none;
color: #ffffff;
}
.cp_navi04 ul.topnav li a:hover:not(.active) {
background-color: #a9bce2;
}
.cp_navi04 ul.topnav li a.active {
background-color: #da3c41;
}
.cp_navi04 ul.topnav li:last-child {
margin-left: auto;
}
@media screen and (max-width: 480px) {
.cp_navi04 ul.topnav {
flex-direction: column;
text-align: center;
}
.cp_navi04 ul.topnav li:last-child {
margin-left: 0;
}
}
<div class="cp_navi05">
<div class="sidenav">
<a href="#" id="home">Home</a>
<a href="#" id="news">News</a>
<a href="#" id="contact">Contact</a>
<a href="#" id="about">About</a>
</div>
</div>
.cp_navi05 {
position: relative;
overflow: hidden;
width: 360px;
height:360px;
}
.cp_navi05 a {
position: absolute;
left: -110px;
width: 110px;
padding: 15px 5px 15px 20px;
text-decoration: none;
color: #ffffff;
border-radius: 0 5px 5px 0;
transition: all 0.3s;
}
.cp_navi05 a:hover {
left: -10px;
}
.cp_navi05 #home {
top: 20px;
background-color: #da3c41;
}
.cp_navi05 #news {
top: 80px;
background-color: #1b2538;
}
.cp_navi05 #contact {
top: 140px;
background-color: #2e9b72;
}
.cp_navi05 #about {
top: 200px;
background-color: #a62e7a;
}
<div class="cp_navi07">
<input type="checkbox" id="cp_navimenuid">
<label class="menu07" for="cp_navimenuid">
<div class="menubar">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</div>
<ul>
<li><a id="home" href="#">Home</a></li>
<li><a id="about" href="#">About</a></li>
<li><a id="contact" href="#">Contact</a></li>
</ul>
</label>
<!-- メニューが開いているときに背景に表示される透明なオーバーレイ -->
<label class="background_overlay" for="cp_navimenuid"></label>
</div>
.cp_navi07 .menu07 {
display: flex;
align-items: center;
justify-content: center;
width: 60px;
height: 60px;
margin: 0 auto;
cursor: pointer;
transition: all 0.5s ease-in-out;
border-radius: 50%;
background-color: #1b2538;
}
.cp_navi07 .menu07 div.menubar {
width: 30px;
height: 30px;
}
.cp_navi07 .menu07 div.menubar .bar {
display: block;
width: 100%;
height: 5px;
margin-top: 3px;
margin-bottom: 5px;
border-radius: 2px;
background-color: #ffffff;
}
.cp_navi07 .menu07 ul {
position: relative;
display: none;
margin: 0;
padding: 0;
list-style-type: none;
text-align: center;
opacity: 0;
z-index: 2;
transition: all 0.5s ease;
}
.cp_navi07 .menu07 ul li {
display: flex;
}
.cp_navi07 .menu07 ul li a {
display: flex;
align-items: center;
height: 50px;
padding: 0 0.5em;
color: #1b2538;
text-decoration: none;
transition: all 0.3s ease-in;
}
.cp_navi07 .menu07 ul li a:hover {
color: #ffffff;
background: #1b2538;
}
/* クリックした時の動き */
.cp_navi07 #cp_navimenuid {
display: none;
}
.cp_navi07 #cp_navimenuid:checked ~ .menu07 {
width: 100%;
height: 60px;
border: 3px solid #1b2538;
border-radius: 5px;
background-color: transparent;
}
.cp_navi07 #cp_navimenuid:checked ~ .menu07 > ul {
display: flex;
opacity: 1;
}
.cp_navi07 #cp_navimenuid:checked ~ .menu07 > .menubar {
display: none;
}
.menu07 li::before {display: none;}
/* 新しく背景のdivを追加して、チェックが入っている時のみ表示 */
.cp_navi07 #cp_navimenuid:checked ~ .background_overlay {
display: flex;
}
.background_overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0);
z-index: 0;
}