CSS实例【十】

终于又到了休息的一天,大小周真的羡慕双休啊~
这一章是CSS对齐和CSS生成内容

<!DOCTYPE html>
<html lang="en">
	<!-- lang是每张页面主要语言声明的属性  en表示英文(详细见ISO语言代码)-->
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
		body{
			margin: 0;
			padding: 0;
			border: #e9cfff solid 0.1875rem;
		}
		.center{
			margin: auto;
			width: 60%;
			border: 3px solid #4CAF50;
			padding: 0.3125rem;
		}
		.left{
			/* position可设置位置对齐 */
			margin: auto;
			position: absolute;
			left: 0rem;
			width: 18.75rem;
			border: 0.1875rem solid #00CC00;
			
			
		}
		.float_right
		{
			/* float可设置左右对齐 */
			float: right;
			width: 18.75rem;
			border: 3px solid #008CBA;
			background-color: #16B8D2;
			
		}
	
		a:after{content: "("attr(href)")";}
		
		/* 事先约定好在哪计数 */
		body{counter-reset:section;}
		h1{counter-reset:subsection;}
		
		h1:before{
			/* 在section这计数 */
			counter-increment: section;
			/* 谁+计的数+. => eg:Section 1.  */
			content: "Section " counter(section) ". ";
			
		}
		h2:before{
			/* 在subsection这计数 */
			counter-increment: subsection;
			/* 计的数.计的数 =>eg:1.1 */
			content: counter(section) "." counter(subsection) " ";
		}
		q:lang(en)
		{
			quotes: "~" "~" "'" "'";
		}
		</style>
	</head>
	<body>
		<h1>一、CSS对齐</h1>
		<h2>1.元素居中对齐: margin: auto;</h2>
		<div class="center">
			<p><b>注意:</b>使用margin:auto无法兼容IE8,除非 !DOCTYPE已经声明</p>
		</div>
		
		<h2>2.左右对齐:position:absolute</h2>
		<div class="left">
			<p>使用position:absolute + left/right:0px来实现左右对齐</p>
		</div>
		<br>
		<br>
		<br>
		<br>
		<h2>3.使用跨浏览器解决方案,设置左右对齐</h2>
		<div class="float_right">
			<p><b>注意:</b>当使用浮动属性对齐,需要包括!DOCTYPE声明,如果不声明IE浏览器会产生奇怪的效果。</p>
		</div>
		<br>
		<br><br>
		
		<h1>二、CSS生成的内容</h1>
		<h2>1.把括号内的url用content属性插入到每个链接后面</h2>
		<p><a href="//www.baidu.com/">百度</a> - 搜索引擎。</p>
		<p><b>注意:</b>仅当 !DOCTYPE已经定义 IE8支持 content属性</p>
		<br>
		<br>
		<h2>2.章节和分节的编号是“第1节”,“1.1”,“1.2”等</h2>
		<br>
		<h1>HTML tutorials</h1>
		<h2>HTML tutorials</h2>
		<h2>XHTML tutorials</h2>
		<h2>CSS tutorials</h2>
		
		<h1>Scripting tutorials</h1>
		<h2>JavaScript</h2>
		<h2>VBScript</h2>
		
		<h1>XML tutorials</h1>
		<h2>XML</h2>
		<h2>XSL</h2>
		<p>因为我前面分章节写代码,所以可能序号有点不整齐了</p>
		
		<h2>3.quotes属性指定了引号</h2>
		<!-- q标签是引用属性 -->
		<p><q>This is a <q>big</q> quote.</q></p>
	</body>
</html>

又是祈求涨粉的一天~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个使用CSS样式设计的实例。这是一个图片墙网页,包含多个图片,鼠标悬停时图片会有放大和变暗的效果。 ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>图片墙</title> <style> body { margin: 0; padding: 0; background-color: #f1f1f1; } .container { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; padding: 20px; } .item { position: relative; margin: 10px; overflow: hidden; border-radius: 5px; box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3); transition: transform 0.5s ease; } .item:hover { transform: scale(1.2); } .item:hover img { opacity: 0.5; } .item img { display: block; width: 100%; height: 100%; transition: opacity 0.5s ease; } .item .title { position: absolute; bottom: 0; left: 0; right: 0; background-color: rgba(0, 0, 0, 0.5); color: #fff; padding: 10px; font-size: 20px; text-align: center; transition: bottom 0.5s ease; } .item:hover .title { bottom: -50px; } </style> </head> <body> <div class="container"> <div class="item"> <img src="https://picsum.photos/400/300" alt=""> <div class="title">图片1</div> </div> <div class="item"> <img src="https://picsum.photos/400/301" alt=""> <div class="title">图片2</div> </div> <div class="item"> <img src="https://picsum.photos/400/302" alt=""> <div class="title">图片3</div> </div> <div class="item"> <img src="https://picsum.photos/400/303" alt=""> <div class="title">图片4</div> </div> <div class="item"> <img src="https://picsum.photos/400/304" alt=""> <div class="title">图片5</div> </div> <div class="item"> <img src="https://picsum.photos/400/305" alt=""> <div class="title">图片6</div> </div> </div> </body> </html> ``` 上述代码中,我们使用了CSS样式来设计一个图片墙网页。首先,我们使用`<div>`标签来创建一个容器,使用`display: flex`来设置容器为弹性布局,使用`flex-wrap: wrap`来设置容器内部元素自动换行。然后,我们使用`<div>`标签来创建多个图片项,使用`position: relative`来设置图片项为相对定位,使用`overflow: hidden`来设置图片溢出部分隐藏,使用`border-radius: 5px`来设置图片项圆角,使用`box-shadow`来设置图片项阴影效果。 在鼠标悬停时,我们使用CSS的`hover`伪类来设置图片和标题的效果。使用`transform: scale(1.2)`来设置图片放大效果,使用`opacity: 0.5`来设置图片变暗效果,使用`transition`来设置过渡效果。使用`bottom: -50px`来设置标题向上移动50像素的效果。 上述代码只是一个简单的图片墙网页示例,你可以根据自己的需要进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值