css基础实践

一、css 层叠样式表
样式表的引用方式:
1、行内样式表

2、页面内样式

3、外部样式表

优先级:
行内>页面内>外部样式表
**************************************************、
color:red; //字体颜色:红色

text-align:center; //文本居中 left/center/right/justify 左/中/右/两端对齐
font-weight:bold; //字体加粗 bold/bolder
font-style: italic; //字体倾斜
text-decoration: underline/none; //下划线/去掉下划线

font-size:19px; //字体大小:19像素;
font-family:宋体;

font:19px 宋体; //字体大小 字体;

background:背景颜色 背景图片 背景是否重复 背景定位位置
//背景图片 url(图片路径)
// 是否重复 repeat/no-repeat/repeat-x/repeat-y 重复/不重复/水平重复/垂直重复
//背景定位位置 left/center/right 水平左中右 top/center/bottom 垂直上中下

background-size:精确像素/百分比 /em/rem 背景图片大小控制
background-attachment: scroll; //背景图片固定定位 scroll 滚动 fixed 固定

        width:400px;  宽度
        height:300px;   高度
        border:solid 1px #000;  边框线 :实线  线粗细 线颜色

线型:solid 实线 double 双线 dotted 点状线 dashed 虚线 none无边框线
————————————
border-style 值:

none: 默认无边框
dotted: 定义一个点线框
dashed: 定义一个虚线框
solid: 定义实线边界
double: 定义两个边界。 两个边界的宽度和border-width的值相同
groove: 定义3D沟槽边界。效果取决于边界的颜色值
ridge: 定义3D脊边界。效果取决于边界的颜色值
inset:定义一个3D的嵌入边框。效果取决于边界的颜色值
outset: 定义一个3D突出边框。 效果取决于边界的颜色值
————————————


1、类选择器的定义方式(可以多次调用)
命名:
.name{}
调用:

2、标签选择器的定义方式 (只要符合标签,都自动调用)
命名:
标签名{} // p{}
调用
<标签>

3、ID选择器定义方式 (只能调用一次)
命名:
#name{}

调用:


网面中图片格式:jpg gif png webp


填充:
padding-top
padding-left
padding-right
padding-bottom
简写:
padding:值

padding:a
一个值表示四边相同的填充
padding:a b;
两个值表示上下是a,左右是b
padding:a b c;
三个值表示上是a,左右是b,下是c
padding:a b c d;
四个值表示:上,右,下,左

边距:
margin-top
margin-left
margin-right
margin-bottom
简写:
margin:值

margin:a
一个值表示四边相同的填充
margin:a b;
两个值表示上下是a,左右是b
margin:a b c;
三个值表示上是a,左右是b,下是c
margin:a b c d;
四个值表示:上,右,下,左

*{ //通配符
margin:0;
padding:0;}

行高 ling-height 行间距
一般用行高布局垂直对齐方式
行高和高度一致,内容在垂直正中间
行高比高度大,内容在偏下
行高比高度小,内容偏上

首行缩进
text-indent:2em; 首行缩进两个字符


单位:
px 像素 % 百分比 em rem

颜色
red #ff0000 #f00 rgb(255,0,0)

#000000 黑色 #ffffff / #fff白色 #ff0000 / #f00 红色 #00ff00 /#0f0 绿色 #0000ff / #00f蓝色 #aaa #999 #666 灰色

浮动:

float:left /right 左浮动、右浮动
margin:0 auto;水平居中


文本转换 text-transform:uppercase/lowercase/capitalize
大写、小写、首字母大写
列表:
list-style-type 列表样式
list-style-image 列表图片
list-style

二、第二部分
类选择器
ID选择器
标签选择器

伪类选择器:
超链接四种状态

a:link 访问前的状态
a:hover 鼠标悬停时状态
a:active 鼠标点击时的状态
a:visited 访问后的状态

后代选择器
格式:父元素/祖先元素 子元素
eg : div a / .nav a

行内元素(内联元素) a span input img label select strong b
块级元素 div p h1~h6 table ul ol dl form pre

display:block; 转换为块级元素 (占一行)
display:inline-block; 转换为行内块 (宽高起作用)
display:inline; 转换为行内元素 (占内容位置)

父子选择器

