首页 > 其他分享 >第六章 元素应用css

第六章 元素应用css

时间:2024-10-20 09:47:34浏览次数:3  
标签:color 元素 height width background 第六章 font border css

6.1 使用css设置字体样式


6.1.1.字体类型

h1{				
font-family: fangsong;
}


6.1.2.字体大小

font-size: 25px;


6.1.3.字体粗细

font-weight: 500;


6.1.4.字体倾斜

font-style: italic;

6.2 使用CSS设置文本样式


6.2.1.文本水平对齐方式

text-align: center;


6.2.2.行高

p{
	line-height: 200%;
			}


6.2.3.文本的修饰.

			#id1{
				font-weight: 900;
			}
			#id2{
				font-style: italic;
			}
			#id3{
				text-decoration: underline;
			}
			#id4{
				text-decoration: overline;
			}
			#id5{
				text-decoration: line-through;
			}


6.2.4.段落首行缩进

			.first{
				letter-spacing: 2em;
			}


6.2.5.首字下沉

			.second::first-letter{
				float: left;
				font-size: 2em;
				font-weight: 900;
				
			}


6.2.6.字符间距

			.first{
				letter-spacing: 2em;
			}

6.2.7.文本的截断

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>文本截断的设置</title>
    <style type="text/css">
        h1 {
            font-family: '黑体';
        }
        p {
            font-family: Arial, "Times New Roman";
        }
        .ellipsis {
            width: 260px;
            height: 20px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    </style>
</head>
<body>
    <h1>经营理念</h1>
    <p class="ellipsis">用户是上帝,也是我们的衣食父母,坚持用户利益至上,不断倾听和深解用户需求,不断给用户惊喜,不断提供超预期的体验和服务,不断创造新的用户价值。</p>
</body>
</html>


6.2.8.文本的颜色

			h1{
				color: #ff0000;
			}


6.2.9.文本的背景颜色

			.first{
				background-color: #ff0000;
			}


6.3 使用CSS设置图像样式


6.3.1.设置图像边框

			img{
				border-color: ##ff0000 #00ff00 #0000ff #000000;
				border-width: 10px;
				border-style: dashed solid dotted double;
			}


6.3.2.图像缩放

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>图像缩放的设置</title>
    <style type="text/css">
        #box {
            padding: 10px;
            width: 1000px;
            height: 700px;
            border: 2px dashed #9c3;
        }
        #box img.test1 {
            width: 30%;
            height: 40%;
        }
        #box img.test2 {
            width: 150px;
            height: 280px;
        }
    </style>
</head>
<body>
    <div id="box">
        <img src="img/4.5.4.jpg">
        <img src="img/4.5.4.jpg" class="test1">
        <img src="img/4.5.4.jpg"" class="test2">
    </div>
</body>
</html>


6.3.3.设置背景图像

			body{
				background-color: #f00;
				background-image: url(img/4.5.4.jpg);
			}


6.3.4设置背景重复

1.水平重复
			body{
				background-color: #f00;
				background-image: url(img/th.jpg);
				background-repeat: repeat-x;
			}

2.垂直重复
			body{
				background-color: #f00;
				background-image: url(img/th.jpg);
				background-repeat: repeat-y;
			}

3.重复
			body{
				background-color: #f00;
				background-image: url(img/th.jpg);
				background-repeat: repeat;
			}


6.3.5.背景图像定位


6.3.5.1.使用关键字进行背景定位

< html>
< head>
< meta charset="UTF-8">
< title>背景定位设置</ title>
< style type=" text/ css">
 body{
 background- color:#7bc144;
# box{
 width:400px;
 height:700px;
 border:6px dashed # fff;
 background- image: url( images/ fu. JPG);/
 background- repeat: no- repeat;
 background- position: center bottom;
</ style>
</ head>
< body>
<div id=1'box''></div>
</ body>
</ html>


6.3.5.2.使用长度进行背景定位

# box{
 width:900px;
 height:700px;
 border:6px dashed # fff;
 background- image: url( images/ fu. JPG);
 background- repeat: no- repeat;
 background- position:150px 70px;
}


6.3.5.3.使用百分比进行背景定位

# box{
 width:900px;
 height:700px;
 border:6px dashed # fff;
 background- image: url( images/ fu. JPG);
 background- repeat: no- repeat;
 background- position:100% 50%;
}

6.4 使用css设置表单样式

1.修饰文本域

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.text1{
				border: 1px solid #f60;
				color: #03c;
			}
			.text2{
				border: 1px solid #c3c;
				height: 20px;
				background-color: #fff url(img/password_bg.JPG) left center no-repeat;
				padding-left: 20px;
			}
			.area{
				border: 1px solid #00f;
				overflow: auto;
				width: 99%;
				height: 100px;
			}
		</style>
	</head>
	<body>
		<p>
			<input type="text" name="normal"/>
			默认样式文本域
		</p>
		<p>
			<input name="chbd" type="text" value="输入的文字显示为蓝色" class="text1"/>
			改变边框颜色和文字颜色的文本域,看起来更加形象直观
		</p>
		<p>
			<textarea name="cha" cols="45" rows="5" class="area">改变边框颜色的多行文本域</textarea>
			
		</p>
	</body>
