当前位置:首页 > 行业动态 > 正文

如何用CSS代码打造一个独特的网站首页?

### ,,用CSS构建网站首页涉及多方面内容,包括页面布局、样式设计等。通过HTML定义页面结构,如导航栏、轮播图、商品分类等模块。CSS则用于设置各元素的样式,像背景、字体、颜色、间距等,以实现美观且符合需求的首页效果。

1、基础结构示例

如何用CSS代码打造一个独特的网站首页?  第1张

“`html

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Konchok</title>

<style>

* {

padding: 0;

margin: 0;

font-family: "楷体";

}

header {

background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(https://images.pexels.com/photos/1083822/pexels-photo-1083822.jpeg?cs=srgb&dl=pexels-lisa-1083822.jpg&fm=jpg);

height: 100vh;

background-size: cover;

background-position: center;

}

ul {

float: right;

list-style-type: none;

margin: 15px;

}

ul li {

display: inline-block;

}

ul li a {

text-decoration: none;

color: #fff;

padding: 5px 20px;

border: 1px solid transparent;

transition: .6s ease;

border-radius: 20px;

}

ul li a:hover {

background-color: #fff;

color: #000;

}

ul li.active a {

background-color: #fff;

color: #000;

}

.title {

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%, -50%);

}

.title h1 {

color: #fff;

font-size: 70px;

font-family: Century Gothic;

}

</style>

</head>

<body>

<header>

<div >

<ul>

<li ><a href="#">首页</a></li>

<li><a href="http://www.baidu.com" target="_blank">百度</a></li>

<li><a href="https://www.china.com" target="_blank">中华网</a></li>

<li><a href="https://blog.csdn.net" target="_blank"><span >C</span>SDN官网</a></li>

</ul>

</div>

<div >

<h1><span >My</span> Homepage</h1>

</div>

</header>

</body>

</html>

2、轮播图示例:
   ```html
     <!DOCTYPE html>
     <html lang="en">
     <head>
         <meta charset="utf-8">
         <title>去旅行吧http://-PsdHtml.CN原创作品,仅供个人学习使用,禁止转卖</title>
         <style type="text/css">
             #father {
                 position: absolute;
                 width: 100%;
                 height: 1418px;
                 z-index: 1;
                 left: 0px;
                 top: 0px;
             }
             #father #top {
                 height: 120px;
                 width: 1000px;
                 margin-right: auto;
                 margin-left: auto;
             }
             #father #title {
                 height: 42px;
                 width: 1000px;
                 margin-right: auto;
                 margin-left: auto;
                 background-image: url(http://cdn.psdhtml.cn/title-skin.jpg);
                 border: 1px solid #fafafa;
             }
             #father #line1 {
                 height: 5px;
                 width: 100%;
                 background-color: #333;
             }
             #father #title #daohang {
                 font-family: "微软雅黑";
                 font-size: 16px;
                 color: #333;
                 float: left;
                 height: 42px;
                 width: 140px;
                 border-top-width: 1px;
                 border-right-width: 1px;
                 border-bottom-width: 1px;
                 border-top-style: solid;
                 border-right-style: solid;
                 border-bottom-style: solid;
                 border-top-color: #fafafa;
                 border-right-color: #ececec;
                 border-bottom-color: #fafafa;
                 border-left-width: 1px;
                 border-left-style: solid;
                 border-left-color: #ffffff;
                 line-height: 42px;
                 text-align: center;
             }
             .d_over {
                 background-color: #217aff;
                 transition-duration: 1s;
             }
             .d_out {
                 background-color: rgba(0, 0, 0, 0);
             }
             a:link {
                 color: #333;
                 text-decoration: none;
             }
             a:visited {
                 text-decoration: none;
                 color: #000;
             }
             a:hover {
                 text-decoration: none;
                 color: #FFFFFF;
             }
             a:active {
                 text-decoration: none;
                 color: #333;
             }
             #father #main {
                 height: 600px;
                 width: 1000px;
                 margin-top: 1px;
                 margin-right: auto;
                 margin-left: auto;
                 background-color: #FFF;
                 font-family: "微软雅黑";
                 font-size: 12px;
                 line-height: 28px;
                 color: #333;
             }
             #father #main #left {
                 float: left;
                 height: 600px;
                 width: 249px;
             }
             #father #main #left #left-text #m-249 {
                 height: 272px;
                 margin-top: 15px;
             }
             #father #main #left #left-text #m-245 {
                 height: 245px;
             }
             #father #main #central {
                 float: left;
                 height: 600px;
                 width: 500px;
                 border-right-width: 1px;
                 border-left-width: 1px;
                 border-right-style: solid;
                 border-left-style: solid;
                 border-right-color: #f2f2f2;
                 border-left-color: #f2f2f2;
             }
             #father #main #left #left-text {
                 height: 520px;
                 width: 195px;
                 margin-top: 30px;
                 margin-left: 28px;
             }
             .dabiao {...} /*此处省略部分样式代码*/
         </style>
     </head>
     <body>...</body>
     </html>

相关问答FAQs:

1、如何修改网页的标题和背景颜色?:在HTML文档的<title>标签中修改网页的标题,在CSS样式表中,通过选择器如body来修改背景颜色,例如body { background-color: #f3f5f7; }。

2、导航栏中的链接如何设置鼠标悬停效果?:在CSS中,通过伪类选择器:hover来设置导航栏链接的鼠标悬停效果,对于导航栏中的一个链接,可以这样设置:nav ul li a:hover { border-bottom: 2px solid #00a4ff; }。

0