格式:父元素>子元素
eg: .box>a
display:block 显示
display:none 隐藏

visibility: hidden;隐藏
visibility:visible; 显示

display和visibility区别:
display隐藏不占位置
visibility隐藏占位置
盒子模型
布局:
1、浮动流
2、标准流
3、浮动+标准流 = 混合流

三、实践例子
1、例子一
代码:
html部分

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="css/index.css"/>
</head>
<body>
<div id="header">
    <div class="logo fl">
        <a href=""><img src="images/logo.gif" alt=""/></a>
    </div>
    <div class="nav fr">
        <a href="" class="active">首 页</a>
        <a href="">集团概况</a>
        <a href="">新闻中心</a>
        <a href="">产品服务</a>
        <a href="">企业文化</a>
        <a href="">综合业务</a>
        <a href="">品牌建设</a>
        <a href="">人力资源</a>
        <a href="">国际合作</a>
    </div>
</div>
<!--banner区-->
<div id="banner"><img src="images/banner.gif" alt=""/></div>
<!--内容区-->
<div id="content">
    <div class="content-left fl">
        <h3><span>图片</span>新闻</h3>
        <a href="">
            <img src="images/news.jpg" alt=""/>
        </a>
    </div>
    <div class="content-main fl">
        <h3 class="title">集团新闻</h3>
        <ul>
            <li><a href="">
                郑州市委书记连维良视察郑州保利百合项目 <span>2012-11-17</span>
            </a></li>
            <li><a href="">
                中国保利集团副总经理国强一行视察浙江公司 <span>2012-11-16</span>
            </a></li>
            <li><a href="">
                保利集团总经理张振高一行视察辽宁公司 <span>2019-10-20</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>2019-10-20</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>2019-10-20</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>2019-10-20</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>2019-10-20</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>2019-10-20</span>
            </a></li>
        </ul>
    </div>
    <div class="content-right fr">
        <h3 class="title">公司简介</h3>
        <p><img src="images/company_02.jpg" alt="" class="fr"/>保利房地产(集团)股份有限公司是中国保利国保利集团控股的大型产上市公司综合价值第一名,截止2010年底,公司总资产达1514.61亿元,实现销售认购过661.68亿元。61亿元,实现销售认购61亿元,实现销售认购过661.68亿元61亿元,实现销售认购过661.68亿元过661.68亿元61亿元,实现销售认购过661....</p>
    </div>
</div>
<div id="shows">
    <div class="shows-left fl">
        <h3 class="title">项目展示</h3>
        <a href=""><img src="./images/1.jpg" alt=""/></a>
        <a href=""><img src="./images/2.jpg" alt=""/></a>
        <a href=""><img src="./images/3.jpg" alt=""/></a>
        <a href=""><img src="./images/4.gif" alt=""/></a>
    </div>
    <div class="shows-right fr">
        <h3><span>站内</span>搜索</h3>
        <table class="one">
        <tr>
            <td>关键字&nbsp;</td>
            <td><input type="text" style="width:160px"/></td>
        </tr>
        </table>
        <div>
            <a href="">Search</a>
        </div>
    </div>
</div>
<div id="footer">
    <ul>
        <li><br/><p>版权信息@正大软件学院.软件技术系所有</p></li>
        <li><p>2010-2020</p></li>
    </ul>
</div>
</body>
</html>

css部分:

/*公共样式*/
*{
    margin:0;
    padding:0;
   /* box-sizing: border-box;*/
}

