整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

H5网页布局+css代码美化,零基础参考

TML5的结构化标签,对搜索引擎更友好

li 标签对不利于搜索引擎的收录,尽量少用

banner图片一般拥有版权,不需要搜索引擎收录,因此可以使用ul + li

<samp></samp>可用于浅色副标题

display:inline-block; 每个导航块存在水平间隙,解决方法是在父元素上添加font-size:0;


sublime安装csscomb插件

选中css代码,ctrl+shift+c 自动整理好代码

排序前:

排序后:

此时存在多余的空行

解决方法:

安装cssformat插件,对代码执行edit->cssformat->expanded 即可删除空行


选中单句样式前面的空白部分(即tab空位)

然后alt+f3 会统一选中所有tab留白

按一次删除,再按一次删除,再空一格

此时这个效果:

然后按向下箭头,按向左箭头,按删除一次,再加个空格

此时效果

再向下箭头,再删除

此时效果

css样式代码美化完毕。

新标签元素的浏览器兼容解决:

header,nav,section,aside,article,footer{display: block;}

最后晒出所有代码

index.html

<!DOCTYPE html>
<html lang="en" manifest="index.manifest">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
    <header>
        <div class="container">
            <a href="#"><img src="cat-little.jpg"></a>
            <nav>
                <a href="#" class="active">导航</a>
                <a href="#">导航</a>
                <a href="#">导航</a>
                <a href="#">导航</a>
                <a href="#">导航</a>
            </nav>
        </div>
    </header>

    <section class="banner">
        <ul>
            <li class="left"><img src="banner1.jpg"></li>
            <li class="active"><img src="banner3.jpg"></li>
            <li class="right"><img src="banner2.jpg"></li>
        </ul>
    </section>

    <section class="main">
        <aside>
            <h1>左边<samp>标题</samp></h1>
            <dl>
                <dt>小标题</dt>
                <dd class="text">文字内容哦~</dd>
                <dd class="pic"><img src="p1.jpg"></dd>
            </dl>
            <dl>
                <dt>小标题</dt>
                <dd class="text">文字内容哦~</dd>
                <dd class="pic"><img src="p2.jpg"></dd>
            </dl>
            <dl>
                <dt>小标题</dt>
                <dd class="text">文字内容哦~</dd>
                <dd class="pic"><img src="p3.jpg"></dd>
            </dl>
        </aside>
        <article>
            <h1>右边<samp>标题</samp></h1>
            <p>这是右边文章内容哦~</p>
            <img src="qrt.jpg">
            <p>这是右边文章内容哦~</p>
        </article>
    </section>

    <footer>
        <div class="container">
            <p>版权信息</p>
            <span>
                <img src="b1.jpg">
                <img src="b2.jpg">
                <img src="b3.jpg">
            </span>
        </div>        
    </footer>
</body>
</html>

style.css

* { font-size: 14px; margin: 0; padding: 0; border: none;}
a { text-decoration: none;}
ul { list-style: none;}

/*浏览器兼容解决*/
header,nav,section,aside,article,footer{display: block;}

