本次需要注意使用的了对应的flex灵活布局(很适合一些搜索栏)
分散的内容可以利用:
display: flex;
flex-direction:row; // 一行的布局
justify-content:space-between; // [1 2 3 ]like this,在一个区间里面均匀分散开
align-items:center; //位置居中
图片可以选择了利用那个下载图片方式下载对应的ui,我这里选择的就是直接复制阿里矢量图网站的一些logo来学习和复线
如果想右边的矢量图标不会随着网页大小变动,利用穿插在right-section这类里面
flex-shrink: 0;
如果想要这个效果随着网页变化最后可以直接缩小到近乎看不见的话,就是
width: 0;
如果想要保证最后这个导航栏一直固定在最上头
position: fixed;
实现结果如下:
<!DOCTYPE html>
<html>
<head>
<title>Youtube.com</title>
<link rel="stylesheet" href="video.css">
<link rel="stylesheet" href="header.css">
<link rel="stylesheet" href="general.css">
<link rel="stylesheet" href="sidebar.css">
</head>
<body>
<div class="header">
<div class="left-section">
<img class="icons-list" src="../photos/列表2.png">
<img class="icons-youtube" src="../photos/youtube.png">
Youtube
</div>
<div class="middle-section">
<input class="search-box" type="text" placeholder="Search">
<button class="search-button"> <img class="icons-search" src="../photos/搜索.png"> </button>
<button class="voice-search-button"> <img class="icons-microphone" src="../photos/麦克风.png"> </button>
</div>
<div class="right-section">
<img class="icons-video" src="../photos/视频播放.png">
<img class="icons-picture" src="../photos/图标.png">
<div class="icons-rings-container">
<img class="icons-rings" src="../photos/提示.png">
<div class="icons-rings-number"> 3</div>
</div>
<img class="present-user" src="../photos/personal-photo.jpeg">
</div>
</div>
<!-- the firsr div -->
<div class="video-preview">
<div>
<img class="thumbnail" src="../photos/thumbnail1.webp">
</div>
<div class="video-time"><strong>14:50</strong></div>
<div class="video-info-grid">
<div class="personal">
<img src="../photos/personal-photo.jpeg">
</div>
<div class="video-info">
<p class="video-title">How The Dinosaurs Actually Died</p>
<p class="video-author">Kurzgesagt-In a Nutshell </p>
<p class="video-stats">116万次观看 · 12小时前</p>
</div>
</div>
</div>
<div class="sidebar">
sidebar
</div>
<!-- the second div -->
<div class="video-preview">
<div>
<img class="thumbnail" src="../photos/thumbnail2.webp">
<div class="video-time"><strong>8:20</strong></div>
</div>
<div class="video-info-grid">
<div class="personal">
<img src="../photos/personal-photo.jpeg">
</div>
<div class="video-info2">
<p class="video-title">The Race For AI Robots Just Got Real (OpenAI, NVIDIA and more)</p>
<p class="video-author">ColdFusion </p>
<p class="video-stats">62万次观看 · 1天前</p>
</div>
</div>
</div>
</body>
</html>
.header {
display: flex;
height: 55px;
flex-direction: row;
justify-content: space-between;
align-items: center;
position: fixed;
z-index: 3;
top: 0;
left: 0;
right: 0;
background-color: white;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(240, 240, 240);
/* 或者 display: inline-block; */
/* 其他样式
这里要注意一般顶头栏都是利用的flex来设置的
flex-direction就是用来安排怎么布局的
youtube网站的搜索框是可以随着网页大小来变换他的长度的,所以也需要利用flex布局来实现(1fr)
除此以外,用justfiy来修改三个容器的布局
*/
}
.left-section {
width: 170px;
font-size: 20px;
margin-top: 0;
display: flex;
align-items: center;
/* 用对应的align结合flex格式来保证文字内容都是居中的
*/
}
.icons-list {
height: 24px;
margin-left: 20px;
margin-right: 20px;
}
.icons-youtube {
margin-left: 10px;
height: 20px;
}
.middle-section {
flex: 1;
display: flex;
align-items: center;
margin-left: 70px;
/*这个要看不同网页的具体情况*/
margin-right: 35px;
max-width: 500px;
}
.search-box {
flex: 1;
height: 34px;
padding-left: 10px;
font-size: 16px;
border-width: 1px;
border-style: solid;
border-color: rgb(192, 192, 192);
border-radius: 2px;
box-shadow: inset 1px 2px 3px rgba(0, 0, 0, 0.05);
width: 0;
}
.search-box::placeholder {
/*这个search框里面的文字未输入文字时候的设置*/
font-size: 16px;
}
.search-button {
height: 38px;
width: 60px;
background-color: rgb(240, 240, 240);
border-width: 1px;
border-style: solid;
border-color: rgb(192, 192, 192);
margin-left: -1px;
margin-right: 10px;
}
.icons-search {
height: 23px;
margin-top: 3px;
}
.voice-search-button {
height: 40px;
width: 40px;
background-color: rgb(240, 240, 240);
border-radius: 20px;
border: none;
}
.icons-microphone {
display: flex;
justify-content: center;
height: 20px;
margin-left: 3px;
}
.right-section {
width: 180px;
margin-right: 10px;
display: flex;
align-items: center;
justify-content: space-between;
flex-shrink: 0;
}
.icons-video {
height: 24px;
}
.icons-picture {
height: 23px;
}
.icons-rings-container {
position: relative;
z-index: 2;
}
.icons-rings {
height: 23px;
}
.icons-rings-number {
position: absolute;
top: -2px;
right: -5px;
color: white;
background-color: rgb(200, 0, 0);
border-radius: 50px;
font-size: 10px;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 1px;
padding-top: 1px;
}
.present-user {
height: 32px;
border-radius: 16px;
}