.fl{
    float:left;
}
.fr{
    float:right;
}
a{
    text-decoration: none;
}
li{
    list-style: none;
}
body{
    font-size: 12px;
    background: url("../images/body.gif");
}
/*首页样式*/
#header,#banner,#shows,#footer{
    width:960px;
    margin:auto;
}
#content{
    width:950px;
    margin:auto;
}
#header{
    height:54px;
    background: #ffffff;
}
#header .logo{
    width:230px;
    height:54px;
}
#header .nav{
    height:40px;
    border-top:solid 5px black;
    margin-top: 9px;
    width:730px;
    line-height: 40px;
}
.nav>a{
    color:#000;
    font-size: 14px;
    padding:0 13px;
    display: inline-block;
    height:40px;
    float:left;
}
.nav>a:hover,.active{
    background: #900;
    color:#fff !important;
}
/*内容区*/
#content{
    height:237px;
    padding:0 5px;
    background: #ffffff;
}
.content-left{
    width:300px;

}
.content-main{
    width:330px;
    margin:0 10px;

}
.content-right{
    width:300px;

}
#content h3{
    font-size: 14px;
    height:30px;
    line-height: 30px;
    padding-left:1.1em;
}
#content h3 span{
    color: #df0000;
}
.content-left img{
    width:288px;
    border:solid 1px #ddd;
    padding:5px;
    border-radius: 5px;
    background: #f5f5f5;
}
.title{
    border-bottom:solid 1px #df0000;
    background:url(../images/ico5.gif) no-repeat left center;
}
.content-main ul li{
    height:25px;
    line-height: 25px;
    border-bottom:dashed 1px #ddd;
    background: url(../images/ico1.gif) no-repeat left center;
    padding-left: 10px;
}
.content-main ul li span{
    float:right;
}
.content-main ul li a{
    color:#666;
}
.content-right img{
    height:200px;
}
.content-right p{
    text-indent: 2em;
    line-height: 17px;
}
#shows{
    height:208px;
    background: #ffffff;
    padding-bottom:10px;
}
#shows div{
    margin-left:10px;
}
#shows h3{
    font-size: 14px;
    height:30px;
    line-height: 30px;
    padding-left:1.1em;
}
.shows-left{
    width:650px;
}
.shows-left a{
    margin:3px 2px;
}
.shows-left img{
    width:154px;
    margin-top:5px;
}
.shows-right{
    width:230px;
    height:135px;
    border:solid 2px #dadada;
    border-radius: 5px;
    margin-right:25px;
    margin-top:30px;
    background: #f4f3f3;
}
#shows h3 span{
    color: #df0000;
}
#shows h3{
    border-bottom:solid 2px #dadada;
}
#shows tr{
    color:#f00;
}
.one{
    margin:10px;
}
.shows-right div{
    width:55px;
    height:20px;
    color:#fff;
    background: #c41402;
    border:solid 1px #b70d07;
    border-radius: 5px;
    margin-left:86px !important;


}
.shows-right div a{
    color:#fff;
    font-size:16px;
    line-height: 16px;
    margin:2px;
}
#footer{
    height:70px;
    background: #b2a796;
}
#footer ul li p{
    display:block;
    font-size:12px;
    line-height:24px;
    text-align: center;
}

2、例子二
html部分:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="css/index.css"/>
</head>
<body>
<div id="header">
    <div class="logo fl">
        <a href=""><img src="images/logo.gif" alt=""/></a>
    </div>
    <div class="nav fr">
        <a href="">首 页</a>
        <a href="">集团概况</a>
        <a href="" class="active">新闻中心</a>
        <a href="">产品服务</a>
        <a href="">企业文化</a>
        <a href="">综合业务</a>
        <a href="">品牌建设</a>
        <a href="">人力资源</a>
        <a href="">国际合作</a>
    </div>
</div>
<!--banner区-->
<div id="banner"><img src="images/zbanner.gif" alt=""/></div>
<div id="content">
    <div class="one fl"></div>
    <div class="fl">
    <p>您目前的位置 :<a href="">首页</a>>><a href="">新闻中心</a></p>
    </div>
    <div class="two fr">
        <table>
        <tr>
            <td><p>站内搜索:<input type="text" style="width:100px"/></p></td>
            <td><img src="./images/001.jpg" alt=""/></td>
        </tr>
        </table>
    </div>
</div>
<div id="shows">
    <div class="shows-left fl">
        <div>
            <p>&nbsp;&nbsp;&nbsp;&nbsp;>新闻中心</p>
            <ul>
                <li> o 集团要闻</li>
                <li> o 经营动态</li>
                <li> o 企业专题</li>
                <li> o 项目新闻</li>
            </ul>
        </div>
    </div>
    <div class="shows-right fr">
        <div>
        <h3>集团要闻 <span>Group News</span></h3>
        <ul>
            <li><a href="">
                郑州市委书记连维良视察郑州保利百合项目 <span>[2012-11-17]</span>
            </a></li>
            <li><a href="">
                中国保利集团副总经理国强一行视察浙江公司 <span>[2012-11-16]</span>
            </a></li>
            <li><a href="">
                保利集团总经理张振高一行视察辽宁公司 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
            <li><a href="">
                中国保利集团副经理视查工作 <span>[2019-10-20]</span>
            </a></li>
        </ul>
            <p>共 <span>10</span>页<span>196</span>条记录
                <a href="">上一页</a>
                <a href="">1</a>
                <a href="">2</a>
                <a href="">3</a>
                <a href="">4</a>
                <a href="">5</a>
                <a href="">下一页</a>
            </p>
        </div>
    </div>
</div>
<div id="footer">
    <ul>
        <li><br/><p>版权信息@正大软件学院.软件技术系所有</p></li>
        <li><p>2010-2020</p></li>
    </ul>
</div>

</body>
</html>

css部分:

/*公共样式*/
*{
    margin:0;
    padding:0;
    /* box-sizing: border-box;*/
}

.fl{
    float:left;
}
.fr{
    float:right;
}
a{
    text-decoration: none;
    color:#000;
}
li{
    list-style: none;
}
body{
    font-size: 12px;
    background: url("../images/body.gif");
}
/*首页样式*/
#header,#banner,#content,#shows,#footer{
    width:960px;
    margin:auto;
}
#header{
    height:54px;
    background: #ffffff;
}
#header .logo{
    width:230px;
    height:54px;
}
#header .nav{
    height:40px;
    border-top:solid 5px black;
    margin-top: 9px;
    width:730px;
    line-height: 40px;
}
.nav>a{
    color:#000;
    font-size: 14px;
    padding:0 13px;
    display: inline-block;
    height:40px;
    float:left;
}
.nav>a:hover,.active{
    background: #900;
    color:#fff !important;
}
#content{
    height:50px;
    margin-top:-4px;
    background: #dedede;
}
.one{
    width:4px;
    height:4px;
    margin:23px 5px;
    border:solid 1px #000;
}
#content p{
    font-size: 12px;
    line-height: 50px;
}

.two{
    margin-right:40px;
}
#content div tr td p{
    color:#f00;
    font-size: 14px;
    font-weight:bold;
    line-height: 50px;
}
#content div tr td img{
    height: 25px;
}
#shows{
    height:600px;
    background: #ffffff;
}
.shows-left{
    width:300px;
    display:inline-block;
}
.shows-right{
    width:660px;
}
.shows-left div{
    width:208px;
    margin:0 30px;
    padding-top:20px;
}
.shows-left div p{
    color: #ffffff;
    font-size: 14px;
    line-height: 30px;
    background:url("../images/listhead.gif") no-repeat top left;
}
.shows-left div ul{
    width:200px;
    margin:0 5px;
    padding-top:20px;
    padding-bottom:30px;
    background: #f9f9f9 url("../images/listfoot.gif") no-repeat bottom center;
}

.shows-left div ul li{
    font-size: 12px;
    line-height: 26px;
    margin:0 10px;
    border-bottom:dashed 1px #cccccc;
}
.shows-right{
    width:630px;
    display:inline-block;
}
.shows-right div{
    margin-top: 20px;
    margin-right:45px;
}
.shows-right div h3{
    font-size: 14px;
    line-height: 28px;
    border-bottom: solid 1px #c1c1c1;
    background:url("../images/listmiddle.gif") no-repeat bottom left;

}
.shows-right div h3 span{
    font-size: 8px;
    color: #9b9b9b;
}
.shows-right div ul{
    font-size: 12px;
    line-height: 24px;
}
.shows-right div ul li{
    border-bottom:dashed 1px #9d9d9d;
}
.shows-right div ul span{
    float:right;
}
.shows-right div p span{
    color:#f00;
    font-size: 12px;
    line-height: 24px;
}
#footer{
    height:70px;
    background: #b2a796;
}
#footer ul li p{
    display:block;
    font-size:12px;
    line-height:24px;
    text-align: center;
}