/*头部*/
header { width: 100%; height: 60px; background-color: #000;}
.container { width: 1200px; margin: 0 auto;}
.container > a { display: block; float: left; width: 150px; height: 60px; padding-left: 10px;}
.container > a img { height: 40px; padding-top: 10px;}
nav { font-size: 0; float: right; padding-right: 10px;}
nav > a { font-size: 16px; line-height: 60px; display: inline-block; width: 100px; height: 60px; cursor: pointer; text-align: center; color: #fff;}
nav > a:first-child { background: rgb(212, 1, 18);}
nav > a:nth-child(2) { background: rgb(254, 184, 0);}
nav > a:nth-child(3) { background: rgb(120, 185, 23);}
nav > a:nth-child(4) { background: rgb(242, 124, 1);}
nav > a:last-child { background: rgb(1, 127, 203);}
nav > a:hover, nav > a.active { padding-bottom: 5px;}

/*banner*/
.banner { background: #ccc;}
.banner ul { position: relative; width: 1200px; height: 400px; margin: 0 auto; padding-top: 100px;}
.banner ul li { position: absolute; z-index: 1; top: 0; bottom: 0; overflow: hidden; width: 500px; height: 250px; margin: auto;}
.banner ul li img { overflow: hidden; width: 100%;}
.banner ul li.active { z-index: 2; right: 0;    /*设置水平居中*/ left: 0; width: 600px; height: 300px;}
.banner ul li.left { /*设置在左边*/ left: 0;}
.banner ul li.right { /*设置在右边*/ right: 0;}

/*主体部分*/
.main { width: 1200px; height: 350px; margin: 0 auto;}
aside { float: left; width: 600px;}
article { float: right; width: 600px;}
.main h1 { font-size: 24px; font-weight: lighter; margin: 20px 0;}
.main h1 samp { color: #7d7d7d;}
aside img { height: 70px;}
aside dl { position: relative; margin-bottom: 10px;}
aside dl dt { position: absolute; top: 0; left: 90px;}
aside dd.pic { overflow: hidden; width: 70px; height: 70px;}
aside dd.text { position: absolute; top: 20px; left: 90px;}
article > img { overflow: hidden; height: 130px;}
article > p { margin-bottom: 10px;}

/*底部*/
footer { background-color: #000;}
footer > .container { width: 1200px; height: 60px; margin: 0 auto;}
footer > .container > p { line-height: 60px; float: left; color: #fff;}
footer > .container > span { float: right;}
footer > .container > span > img { width: 25px; height: 25px; margin-left: 10px; padding-top: 17px; cursor: pointer; opacity: .7;}
footer > .container > span > img:hover { opacity: 1;}
/*# sourceMappingURL=style.css.map */

效果图

原文链接:https://www.cnblogs.com/chenyingying0/p/12250255.html


喜欢小编的可以点个赞关注小编哦,小编每天都会给大家分享文章。

我自己是一名从事了多年的前端老程序员,小编为大家准备了新出的前端编程学习资料,免费分享给大家!

如果你也想学习前端,可以观看【置顶】文章。也可以私信【1】 领取最新前端练手实战项目

、页面使用CSS的好处:

有效的传递页面信息。

使用CSS美化过的页面文本,使页面漂亮、美观,吸引用户。

可以很好的突出页面的主题内容,使用户第一眼可以看到页面主要内容。

具有良好的用户体验。

2、美化网页的一些基本样式

A:字体样式:

font-family设置字体类型font-family:"隶书";

font-size设置字体大小font-size:12px;

font-style设置字体风格font-style:italic;

font-weight设置字体的粗细font-weight:bold;

font在一个声明中设置所有字体属性font:italic bold 36px "宋体";

举例:

body{font-family: Times,"Times New Roman", "楷体";}

h1{font-size:24px;} 单位->px:像素

h2{font-style:oblique;}

p{font-weight:bold;}

p span{font:oblique bold 12px "楷体";}



B:文本属性:

color设置文本颜色color:#00C;

text-align设置元素水平对齐方式text-align:right;

text-indent设置首行文本的缩进text-indent:20px;

line-height设置文本的行高line-height:25px;

text-decoration设置文本的装饰text-decoration:underline;



C:排版文本段落:

水平对齐方式:text-align:left|right|center|justify;

left把文本排列到左边。默认值:由浏览器决定

right把文本排列到右边

center把文本排列到中间

justify实现两端对齐文本效果

首行缩进:text-indent:em或px

行高:line-height:px

文本修饰:text-decoration:none|underline|overline|line_through

值说明

none默认值,定义的标准文本

underline设置文本的下划线

overline设置文本的上划线

line-through设置文本的删除线


垂直对齐方式:vertical-align属性:middle、top、bottom

文本阴影:text-shadow : color x-offset y-offset blur-radius;


D:背景颜色和背景图片:

background-color:"red";

background-image:url(图片路径);

background-repeat:

沿水平和垂直两个方向平铺

no-repeat:不平铺,即只显示一次

repeat-x:只沿水平方向平铺

repeat-y:只沿垂直方向平铺

background-position:X、Y方向关键词 水平方向的关键词:left、center、right

垂直方向的关键词:top、center、bottom

举例:

.title {

font-size:18px;

font-weight:bold;

color:#FFF;

text-indent:1em;

line-height:35px;

background:#C00 url(../image/arrow-down.gif) 205px 10px no-repeat;

}

线性渐变:linear-gradient ( position, color1, color2,…)


3、举例:

<head>

<title>家用电器</title>

</head>

<link rel="stylesheet" href="jiayongdianqi.css">

<body>

<div class="container">

<h2>家用电器</h2>

<div class="type">

<h6><a href="#">大家电</a></h6>

<ul>

<li> <a href="#">平板电视</a> <a href="#">洗衣机</a> <a href="#">冰箱</a></li>

<li> <a href="#">空调</a> <a href="#">烟机/灶具</a> <a href="#"> 热水器</a></li>

<li> <a href="#">冷柜/酒柜</a> <a href="#">消毒柜</a> <a href="#">家庭影院</a></li>

</ul>

<h6><a href="#">生活电器</a></h6>

<ul>

<li> <a href="#">电风扇</a> <a href="#">净化器</a> <a href="#">吸尘器</a></li>

<li> <a href="#">净水设备</a> <a href="#">挂烫机</a> <a href="#"> 电话机</a></li>

</ul>

<h6><a href="#">厨房电器</a></h6>

<ul>

<li> <a href="#">榨汁机</a> <a href="#">电压力锅</a> <a href="#">电饭煲</a></li>

<li> <a href="#">豆浆机</a> <a href="#">微波炉</a> <a href="#"> 电磁炉</a></li>

</ul>

<h6><a href="#">五金家装</a></h6>

<ul>

<li> <a href="#">淋浴/水槽</a> <a href="#">电动工具</a> <a href="#">手动工具</a></li>

<li> <a href="#">仪器仪表 </a> <a href="#">浴霸/排气 </a> <a href="#"> 灯具</a></li>

</ul>

</div>

</div>

</body>

</html>

li{

/* 去圆点 */

list-style: none;

}

/* 分类页面总宽度 */

.container{

width: 500px;

}


a{

/* 去超链接下划线 */

text-decoration: none;

}

/* 大标题字体 */

.container>h2{

font-size: 18px;

color: white;

font-weight: bolder;

line-height: 50px;

text-indent: 2px;

/*从上到下,0%开始颜色。50%颜色。70%颜色 */

background: linear-gradient(to bottom,#0467ac,#63a7d6,#b6dbf5);

}

css代码:

/* 所有电器分类内容 */

.type{

/* 首行缩进 */

text-indent: 4.5em;

/* 左外边距40px */

margin-left: 40px;

}


/* 电器分类 */

.type>h6{

font-size: 14px;

font-weight: bolder;

line-height: 30px;

background: linear-gradient(to bottom,#e4f1fa,#bddff7,#e4f1fa);

}

/* 电器分类中的A标签 */

.type>h6>a{

color:#0467ac;

}

/* 电器分类中的A标签鼠标悬浮效果 */

.type>h6>a:hover{

text-decoration: underline;

}

/* 分类内容字体 */

.type>ul>li{

font-size: 12px;

line-height: 26px;

}

/* 分类内容字体里面的A标签 */

.type>ul>li>a{

color: #969696;

}


/* 分类内容字体里面的A标签悬浮效果 */

.type>ul>li>a:hover{

color: #804000;

text-decoration: underline;

}

4、效果图链接:file:///D:/ruanjian/VS/wenjianxiangmu/htmlFive/jiayongdianqi.html

廓线(outstyle)

比较常见于表单和链接等 。

outline-style:none; 取消谷歌、360等蓝色边框


:focus 获得焦点的状态, 鼠标的光标就是焦点

.username:focus{ /*获得焦点的状态*/
    border:1px dashed pink;
    background-color:#FFF7FB;
    color:pink;
}

取消表单边框

因为表单在不同浏览器里面, 以后不同的显示方式。

所以, 一般情况下, 我们会把所有的表单都去掉边框。

border: 0 none; 兼容性更好的写法

Label 标签

<label for="txt">搜索一下</label>: <input type="text" id="txt" class="search" value="请输入..." />

这样, 我们点击搜索一下, 光标就跳到了相应id的 input 里面了

完整实例: