今天來練習切側邊選單
<div class="side-menu">
<form>
<input type="search" placeholder="請輸入關鍵字">
<button><i class="fas fa-search"></i></button>
</form>
<nav>
<a href="#">
<i class="fas fa-running"></i>
鐵人賽
</a>
<a href="#">
<i class="fas fa-smile"></i>
切版練習
</a>
<a href="#">
<i class="fas fa-running"></i>
自煮生活
</a>
<a href="#">
<i class="fas fa-smile"></i>
保持好心情
</a>
<a href="#">
<i class="fas fa-running"></i>
記得要運動
</a>
</nav>
</div>
設定css rest
載入google fonts字體連結
載入 font awesome圖示連結
@import url("https://fonts.googleapis.com/css?family=Noto+Sans+TC:100,300,400,500,700,900&display=swap");
@import url("https://pro.fontawesome.com/releases/v5.10.0/css/all.css");
* {
margin: 0;
padding: 0;
list-style: none;
font-family: "Noto Sans TC", sans-serif;
}
設定高度是滿版
html, body{
height: 100%;
}
設定背景色
body{
background-color: #546377;
}
目前的畫面
.side-menu{
width: 300px;
height: 100%;
background-image: linear-gradient(0deg, #3381b0, #c2196c);
display: flex;
flex-direction: column;
}
nav a{
display: block;
padding: 10px;
color:#fff;
text-decoration: none;
}
nav a{
display: block;
padding: 10px;
color:#fff;
text-decoration: none;
position: relative;
}
nav a + a::before{
content:'';
position:absolute;
border-top: 1px solid #fff;
left:10px;
right:10px;
top:0;
}
display:flex;
將input和button並排貼在一起.side-menu form{
display: flex;
margin: 0 10px;
}
.side-menu form input,
.side-menu form button{
border: none;
color: #fff;
padding:5px 10px;
}
調整input 和button的寬度
.side-menu form input{
width:230px;
}
.side-menu form button{
width:50px;
}
將input 和button 的背景顏色改成透明色
form框線設成圓弧形
.side-menu form{
display: flex;
margin: 0 10px ;
border-radius: 100px;
border:1px solid rgb(255,255,255,.4);
}
.side-menu form input,
.side-menu form button{
border: none;
background-color: transparent;
color: #fff;
padding:5px 10px;
}
.side-menu form input:focus ,
.side-menu form button:focus{
outline:none;
}
.side-menu{
width: 300px;
height: 100%;
padding:50px 0;
box-sizing: border-box;
background-image: linear-gradient(0deg, #3381b0, #c2196c);
display: flex;
flex-direction: column;
box-shadow: 5px 0px 10px hsla(240, 40%, 15%, .6);
}
nav a .fas {
margin-right: -1.1em;
transform:scale(0);
transition:.3s;
}
nav a:hover .fas{
margin-right: 0em;
transform:scale(1);
}
參考資料: 金魚都能懂的這個網頁畫面怎麼切 : 側邊選單怎麼切, 深入理解 CSS 漸層 ( CSS Gradient ), 親代選取器之妹妹選取器與鞭炮串選取器, box-shadow
以上為個人學習筆記整理
若有錯誤,歡迎指正