3、例子三
html部分:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="css/index.css"/>
</head>
<body>
<div id="header">
    <div class="logo fl">
        <a href=""><img src="images/logo.gif" alt=""/></a>
    </div>
    <div class="nav fr">
        <a href="">首 页</a>
        <a href="">集团概况</a>
        <a href="" class="active">新闻中心</a>
        <a href="">产品服务</a>
        <a href="">企业文化</a>
        <a href="">综合业务</a>
        <a href="">品牌建设</a>
        <a href="">人力资源</a>
        <a href="">国际合作</a>
    </div>
</div>
<!--banner区-->
<div id="banner"><img src="images/zbanner.gif" alt=""/></div>
<div id="content">
    <div class="one fl"></div>
    <div class="fl">
        <p>您目前的位置 :<a href="">首页</a>>><a href="">新闻中心</a>>><a href="">集团要闻</a></p>
    </div>
</div>
<div id="shows">
    <div>
    <h3>中国保利集团副总经理国强一行视察青岛公司</h3>
        <p class="three">Date:2011-12-12 View:188</p>
        <div class="two">
            <p>2011年12月2日,中国保利集团副总经理国强一行莅临青岛,在保利地产青岛公司总经理邢巍等的陪同下,对保利海上罗兰和保利里院里等项目进行了深入视察。</p>
            <p>在视察过程中,国强总对保利嗨上罗兰等项目的整体规划产品设计、工程施工和示范区展示给予高度评价,并对香岛公司在今年严市场形势下得的好业绩表示肯定;围强总强调,面对严啖的市场环境,公司在运作过程中更要坚持以“品、品质、品位”三品为一体,以高品质、高性价比的产品水平的服务得市场,并秉承保利地产一的精品开发路钱,不断提高公司的核心竞争力,最后,国强总希望青岛公司在临近年底时,加快资金回笼,圆满完成公司各项任务指标。
            </p>
            <div class="four">
            <img src="./images/002.jpg" alt=""/>
            </div>
        </div>
    </div>
</div>
<div id="footer">
    <ul>
        <li><br/><p>版权信息@正大软件学院.软件技术系所有</p></li>
        <li><p>2010-2020</p></li>
    </ul>
</div>
</body>
</html>

css部分:

/*公共样式*/
*{
    margin:0;
    padding:0;
    /* box-sizing: border-box;*/
}

.fl{
    float:left;
}
.fr{
    float:right;
}
a{
    text-decoration: none;
    color:#000;
}
li{
    list-style: none;
}
body{
    font-size: 12px;
    background: url("../images/body.gif");
}
/*首页样式*/
#header,#banner,#content,#shows,#footer{
    width:960px;
    margin:auto;
}
#header{
    height:54px;
    background: #ffffff;
}
#header .logo{
    width:230px;
    height:54px;
}
#header .nav{
    height:40px;
    border-top:solid 5px black;
    margin-top: 9px;
    width:730px;
    line-height: 40px;
}
.nav>a{
    color:#000;
    font-size: 14px;
    padding:0 13px;
    display: inline-block;
    height:40px;
    float:left;
}
.nav>a:hover,.active{
    background: #900;
    color:#fff !important;
}
#content{
    height:50px;
    margin-top:-4px;
    background: #dedede;
}
.one{
    width:4px;
    height:4px;
    margin:23px 5px;
    border:solid 1px #000;
}
#content p{
    font-size: 12px;
    line-height: 50px;
}
#shows{
    height:650px;
    background: #ffffff;
}
#shows div{
    margin:0 50px;
}
#shows div h3{
    text-align: center;
    line-height: 50px;
    border-bottom:dashed 1px #cccccc;
}
.three{
    color:#666;
    font-size: 10px;
    float:right;
}
.two p{
    font-size: 12px;
    line-height: 24px;
    text-indent: 2em;
    margin:20px 0;
}
.four{
    width:500px;
    height:370px;
    margin:0 auto !important;
}
.four img{
    width:500px;
    height:375px;
}
#footer{
    height:70px;
    background: #b2a796;
}
#footer ul li p{
    display:block;
    font-size:12px;
    line-height:24px;
    text-align: center;
}

总结:css中的样式比较多,需要加深记忆,多用多练习就会慢慢熟练起来。

发布了29 篇原创文章 · 获赞 1 · 访问量 585

猜你喜欢

转载自blog.csdn.net/Always_Love/article/details/102708453