金魚都能懂的網頁切版:8、9
https://codepen.io/mikeyam/pen/mdPNOwX
在外層用flex特性,把子層都做水平、垂直置中,並且logo用 position: absolute;固定
.header{
background: linear-gradient(-20deg,burlywood,#fe70d8);
}
.container{
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
max-width: 1200px;
margin: auto;
.logo{
width: 100px;
position: absolute;
}
.logo img{
width: 100%;
vertical-align: middle;
}
}
a:nth-child(3)
把第三個a連結往左推
.main-nav{
display: flex;
}
.main-nav a{
text-decoration: none;
color: #fff;
padding: 5px 1em;
position: relative;
transform: translateY(0px);
transition: 1s;
}
.main-nav a:nth-child(3){
margin-left: 140px ;
}
.main-nav a:hover{
transform: translateY(-5px);
}
.main-nav a::after{
content: '';
position: absolute;
left: 50%;
right: 50%;
height: 0;
bottom: -5px;
border-bottom: 1px solid #fff;
transition: .3s;
}
.main-nav a:hover::after{
left: 0;
right: 0;
}
https://codepen.io/mikeyam/pen/ExKqNoy?editors=0110
外層一樣用flex排列,我把麵包屑設定固定寬度
.wrap{
padding: 10px 0;
background-color: black;
box-shadow: 0px 5px 5px blue;
}
body{
background-color: cornsilk;
}
.breadcrumb{
max-width: 700px;
display: flex;
}
這裡用到:last-child,可以選定最後一個做設定
用到+號的選取器,可以使li做出padding-left: 0;,但不包括第一個
參考:https://code.tutsplus.com/zh-hant/tutorials/the-30-css-selectors-you-must-memorize--net-16048
.breadcrumb li{
padding: 0 20px;;
}
.breadcrumb a{
text-decoration: none;
color: #fff;
}
.breadcrumb a:hover,
.breadcrumb li:last-child a{
color: #ff0;
}
.breadcrumb li + li{
padding-left: 0;
}
.breadcrumb li + li:before{
content: '>';
color: #fff;
margin-right: 20px;
}