</html>

2.修饰按钮

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>修饰按钮</title>
		<style type="text/css">
			.btn01{
				background: url(img/btn_bg02.jpg); repeat-x:;
				border: 1px solid #f00;
				height: 32px;
				font-weight: bold;
				padding-top: 2px;
				cursor: pointer;
				font-size: 14px;
				color: #fff;
			}
			.btn02{
				background: url(img/btn_bg03.jpg) repeat-x;
				width: 107px;
				height: 37px;
				border: none;
				font-size: 14px;
				font-weight: bold;
				color: #d84700;
				cursor: pointer;
			}
		</style>
	</head>
	<body>
		<p>
		<input name="button" type="submit" value="提交"/>
		默认风格的 提交 按钮
		</p>
		<p>
			<input name="button01" type="submit" class="btn01" id="button01" value="自适应宽度按钮"/>
		</p>
		<p>
			<input name="button02" type="submit" class="btn02" id="button02" value="免费注册"/>
			固定背景图片的按钮
		</p>
	</body>
</html>

3.登录界面

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录表单的制作</title>
    <style type="text/css">
        .login {
            margin: 0 auto;
            width: 280px;
            padding: 14px;
            border: dashed 2px #b7ddf2; /* 2px虚线淡蓝色边框 */
            background: #ebf4fb;
        }
        .login * {
            margin: 0;
            padding: 0;
            font-family: 宋体;
            font-size: 12px;
            line-height: 1.5em;
        }
        .login h2 {
            text-align: center; /* 文字水平居中对齐 */
            font-size: 18px;
            font-weight: bold; /* 字体加粗 */
            margin-bottom: 10px;
            padding-bottom: 5px;
            border-bottom: solid 1px #b7ddf2; /* 下边框为1px实线淡蓝色边框 */
        }
        .login .content {
            padding: 5px; /* 容器内容区域的样式 */
        }
        .login .frm_cont {
            margin-bottom: 8px; /* 内容区域的样式 */
        }
        .login .username input, .login .password input {
            width: 180px;
            height: 18px;
            padding: 2px 0px 2px 18px; /* 文本框左内边距18px,以便为背景图像预留空间 */
            border: solid 1px #aacfe4; /* 1px实线淡蓝色边框 */
        }
        .login .username input {
            background: #fff url(img/username.JPG) no-repeat left center;
        }
        .login .password input {
            background: #fff url(img/lock.JPG) no-repeat left center;
        }
        .login .btns {
            text-align: center; /* 文字水平居中对齐 */
        }
    </style>
</head>
<body>
    <div class="login">
        <h2>用户登录</h2>
        <div class="content">
            <form action="#" method="post">
                <div class="frm_cont username">
                    用户名:
                    <label for="username"></label>
                    <input type="text" name="username" id="username" />
                </div>
                <div class="frm_cont password">
                    密码:
                    <label for="password"></label>
                    <input type="password" name="password" id="password" />
                </div>
                <div class="btns">
                    <input type="submit" name="button1" id="button1" value="登录" />
                    <input type="button" name="button2" id="button2" value="注册" />
                </div>
            </form>
        </div>
    </div>
</body>
</html>

6.5本章案例

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>会员注册</title>
    <link type="text/css" href="CSS/style.css" rel="stylesheet"/>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        body {
            font-size: 12px;
            color: #333;
        }
        ol, ul {
            list-style: none;
        }
        img, a {
            border: 0;
            text-decoration: none;
        }
        a {
            color: #333;
        }
        a:hover {
            color: #f00;
        }
        .loginLogo {
            width: 100%;
            border-bottom: #efefef 1px solid;
        }
        .logoMid {
            width: 1040px;
            margin: 0 auto;
        }
        .loginReg {
            height: 30px;
            line-height: 30px;
            text-align: right;
        }
        .loginReg a {
            color: #7bc144;
        }
        .loginReg a:hover {
            color: #f00;
        }
        .loginBox {
            width: 1050px;
            margin: 30px auto;
            position: relative;
        }
        .regList {
            height: 35px;
            line-height: 35px;
            margin-bottom: 30px;
            position: relative;
        }
        .regList label {
            float: left;
            width: 105px;
            margin-right: 10px;
            text-align: right;
            color: #999;
        }
        .regList input {
            margin: 0;
            padding: 0;
            width: 283px;
            height: 33px;
            border: 1px solid #373840;
            background: #feffdf;
            padding-left: 3px;
        }
        .regList input.yanzheng {
            width: 135px;
        }
        .regList img {
            left: 260px;
            position: absolute;
        }
        .xieyi {
            height: 30px;
            line-height: 30px;
            font-size: 12px;
            padding-left: 115px;
        }
        .xieyi input {
            position: relative;
            top: 2px;
        }
        .xieyi a {
            color: #7BC144;
        }
        .reg {
            padding-left: 115px;
            margin-top: 10px;
        }
        .chengnuo {
            position: absolute;
            right: 0;
            top: 0;
        }
    </style>
</head>
<body>
    <div class="loginLogo">
        <div class="logoMid">
            <h1 class="logo" style="height: 71px; padding-top: 10px;">
                <a href="index.html">
                    <img src="../img/qqhlogo.jpg"/>
                </a>
            </h1>
            <div class="loginBox">
                <img src="../img/chengguo.jpg" width="295" height="393" class="chengnuo" />
                <form action="#.html" method="get" class="reg">
                    <div class="regList">
                        <label><span class="red">*</span>用户名</label>
                        <input type="text" />
                        <span style="color: #999;">请输入邮箱/用户名/手机号</span>
                    </div>
                    <div class="regList">
                        <label><span class="red">*</span>请设置密码</label>
                        <input type="password" />
                    </div>
                    <div class="regList">
                        <label><span class="red">*</span>请确认密码</label>
                        <input type="password" />
                    </div>
                    <div class="regList">
					                        <label><span class="red">*</span>验证码</label>
					                        <input type="text" class="yanzheng" />
					                        <img src="../img/yanzheng.jpg" width="103" height="38" />
					                    </div>
					                    <div class="xieyi">
					                        <input type="checkbox" id="agreement" />
					                        <label for="agreement">我已经阅读并同意</label>
					                        <a href="user-agreement.html">商城用户注册协议</a>
					                    </div>
					                    <div class="reg">
					                        <input type="submit" value="立即注册" />
					                    </div>
					                </form>
					                <div class="clears"></div>
					            </div>
					        </div>
					    </div>
					</body>
					</html>

标签:color,元素,height,width,background,第六章,font,border,css
From: https://blog.csdn.net/2301_80973106/article/details/142934270

相关文章

  • CSS文字超出宽度---换行总结
       <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Document</titl......
  • 帝国网站后台css怎么修改?修改网站后台参数?
    修改帝国网站后台的CSS样式可以通过以下几种方法实现:直接修改源文件:找到帝国CMS安装目录下的后台样式文件,通常位于e/admin/style目录下。使用文本编辑器打开对应的CSS文件(如style.css)进行编辑。修改完成后保存文件,刷新后台页面查看效果。通过自定义CSS文件:在后台模板......
  • 第六章元素应用CSS
    6.1使用CSS设置字体样式作用:一是传递语义功能,二是有美学作用。CSS提供font-family属性来控制文本的字体类型。格式如下:fonl-family:字体名称;参数:字体名称按优先顺序排列,以逗号隔开。如果字体名称包含空格,则应用引号括起。说明:用font-family属性可控制显示字体。不同......
  • HTML·第六章 元素应用CSS
    6.1使用CSS设置字体样式在CSS中设置字体样式是网页设计中非常基础且重要的部分,它可以帮助设计师控制网页上文本的外观。以下是一些常用的CSS属性,用于设置字体样式:font-family:定义字体族,指定文本的字体。可以设置一个或多个字体,浏览器会使用列表中第一个可用的字体。p{......
  • 第六章 课后作业
    1.使用css对页面元素加以修饰制作“旅游攻略”网站<!DOCTYPEhtml><html> <head> <metacharset="utf-8"> <title>旅游攻略</title> <styletype="text/css"> .all{ width:700px; height:600px; border:0px......
  • 第六章 元素应用css
    6.1使用css设置字体样式在学习HTML时,通常也会使用HTML对文本字体进行一些非常简单的样式设置,而使用css对字体样式进行设置远比HTML灵活、精确得多。6.1.1 字体类型字体具有两方面的作用:一是传递语义功能,二是由美学效应。由于不同的字体给人带来不同的风格感受,所以对于网......
  • 第六章元素应用CSS
    6.1使用CSS设置字体样式6.1.1.字体类型font-family属性用于指定元素中文本的字体系列。为了确保跨平台的一致性,通常会列出多个字体名称作为“后备”机制,浏览器会尝试按顺序使用列表中的字体,直到找到一个可用的为止。如果都没有找到,则使用默认字体。字体名如果是多词组成......
  • 前端js html css 基础巩固4
    这是生成了不同的按钮进行显示 每一个按钮对应一个音频 点击按钮会播放对应的音频直接上代码<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0&qu......
  • CSS--固定定位
    固定定位概念固定定位是绝对定位的子类别,一个设置固定定位的元素是相对于视窗固定的,就算页面文档发生了滚动,它也会一直待在相同的地方。固定定位代码添加:position:fixed水平方向:left right垂直方向:top bottom注:1.两个方向各选一个参数即可定位;    2.定......
  • 前端HTML+CSS+JS总结 我的学习笔记
    前端HTMLCSSJS总结一、HTML1.HTML介绍2.基础标签3.图片、音频、视频标签4.超链接标签5.列表标签6.表格标签7.布局标签8.表单标签二、CSS1.CSS概述2.CSS导入方式3.CSS选择器三、JavaScript1.JavaScript简介2.JavaScript引入方式3.JavaScript基础语法书写语法输......