Quantcast
Channel: w3cplus
Viewing all 1557 articles
Browse latest View live

jQuery制作Facebook Timeline

$
0
0

不知道大家有没有经常观注Facebook,不过我是经常观注他,时时了解他的Web页面的设计与变化,因为我很喜欢他的风格。最近看到Facebook的一个比较明显的变化——Facebook Timeline

Facebook Timeline design

这一变化把我吸引了,仔细看了他们的源代码,但不懂js的我来说,实现风格并不难,但是要实现功能还是相当的困难。没办法的情况之下只好借助GG在网上搜索“Facebook Timeline design”。终于找到一篇Srinivas Tamada写的《Facebook Timeline Design using JQuery and CSS.》教程。于是马上自己跟着动手写了一个,觉得很有意思,并不是想像中的那么难,稍加整理一翻,贴上来与大家一起分享。

从上图中可以看到“Facebook Timeline”效果是一个以时间为主线,主线左右两边有很多个block,并且在主线上点击会弹出一个文本输入,让你添加内容,从而显示到页面上。请看下面的示意思图:

facebook timeline design

大概了解了“Facebook Timeline”是什么东东后,我们就一起跟着Srinivas Tamada写的《Facebook Timeline Design using JQuery and CSS.》教程一起来学习如何制作自己的“timeline”效果。

需要的资源

制作这个效果我们首先需要准备两样东西,第一个是jQuery版本库,另外一个就是制作瀑布流效果的插件jQuery Masonry plugin。有了这两样东东后,就可以进入后面的制作。

HTML Markup

第一步先创建一个容器div,这里把称为“div#container”,同时这个容器是可以放置多个div元素,并且此处给其一个类名“item”,另外在每个“div.item”放置一个“div.inner”:

		<div id="container">
		  <div class="item">
		    <div class="inner">Block Content</div>
		  </div>
		  [...]
		  <div class="item">
		    <div class="inner">Block Content</div>
		  </div>
		</div>
	

注:这只是最初步的HTML结构,随着后面的内容介绍,我们所需的结构会有一定的变化。请仔细留意。

先给这个Markup一个基本样式:

		*{
			margin: 0;
			padding: 0;
		}
		ul,
		ol {
			list-style: none outside none;
		}
		#container {
			width: 860px;
			margin: 0 auto;
		}
		.item {
			width: 408px;
			margin: 20px 10px 10px;
			float: left;
			background-color: #fff;
			border: 1px solid #b4bbcd;
			min-height: 50px;
			text-align: justify;
			word-wrap: break-word;
		}
		.inner {
			padding: 10px;
		}
	

经过上面的样式设置后,Block进行float后,如下图所示的效果:

facebook timeline design

很显然,上面的效果并不是我们期待的效果,块与块之间的距离太大了,那么我们需要怎样来处理呢?想要答案吗?请看第二步。

第二步:消除块与块之间的距离

前面一步,我们有一个很不理想的效果,就是块与块之间的距离太大了,那么这一步,我们就来看是如何让块与块之间的效果都是一致的。答案很简单,使用jquery和Masonry插件实现。这也就是前面为什么说需要准备jQuery版本库jQuery Masonry plugin的原因(有关于jQuery Masonry plugin的详细介绍请点击这里)。下面别的不多说,请看如何调用:

调用库和插件

		<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
		<script type="text/javascript" src="js/jquery.masonry.js"></script>
	

启用Masonry插件

		<script type="text/javascript" >
		$(function(){
		  // masonry plugin call
		  $('#container').masonry({itemSelector : '.item',});
		});
		</script>
	

下面一起来看看运用了jQuery Masonry plugin后的效果:

facebook timeline design

第三步:制作timeline导航

上面完成了区块的效果设置,接下来这一步主要是制作Timeline导航的效果,在这里在“div#container”容器中添加一些需要使用的HTML标签用来制作“timeline”导航:

HTML Markup

		<div id="container">
		
		  <!-- TimeLine导航 -->
		  <div class="timeline_container">
		    <div class="timeline">
		      <div class="plus"></div>
		    </div>
		  </div>
		
		  <div class="item">
		    <div class="inner">Block Content</div>
		  </div>
		  [...]
		  <div class="item">
		    <div class="inner">Block Content</div>
		  </div>
		</div>
	

结构添加完成后,我们需要对其样式进行设置

CSS Code

		/*timeline navigatior css*/
		.timeline_container {
			width: 16px;
			text-align: center;
			margin: 0 auto;
			cursor: pointer;
			display: block;
		}
		.timeline{
			margin: 0 auto;
			background-color: #e08989;
			display: block;
			float: left;
			height: 100%;
			left: 428px;
			margin-top: 10px;
			position: absolute;
			width: 4px;
		}
		.timeline:hover{
			cursor: pointer;
			margin: 0 auto;
		}
		.timeline div.plus{
			width: 14px;
			height: 14px;
			position:relative;
			left: -6px;
		}
	

接下来使用jQuery来改为“div.plus”的背景图片:

jQuery Code

			//timeline_container add mousemove event
			$(".timeline_container").mousemove(function(e){
			    var topdiv = $("#containertop").height();
			    var page = e.pageY - topdiv - 26;
			    $(".plus").css({
				      "top": page + "px",
				      "background":"url('images/plus.png')",
				      "margin-left": "1px"
			    });
			}).mouseout(function(){
			    $(".plus").css({
				      "background":"url('')"
			    });
			});			
	

完成后的效果就变成下图所示的风格:

facebook timeline design

第四步:给item块加上箭头效果

这一步主要实现的效果是,给每个“div.item”的块加上箭头效果,如果“div.item”的在左边加上“向右箭头”,反之加上“向左箭头”。

jQuery Code

			//injecting arrow points
			function Arrow_Points(){
			  var s = $("#container").find(".item");
			  $.each(s,function(i,obj){
			    var posLeft = $(obj).css("left");
			    if(posLeft == "0px"){
			      html = "<span class='rightCorner'></span>";
			      $(obj).prepend(html);
			    } else {
			      html = "<span class='leftCorner'></span>";
			      $(obj).prepend(html);
			    }
			  });
			}
			Arrow_Points();
	

接下来给这两个箭头写上相应的样式效果:

CSS Code

		/*arrow css style*/
		.rightCorner {
			background-image: url("images/right.png");
			display: block;
			height: 15px;
			margin-left: 408px;
			margin-top: 8px;
			padding: 0;
			vertical-align: top;
			width: 13px;
			z-index: 2;
			position: absolute;
		}
		.leftCorner {
			background-image:url("images/left.png");
			display: block;
			height: 15px;
			width: 13px;
			margin-left: -13px;
			margin-top: 8px;
			position: absolute;
			z-index: 2;
		}
	

完成后的效果

facebook timeline design

第五步:给item块增加删除按钮

这一步,给每个“div.item”添加一个“删除”按钮,当你点击这个“删除”按钮时,被点击块将隐藏,而整个布局重新更样布局。

HTML Markup

		<div id="container">
		
		  <!-- TimeLine导航 -->
		  <div class="timeline_container">
		    <div class="timeline">
		      <div class="plus"></div>
		    </div>
		  </div>
		
		  <div class="item">
		    <a href='#' class='deletebox'>X</a>
		    <div class="inner">Block Content</div>
		  </div>
		  [...]
		  <div class="item">
		    <a href='#' class='deletebox'>X</a>
		    <div class="inner">Block Content</div>
		  </div>
		</div>
	

CSS Code

		/*deletebox style */
		.deletebox {
			color: #CC0000;
			float: right;
			font-weight: bold;
			margin: 8px 10px;
			text-decoration: none;
		}
	

下面的jQuery代码给“.deletebox”按钮一个“click”事件,当你点击这个按钮时,主要完成以下事情:当前“item”块移除掉,并且剩下的块重新通过“Masonry”进行排列,具体看代码:

jQuery Code

			//delete item box
			$(".deletebox").live("click",function(){
			  if(confirm("Are you sure?")){
			    $(this).parent().fadeOut("slow");
			    //remove item block
			    $("#container").masonry("remove",$(this).parent());
			    //remove masonry plugin
			    $("#container").masonry("reload");
			    //Hiding existing arrows
			    $(".rightCorner").hide();
			    $(".leftCorner").hide();
			    //injecting fresh arrow
			    Arrow_Points();
			  }
			  return false;
			});			
	

第六步:弹出窗的制作

最后一步,需要制作一个弹出窗效果,制作这个效果,需要先给他加上一些HTML标签。

HTML Markup

		<div id="container">
		
		  <!-- TimeLine导航 -->
		  <div class="timeline_container">
		    <div class="timeline">
		      <div class="plus"></div>
		    </div>
		  </div>
		
		  <div class="item">
		    <a href='#' class='deletebox'>X</a>
		    <div class="inner">Block Content</div>
		  </div>
		  [...]
		  <div class="item">
		    <a href='#' class='deletebox'>X</a>
		    <div class="inner">Block Content</div>
		  </div>
		
		  <div id="popup" class="shade">
		    <div class="Popup_rightCorner"></div>
		    <div class="inner">
		      <h3>What's Up?</h3>
		      <div class="clearfix"><textarea name="" id="update"></textarea></div>
		      <div class="clearfix"><input type="submit" id="update_button" value="Update"/></div>
		    </div>
		  </div>
		
		</div>
	

修改完成后,给“弹出窗”写个简单的样式:

CSS Code

		/*popup*/
		#popup {
			display: block;
			width: 408px;
			float: left;
			background-color: #fff;
			border: 1px solid #a9b6d2;
			min-height: 60px;
			display: none;
			position: absolute;
			margin: 10px;
		}
		#update {
			width: 100%;
			resize: none;
			min-height: 50px;
		}
		#update_button {
			background-color: #CC0000;
			border: 1px solid #333333;
			color: white;
			cursor: pointer;
			font-weight: bold;
			margin-top: 5px;
			padding: 5px;
		}
	

最后一上就是让这个“弹出窗”如何工作

jQuery Code

			//Timeline navigator on click action
			$(".timeline_container").click(function(e){
			  var topdiv = $("#containertop").height();
			  //Current Postion
			  $("#popup").css({
			    "top": (e.pageY - topdiv - 33) + "px"
			  });
			  $("#popup").fadeIn();//Popup block show
			  //textbox focus
			  $("#update").focus();
			});
			
			//Mouseover no action
			$("#popup").mouseup(function(){
			  return false;
			});
			
			//outside action of the popup block
			$(document).mouseup(function(){
			  $("#popup").hide();
			});
			
			//update button action
			$("#update_button").live("click",function(){
			  //textbox value
			  var x = $("#update").val();				
			  //ajax part
			  $("#container").prepend('<div class="item"><a href="#" class="deletebox">X</a>' + '<div class="inner">' + x + '</div></div>');
			  //reload masnory
			  $("#container").masonry("reload");
			  //Hiding existing arrows
			  $(".rightCorner").hide();
			  $(".leftCorner").hide();
			  //injecting fresh arrows
			  Arrow_Points();
			  //clear popup text box value
			  $("#update").val("");
			  //popup hide
			  $("#popup").hide();
			  return false;
			});
	

最终效果就如下面的草图所示:

facebook timeline design

完成第六步后,类似于Facebook Timeline的效果就算是做出来了,最后我把相关代码列出来:

HTML Markup

		<div id="container">
		
		  <!-- TimeLine导航 -->
		  <div class="timeline_container">
		    <div class="timeline">
		      <div class="plus"></div>
		    </div>
		  </div>
		
		  <div class="item">
		    <a href='#' class='deletebox'>X</a>
		    <div class="inner">Block Content</div>
		  </div>
		  [...]
		  <div class="item">
		    <a href='#' class='deletebox'>X</a>
		    <div class="inner">Block Content</div>
		  </div>
		
		  <div id="popup" class="shade">
		    <div class="Popup_rightCorner"></div>
		    <div class="inner">
		      <h3>What's Up?</h3>
		      <div class="clearfix"><textarea name="" id="update"></textarea></div>
		      <div class="clearfix"><input type="submit" id="update_button" value="Update"/></div>
		    </div>
		  </div>
		
		</div>
	

CSS Code

		*{
			margin: 0;
			padding: 0;
		}
		ul,
		ol {
			list-style: none outside none;
		}
		#container {
			width: 860px;
			margin: 0 auto;
		}
		.item {
			width: 408px;
			margin: 20px 10px 10px;
			float: left;
			background-color: #fff;
			border: 1px solid #b4bbcd;
			min-height: 50px;
			text-align: justify;
			word-wrap: break-word;
		}
		.inner {
			padding: 10px;
		}
		/*timeline navigatior css*/
		.timeline_container {
			width: 16px;
			text-align: center;
			margin: 0 auto;
			cursor: pointer;
			display: block;
		}
		.timeline{
			margin: 0 auto;
			background-color: #e08989;
			display: block;
			float: left;
			height: 100%;
			left: 428px;
			margin-top: 10px;
			position: absolute;
			width: 4px;
		}
		.timeline:hover{
			cursor: pointer;
			margin: 0 auto;
		}
		.timeline div.plus{
			width: 14px;
			height: 14px;
			position:relative;
			left: -6px;
		}
		/*arrow css style*/
		.rightCorner {
			background-image: url("images/right.png");
			display: block;
			height: 15px;
			margin-left: 408px;
			margin-top: 8px;
			padding: 0;
			vertical-align: top;
			width: 13px;
			z-index: 2;
			position: absolute;
		}
		.leftCorner {
			background-image:url("images/left.png");
			display: block;
			height: 15px;
			width: 13px;
			margin-left: -13px;
			margin-top: 8px;
			position: absolute;
			z-index: 2;
		}
		/*deletebox style */
		.deletebox {
			color: #CC0000;
			float: right;
			font-weight: bold;
			margin: 8px 10px;
			text-decoration: none;
		}
		/*popup*/
		#popup {
			display: block;
			width: 408px;
			float: left;
			background-color: #fff;
			border: 1px solid #a9b6d2;
			min-height: 60px;
			display: none;
			position: absolute;
			margin: 10px;
		}
		#update {
			width: 100%;
			resize: none;
			min-height: 50px;
		}
		#update_button {
			background-color: #CC0000;
			border: 1px solid #333333;
			color: white;
			cursor: pointer;
			font-weight: bold;
			margin-top: 5px;
			padding: 5px;
		}
	

jQuery Code

		<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
		<script type="text/javascript" src="js/jquery.masonry.js"></script>
		<script type="text/javascript">
			$(function(){
				//masonry plugin call
				$("#container").masonry({
					itemSelector:".item",
				});
				
				//timeline_container add mousemove event
				$(".timeline_container").mousemove(function(e){
					var topdiv = $("#containertop").height();
					var page = e.pageY - topdiv - 26;
					$(".plus").css({
						"top": page + "px",
						"background":"url('images/plus.png')",
						"margin-left": "1px"
					});
				}).mouseout(function(){
					$(".plus").css({
						"background":"url('')"
					});
				});
				
				//injecting arrow points
				function Arrow_Points(){
					var s = $("#container").find(".item");
					$.each(s,function(i,obj){
						var posLeft = $(obj).css("left");
						if(posLeft == "0px"){
							html = "<span class='rightCorner'></span>";
							$(obj).prepend(html);
						} else {
							html = "<span class='leftCorner'></span>";
							$(obj).prepend(html);
						}
					});
				}
				Arrow_Points();
				
				//delete item box
				$(".deletebox").live("click",function(){
					if(confirm("Are you sure?")){
						$(this).parent().fadeOut("slow");
						//remove item block
						$("#container").masonry("remove",$(this).parent());
						//remove masonry plugin
						$("#container").masonry("reload");
						//Hiding existing arrows
						$(".rightCorner").hide();
						$(".leftCorner").hide();
						//injecting fresh arrow
						Arrow_Points();
					}
					return false;
				});
				
				//Timeline navigator on click action
				$(".timeline_container").click(function(e){
					var topdiv = $("#containertop").height();
					//Current Postion
					$("#popup").css({
						"top": (e.pageY - topdiv - 33) + "px"
					});
					$("#popup").fadeIn();//Popup block show
					//textbox focus
					$("#update").focus();
				});
				
				//Mouseover no action
				$("#popup").mouseup(function(){
					return false;
				});
				
				//outside action of the popup block
				$(document).mouseup(function(){
					$("#popup").hide();
				});
				
				//update button action
				$("#update_button").live("click",function(){
					//textbox value
					var x = $("#update").val();				
					//ajax part
					$("#container").prepend('<div class="item"><a href="#" class="deletebox">X</a>' + '<div class="inner">' + x + '</div></div>');
					//reload masnory
					$("#container").masonry("reload");
					//Hiding existing arrows
					$(".rightCorner").hide();
					$(".leftCorner").hide();
					//injecting fresh arrows
					Arrow_Points();
					//clear popup text box value
					$("#update").val("");
					//popup hide
					$("#popup").hide();
					return false;
				});
			});
		</script>
	

类似“Facebook Timeline”的效果所需代码都在上面了,如果你想看看真实效果,你可以看看Srinivas Tamada写的一个DEMO效果。不过我建议大家还是动手一试好点,这样才能体会到。当然如果你不想自己动手,也可以点击这里进行下载。

那么有关于“Facebook Timeline”的介绍到这就算是全部完成了,希望大家能喜欢,如果您有更好的制作方法,记得与我分享。或者你对上面有任何问题可以直接在下面的评论中留言。

最后在结束此文时,让我们再一次感谢Srinivas Tamada给我们带来这么详细的教程——《Facebook Timeline Design using JQuery and CSS.

如需转载烦请注明出处:W3CPLUS


CSS制作Facebook的媒体对象

$
0
0

前面在《OOCSS——核心篇》一文中有简单的提到Facebook的媒体对象(有的地方称作为“信息状态块”)的制作。那么今天老话重谈,主要使用不同的几种结构来制作这个媒体对象效果:

我们把上图拆分细化一下,可以划成下图的样子:

根据上图我们就可以轻松的写出需要的HTML结构。

HTML Markup:

		<div class="stbody">
		  <div class="stimg">img part</div>
		  <div class="sttext">text part</div>
		</div>
	

有了结构,我们就可以来分析样式的写法

CSS Code

		.stbody {
			min-height: 70px;
			margin-bottom: 10px;
			border-bottom: 1px dashed #c00;
		}
		.stimg {
			float: left;
			height: 50px;
			width: 50px;
			border: 1px solid #dedede;
			padding: 5px;
		}
		.sttext {
			overflow: hidden;
			min-width: 50px;
			word-wrap: break-word;
			padding: 5px;
		}
	

注:如果你的图片是带有链接的,那么可以将div换成a标签。

上面代码呈现的效果如下所示:

当然“div.sttext”里面的元素可以根据自己的要求来写。还有一种情况,我们有时图片在右边怎么办?其实答案不用我说,大家都知道。我这里介绍的方法就是在“div.stimg”标签中加上一个类名“stimgR”,然后并在其身上运用样式:

		.stimg.stimgR {
			float: right;
		}
	

那么此时效果就出来了:

此处有一个关键之处,如何让“sttext”中的内容不围绕在图片的周围,有关于解决这种现象有几种方法:

1、方法一:

		.sttext {
			oveflow: hidden;
			zoom:1
		}
	

2、方法二

		.sttext {
			display: table;
			zoom:1
		}
	

3、方法三

		.sttext {
			display: table-cell;
			zoom:1
		}
	

有关于这个的详细介绍大家可以参考《如何解决浮动元素周围环绕文字》一文。

为了让你的样式更具完美,在“.sttext”中还要让文本能自动换行:

		.sttext {
			word-wrap: break-word;
		}
	

有关于文本换行的详细介绍大家不仿参考《CSS3 Word-wrap》一文的介绍。

那么这样一个完美的媒体块的制作就算是完美了。

上面只是一种制作方法,接下来我们在来看另外一种:

HTML Markup

		<div class="sttbody">
		  <a href="aboutme.html" class="sttimg">
		    <img src="myimage.png" alt="img" />
		  </a>
		  <div class="sttext">
		    Something about me
		  </div>
		</div>
	

CSS Code

		.sttbody {margin: 10px;}
		.sttext {display: table-cell;zoom:1;}
		.sttext > :first-child{margin-top:0;}/*你也可以在这个标签中加上一个类名.nmT {margin-top:0;}*/
		.sttext > :last-child{margin-bottom:0;}/*在这个标签上加上一个类名.nmB {margin-bottom:0}*/
		.sttimg {float:left;margin-right:10px;}/*这两个属性完全可以用类名来代替:.fl{float:left} .mrm {margin-right: 10px}*/
		.sttimg img {display: block;}
		.sttimgR {float:right;margin-left: 10px;}/*这两个属性完全可以用类名来代替:.fr{float:right} .mlm {margin-left: 10px}*/
	

上面这种方法采用的是模块化思路,当你一个项目多处出现这样的样式风格,我们都可以采用这个模板来制作。前面在《OOCSS——核心篇》一文中专门介绍了这一个东东。

上面是单一的,如果你有多个这样的循环效果,上面的效果也可以帮您完成,不过我更建议使用列表的形式来制作。

HTML Markup

		<ul>
		  <li class="stbody>
		    <div class="stimg"></div>
		    <div class="sttext"></div>
		  </li>
		  [...]
		  <li class="stbody">
		    <div class="stimg"></div>
		    <div class="sttext"></div>
		  </li>
		</ul>
	

我们只需改变结构,无需换样式就能做出效果:

这些效果做起来都并不难,但有时我们会碰到里面嵌套一层类似效果:

正如上图展示的一样,那么肯定有人在想,要重新来过一个结构,在来过一套样式。如果你是这么想的话,那您就错了,为什么呢?不多说,直接看下文。

首先我在前面的HTML结构上做一下修改:

		<ul>
		  <li class="stbody>
		    <div class="stimg"></div>
		    <div class="sttext">
		      <!-- 父元素内容	-->
		
		      <div class="stbody img_attachment">
		        <div class="stimg">img part</div>
		        <div class="sttext">text part</div>
		      </div>
		
		    </div>
		  </li>
		  [...]
		  <li class="stbody">
		    <div class="stimg"></div>
		    <div class="sttext">
		      <!-- 父元素内容	-->
		
		      <div class="stbody img_attachment">
		        <div class="stimg">img part</div>
		        <div class="sttext">text part</div>
		      </div>
		
		    </div>
		  </li>
		</ul>
	

我们只是在原先的“div.sttext”内容下面在放了一个这样的结构,并给里面的“stbody”加了一个类名“img_attachment”,我们只稍为加一点点样式就OK了:

		.img_attachment {
			margin-top:14px;
		}
		.img_attachment.stbody {
			border-bottom: none;
			margin-bottom:0;
		}
	

看看我自己做的效果吧:

那么今天啰嗦扯了一堆,不知道您是否看明白了。虽然此文介绍的制作几种方法都不难,可以说很常见,但能运用得好的我想还是需要一点技巧的,特别的是重用,套用。正如上面介绍的一样。不过今天我最想给大家传达的是一个思路“在平时制作中,把相同的一块提出来,拆分成一个独立的模块。在拆分模块时应保证数量尽可能的少的原则下,做到尽可能的简单,以提高他的重用性。

那么今天就扯到这了,希望大家喜欢这篇文章的内容,如果您有更好的思路,请在下面的评论中与大家一起分享。

如需转载烦请注明出处:W3CPLUS

Google Plus UI Button制作

$
0
0

Google+的“button”效果一直都吸引了我,早就想亲手去体会一下这样的感觉,但一直给自己找借口,直到最近几天,终于动手一试了,试后才知道,他们做的真NB。Google+的UI Buttons形成了一个制作“按钮”、“图标按钮”、“带有标签的图标按钮”、“下拉按钮”、“tip按钮”等按钮的工具或者说UI Buttons框架,使用这一套“UI Button”将会给你的工作带来极大的速度与视觉冲击效果。

那么我们今天的目的就是来看看Google+的攻城师是怎么写的这个代码。因为只有通过代码,我们才能知道其中的原理与制作过程。

HTML Markup:

老样子,首先就需要他的HTML Markup是怎么写的,因为我们在实际应用中这一块是不可缺少的,如果没有这一块,你就无法继续下去,俗话说得好“巧妇难为无米之炊”。下面我们不说别的,直接上代码才是王道:

			<a href="#" class="button"><span class="label">Button</span></a>
			<button><span class="label">Button</span></button>
		

上面的代码是用于单个按钮的,不过我们有时需要几个代码在同一行,类似于菜单的效果,那么最好在外面加上一个包裹容器:

			<div class="buttons">
			  <a class="button" href="#"><span class="label">button</span></a>
			  <a class="button" href="#"><span class="label">button</span></a>
			</div>
		

这样写的好处是:“对于单个Button并看不出其好处,但对于多个处于同一行的Button效果来说,加上这个“div.buttons”容器就很有必要了。我们可以在这个元素上进行浮动的清除,当然你也可以在这个元素上加上一个“clearfix”类名”。

			.buttons {
					/* Style as you wish (toolbar)*/
			 }
			 .buttons:before,
			 .buttons:after {
					content:"";
					display: table;
			 }
			 .buttons:after {
					clear: both;
			 }
			 .buttons {
					zoom:1;
			 }
		

上面我采用的是直接在“.buttons”上清除浮动,没有增加任何标签或者属性值。有关于清除浮动的方法有多种,如果您想了解这方面的知识点,不仿点击《Clear Float》进去看看。

那么说了这么多,我个人强烈建议“不管是单个按钮或者多个按钮,最好都给“button”加上这个“div.buttons”容器”。

			<div class="buttons"><a href="#" class="button"><span class="label">Button</span></a></div>
		

或者:

			<div class="buttons">
			  <a href="#" class="button left"><span class="label">Left Button</span></a>
			  <a href="#" class="button middle"><span class="label">Middle Button</span></a>
			  <a href="#" class="button right"><span class="label">Right Button</span></a>
			</div>
		

上面的结构是我们制作“基本按钮”的一个HTML Markup,但对于后面的“下接按钮”和“TIP按钮”,我们到时还是需要做出一定的修改,详细的可以留意后面的变化,在没有进行另外的说明,都将是以这种“HTML Markup”来制作“Button”。

前面主要介绍了制作“Button”的“HTML Markup”,下面主要来其样式。样式我主要以这样的方式来给大家呈现:首先是“HTML Markup”,接着是“CSS Code”,最后在给大家一个对应的效果图。首先将“Google+的UI Button”分成以下几类:

  1. 基本按钮
  2. ON Button
  3. 动作按钮
  4. 颜色按钮
  5. Inline Button
  6. Negative and postion Buttons
  7. 图标按钮
  8. Tip按钮
  9. 有标签的图标按钮
  10. 下接菜单按钮

一、基本按钮

HTML Markup

			<div class="buttons">
			  <button>
			    <span class="label">Button</span>
			  </button>
			</div>
			<!-- ======OR======== -->
			<div class="buttons">
			  <a class="button">
			    <span class="label">Button</span>
			  </a>
			</div>
		

CSS Code

			/*Default style*/
			button,
			.button {
				text-decoration: none;
				text-shadow: 0 1px 0 #fff;
				
				font: bold 11px Helvetica, Arial, sans-serif;
				color: #444;
				line-height: 17px;
				height: 18px;
				
				display: inline-block;
				float: left;
				
				margin: 5px;
				padding: 5px 6px 4px 6px;
				
				background: #F3F3F3;
				border: solid 1px #D9D9D9;
				
				-webkit-border-radius: 2px;
				-moz-border-radius: 2px;
				border-radius: 2px;
				
				-webkit-transition: border-color .20s;
				-moz-transition: border-color .20s;
				-o-transition: border-color .20s;
				transition: border-color .20s;
			}
			button {
				height: 29px !important;
				cursor: pointer;
			}
			/*Suspended state style (:hover)*/
			button:hover,
			.button:hover {
				background: #F4F4F4;
				border-color: #C0C0C0;
				color: #333;
				text-decoration: none;
			}	

			/*Click on the state effect(:active)*/
			button:active, 
			.button:active {
				border-color: #4D90FE;
				color: #4D90FE;
				
				-moz-box-shadow:inset 0 0 10px #D4D4D4;
				-webkit-box-shadow:inset 0 0 10px #D4D4D4;
				box-shadow:inset 0 0 10px #D4D4D4;
			}
			/*label style*/
			.ddm span.label, 
			button span.label, 
			.button span.label {
				display: inline-block;
				float: left;
				line-height: 17px;
				height: 18px;
				padding: 0 1px;
				overflow: hidden;
				color: #444;
				
				-webkit-transition: color .20s;
				-moz-transition: color .20s;
				-o-transition: color .20s;
				transition: color .20s;
			} 
			button span.label {
				line-height: 15px !important;
			}
			.ddm:active span.label, 
			button:active span.label, 
			.button:active span.label {
					color: #4D90FE;
			}

			button:hover .label, 
			.button:hover .label {
					color: #333;
			}

			button:hover .label.red, 
			.button:hover .label.red {
					color: #DB4A37;
			}
			button:hover .label.blue, 
			.button:hover .label.blue {
					color: #7090C8;
			}
			button:hover .label.green, 
			.button:hover .label.green {
					color: #42B449;
			}
			button:hover .label.yellow, 
			.button:hover .label.yellow {
					color: #F7CB38;
			}

			button.blue .label, 
			.button.blue .label {
				color: #FFF !important;
				text-shadow: 0 1px 0 #2F5BB7 !important;
			}
			button.green .label, 
			.button.green .label {
				color: #FFF !important;
				text-shadow: 0 1px 0 #2D6200 !important;
			}
			button.red .label, 
			.button.red .label {
				color: #FFF !important;
				text-shadow: 0 1px 0 #B0281A !important;
			}
			button.action .label, 
			.button.action .label {
				padding: 0 17px !important;
			}

			button.action:active .label, 
			.button.action:active .label {
				color: #333 !important;
			}

			button.blue:active .label, 
			button.green:active .label, 
			button.red:active .label, 
			.button.blue:active .label, 
			.button.green:active .label, 
			.button.red:active .label {
				color: #FFF !important;
			}
		

效果

google plus ui buttons

这个效果可以说是整个Google+的默认按钮效果。接下来我们一起来看第二种。

二、ON Button

这个效果只是在前面的默认按钮效果上做了一定的修改,这个修改也是很简单的,首先在“button”的HTML标签上增加一个“on”类名,然后样多在“.on”上增加一些别的样式效果,具体看代码吧:

HTML Markup

			<div class="buttons">
			  <button class="on">
			    <span class="label">On Button</span>
			  </button>
			</div>
			<!-- ====	OR  ==== -->
			<div class="buttons">
			  <a class="button on">
			    <span class="label">On Button</span>
			  </a>
			</div>
		

CSS Code

			button.on, 
			.button.on {
				border-color: #BBB;
				
				-moz-box-shadow:inset 0 0 10px #D4D4D4;
				-webkit-box-shadow:inset 0 0 10px #D4D4D4;
				box-shadow:inset 0 0 10px #D4D4D4;
			}
			button.on:hover, 
			.button.on:hover {
				border-color: #BBB;
				
				-moz-box-shadow:inset 0 0 10px #D4D4D4;
				-webkit-box-shadow:inset 0 0 10px #D4D4D4;
				box-shadow:inset 0 0 10px #D4D4D4;
			}
			button.on:active, 
			.button.on:active {
				border-color: #4D90FE;
			}
		

效果

三、动作按钮

动作按钮制作方法和“ON Button”是一样的,只需要在“button”上加上一个“.action”类名,其html代码和上面的“on button”是一样的,只不过把“on”换成了“action”。所以我们直接来看CSS代码的变化.

CSS Code

			button.action, 
			.button.action {
				border: 1px solid #D8D8D8 !important;
				
				background: #F2F2F2;
				background: -webkit-linear-gradient(top, #F5F5F5, #F1F1F1);
				background: -moz-linear-gradient(top, #F5F5F5, #F1F1F1);
				background: -ms-linear-gradient(top, #F5F5F5, #F1F1F1);
				background: -o-linear-gradient(top, #F5F5F5, #F1F1F1);
				
				-webkit-transition: border .20s;
				-moz-transition: border .20s;
				-o-transition: border .20s;
				transition: border .20s;
			}
			button.action:hover, 
			.button.action:hover {
				border: 1px solid #C6C6C6 !important;
				
				background: #F3F3F3;
				background: -webkit-linear-gradient(top, #F8F8F8, #F1F1F1);
				background: -moz-linear-gradient(top, #F8F8F8, #F1F1F1);
				background: -ms-linear-gradient(top, #F8F8F8, #F1F1F1);
				background: -o-linear-gradient(top, #F8F8F8, #F1F1F1);

				-moz-box-shadow: 0 1px 0px #DDD;
				-webkit-box-shadow: 0 1px 0px #DDD;
				box-shadow:iset 0 1px 0px #DDD;
			}
			button.action:active, 
			.button.action:active {
				-moz-box-shadow: none !important;
				-webkit-box-shadow: none !important;
				box-shadow: none !important;
				border-color: #C6C6C6 !important;
			}
		

效果

四、颜色按钮

这里只提供了几种颜色按钮的制作,当然大家可以按照这样的思路自己去配置更多的色彩颜色按钮库。其结构也没有多大的变化,只是在“.button”上增加一个“colorName”的类名,当然这个“colorName”是所指你需要的颜色的名称,他可以是“red,blue,green”等等。接下来只需改变相应的样式。

CSS Code

			/*Blue Button*/
			button.blue, 
			.button.blue {
				border: 1px solid #3079ED !important;
				
				background: #4B8DF8;
				background: -webkit-linear-gradient(top, #4C8FFD, #4787ED);
				background: -moz-linear-gradient(top, #4C8FFD, #4787ED);
				background: -ms-linear-gradient(top, #4C8FFD, #4787ED);
				background: -o-linear-gradient(top, #4C8FFD, #4787ED);
				
				-webkit-transition: border .20s;
				-moz-transition: border .20s;
				-o-transition: border .20s;
				transition: border .20s;
			}
			button.blue:hover, 
			.button.blue:hover {
				border: 1px solid #2F5BB7 !important;
				
				background: #3F83F1;
				background: -webkit-linear-gradient(top, #4D90FE, #357AE8);
				background: -moz-linear-gradient(top, #4D90FE, #357AE8);
				background: -ms-linear-gradient(top, #4D90FE, #357AE8);
				background: -o-linear-gradient(top, #4D90FE, #357AE8);
			}
			button.blue:active, 
			.button.blue:active {
				border-color: #2F5BB7 !important;
			}

			/*green button*/
			button.green, 
			.button.green {
				border: 1px solid #29691D !important;
				
				background: #3A8E00;
				background: -webkit-linear-gradient(top, #3C9300, #398A00);
				background: -moz-linear-gradient(top, #3C9300, #398A00);
				background: -ms-linear-gradient(top, #3C9300, #398A00);
				background: -o-linear-gradient(top, #3C9300, #398A00);
				
				-webkit-transition: border .20s;
				-moz-transition: border .20s;
				-o-transition: border .20s;
				transition: border .20s;
			}
			button.green:hover, 
			.button.green:hover {
				border: 1px solid #2D6200 !important;
				
				background: #3F83F1;
				background: -webkit-linear-gradient(top, #3C9300, #368200);
				background: -moz-linear-gradient(top, #3C9300, #368200);
				background: -ms-linear-gradient(top, #3C9300, #368200);
				background: -o-linear-gradient(top, #3C9300, #368200);
			}
			button.green:active, 
			.button.green:active {
				border-color: #2D6200 !important;
			}

			/*red button*/
			button.red, 
			.button.red {
				border: 1px solid #D14836 !important;
				
				background: #D64937;
				background: -webkit-linear-gradient(top, #DC4A38, #D14836);
				background: -moz-linear-gradient(top, #DC4A38, #D14836);
				background: -ms-linear-gradient(top, #DC4A38, #D14836);
				background: -o-linear-gradient(top, #DC4A38, #D14836);
				
				-webkit-transition: border .20s;
				-moz-transition: border .20s;
				-o-transition: border .20s;
				transition: border .20s;
			}
			button.red:hover, 
			.button.red:hover {
				border: 1px solid #B0281A !important;
				
				background: #D14130;
				background: -webkit-linear-gradient(top, #DC4A38, #C53727);
				background: -moz-linear-gradient(top, #DC4A38, #C53727);
				background: -ms-linear-gradient(top, #DC4A38, #C53727);
				background: -o-linear-gradient(top, #DC4A38, #C53727);
			}
			button.red:active, 
			.button.red:active {
				border-color: #B0281A !important;
			}
		

这里只写了几种颜色按钮的风格,大家要是对色彩有一定的了解,你可以按您自己想要的风格去写,另外这个色彩按钮一般都是配合“动作按钮”一起使用。只要在上面的样式基础上,改变一下HTML标签:

			<div class="buttons">
			  <a href="#" class="button red action"><span class="label">Upload</span></a>
			</div>
		

注:代码中的“red”类名就是所指的“colorName”,你可以根据需要换成你自己想的类名。当然写上相应的样式代码。

效果

五、Inline Button

这个效果是将“Buttons”以一行的风格显示,有点类似是横向菜单的效果。此处将其分为“left”、“middle”和“right”,需要注意的一点就是“left”和“right”将圆角效果去除一边,而“middle”的圆角效果全部清除。

HTML Markup

			<div class="buttons">
			  <a href="#" class="button left"><span class="label">Left</span></a>
			  <a href="#" class="button middle"><span class="label">Middle</span></a>
			  <a href="#" class="button right"><span class="label">right</span></a>
			</div>
		

CSS Code

			button.left, 
			.button.left {
				margin: 5px 0 5px 5px;
				
				border-top-right-radius: 0;
				-webkit-border-top-right-radius: 0;
				-moz-border-radius-topright: 0;
				
				border-bottom-right-radius: 0;
				-webkit-border-bottom-right-radius: 0;
				-moz-border-radius-bottomright: 0;
			}

			button.middle, 
			.button.middle {
				margin: 5px 0;
				
				border-left-color: #F4F4F4;
				
				border-radius: 0;
				-webkit-border-radius: 0;
				-moz-border-radius: 0;
			}
			button.right, 
			.button.right {
				margin: 5px 5px 5px 0;
				
				border-left-color: #F4F4F4;
				
				border-top-left-radius: 0;
				-webkit-border-top-left-radius: 0;
				-moz-border-radius-topleft: 0;
				
				border-bottom-left-radius: 0;
				-webkit-border-bottom-left-radius: 0;
				-moz-border-radius-bottomleft: 0;
			}
		

这段代码有一个细节问题,需要将上面的代码放置在“.button:hover”代码前面,因为我们此处没有为这几种按钮另写一个“:hover”效果。

效果

六、Negative and postion Buttons

第六种按钮效果和前面的“On Button”。“Action Button”类似,只是在“button”上增加了一个“negative”或者“position”类名,然后在单独为这两种类型按钮写了样式。

			.button.negative:hover {
				border: solid 1px #ff3333;
				text-shadow: 0 1px 0 #FCC;
				background: #ffcccc;
				background: -webkit-linear-gradient(top, #ff9999, #DD5555);
				background: -moz-linear-gradient(top, #ff9999, #DD5555);
				background: -ms-linear-gradient(top, #ff9999, #DD5555);
				background: -o-linear-gradient(top, #ff9999, #DD5555);
			}
			.button.positive:hover {
				border: solid 1px #009900;
				text-shadow: 0 1px 0 #CFC;
				background: #ccffcc;
				background: -webkit-linear-gradient(top, #99ff99, #559955);
				background: -moz-linear-gradient(top, #99ff99, #559955);
				background: -ms-linear-gradient(top, #99ff99, #559955);
				background: -o-linear-gradient(top, #99ff99, #559955);
			}
			.button.negative:active {
				border: solid 1px #FF3333;
				background: #ffaaaa;
				text-shadow: 0 1px 0 #CC7777;
				background: -webkit-gradient(linear, left top, left bottom, from(#BB3333), color-stop(0.15, #DD5555), to(#CC5555));
				background: -webkit-linear-gradient(top, #BB3333, #DD5555 15%, #CC5555);
				background: -moz-linear-gradient(top, #BB3333, #DD5555 15%, #CC5555);
				background: -ms-linear-gradient(top, #BB3333, #DD5555 15%, #CC5555);
				background: -o-linear-gradient(top, #BB3333, #DD5555 15%, #CC5555);
			}
			.button.positive:active {
				border: solid 1px #009900;
				background: #aaffaa;
				text-shadow: 0 1px 0 #77CC77;
				background: -webkit-gradient(linear, left top, left bottom, from(#337733), color-stop(0.15, #559955), to(#77CC77));
				background: -webkit-linear-gradient(top, #337733, #559955 15%, #77CC77);
				background: -moz-linear-gradient(top, #337733, #559955 15%, #77CC77);
				background: -ms-linear-gradient(top, #337733, #559955 15%, #77CC77);
				background: -o-linear-gradient(top, #337733, #559955 15%, #77CC77);
			} 
		

效果

七、图标按钮

这里使用sprites技术的配合,制作了一个200个图标的按钮效果。首先来看HTML的不同之处.

HTML Markup

			<div class="buttons"><a href="" class="button"><span class="icon iconNum">iconNum</span></a></div>
		

此处的“iconNum”是代表的“icon”编号,在这里指的是“icon1”至“icon200”。具体可以看下面两张图:

默认icon sprites图:

悬浮状态下的icon sprites图:

下面的样式中就需要使用到这两张图片,接下来看样式的写法吧:

CSS Code

			.ddm span.icon, 
			button span.icon, 
			.button span.icon {
				background-image: url(../images/google+-ui-sprite-gray.png);
				
				display: inline-block;
				margin: 0 7px;
				float: left;
				
				line-height: 18px;
				height: 18px;
				width: 18px;
				max-width: 18px;
				
				overflow: hidden;
				text-indent: -9999px;
				
				background-repeat: no-repeat;
				
				-webkit-transition: background-image 0.20s linear;
				-moz-transition: background-image 0.20s linear;
				-o-transition: background-image 0.20s linear;
				transition: background-image 0.20s linear;
			}
			.ddm:hover span.icon, 
			button:hover span.icon, 
			.button:hover span.icon {
				background-image: url(../images/google+-ui-sprite-colour.png);
			}
			/*=========================
			 * ICON BACKGROUND POSITION
			 *=======================*/
			 /* Sprite Row 1 */
			span.icon1 {background-position: -0px -0px;}
			span.icon2 {background-position: -18px -0px;}
			span.icon3 {background-position: -36px -0px;}
			span.icon4 {background-position: -54px -0px;}
			span.icon5 {background-position: -72px -0px;}
			span.icon6 {background-position: -90px -0px;}
			span.icon7 {background-position: -108px -0px;}
			span.icon8 {background-position: -126px -0px;}
			span.icon9 {background-position: -144px -0px;}
			span.icon10 {background-position: -162px -0px;}
			span.icon11 {background-position: -180px -0px;}
			span.icon12 {background-position: -198px -0px;}
			span.icon13 {background-position: -216px -0px;}
			span.icon14 {background-position: -234px -0px;}
			span.icon15 {background-position: -252px -0px;}
			span.icon16 {background-position: -270px -0px;}
			span.icon17 {background-position: -288px -0px;}
			span.icon18 {background-position: -306px -0px;}
			span.icon19 {background-position: -324px -0px;}
			span.icon20 {background-position: -342px -0px;}

			/* Sprite Row 2 */
			span.icon21 {background-position: -0px -18px;}
			span.icon22 {background-position: -18px -18px;}
			span.icon23 {background-position: -36px -18px;}
			span.icon24 {background-position: -54px -18px;}
			span.icon25 {background-position: -72px -18px;}
			span.icon26 {background-position: -90px -18px;}
			span.icon27 {background-position: -108px -18px;}
			span.icon28 {background-position: -126px -18px;}
			span.icon29 {background-position: -144px -18px;}
			span.icon30 {background-position: -162px -18px;}
			span.icon31 {background-position: -180px -18px;}
			span.icon32 {background-position: -198px -18px;}
			span.icon33 {background-position: -216px -18px;}
			span.icon34 {background-position: -234px -18px;}
			span.icon35 {background-position: -252px -18px;}
			span.icon36 {background-position: -270px -18px;}
			span.icon37 {background-position: -288px -18px;}
			span.icon38 {background-position: -306px -18px;}
			span.icon39 {background-position: -324px -18px;}
			span.icon40 {background-position: -342px -18px;}

			/* Sprite Row 3 */
			span.icon41 {background-position: -0px -36px;}
			span.icon42 {background-position: -18px -36px;}
			span.icon43 {background-position: -36px -36px;}
			span.icon44 {background-position: -54px -36px;}
			span.icon45 {background-position: -72px -36px;}
			span.icon46 {background-position: -90px -36px;}
			span.icon47 {background-position: -108px -36px;}
			span.icon48 {background-position: -126px -36px;}
			span.icon49 {background-position: -144px -36px;}
			span.icon50 {background-position: -162px -36px;}
			span.icon51 {background-position: -180px -36px;}
			span.icon52 {background-position: -198px -36px;}
			span.icon53 {background-position: -216px -36px;}
			span.icon54 {background-position: -234px -36px;}
			span.icon55 {background-position: -252px -36px;}
			span.icon56 {background-position: -270px -36px;}
			span.icon57 {background-position: -288px -36px;}
			span.icon58 {background-position: -306px -36px;}
			span.icon59 {background-position: -324px -36px;}
			span.icon60 {background-position: -342px -36px;}

			/* Sprite Row 4 */
			span.icon61 {background-position: -0px -54px;}
			span.icon62 {background-position: -18px -54px;}
			span.icon63 {background-position: -36px -54px;}
			span.icon64 {background-position: -54px -54px;}
			span.icon65 {background-position: -72px -54px;}
			span.icon66 {background-position: -90px -54px;}
			span.icon67 {background-position: -108px -54px;}
			span.icon68 {background-position: -126px -54px;}
			span.icon69 {background-position: -144px -54px;}
			span.icon70 {background-position: -162px -54px;}
			span.icon71 {background-position: -180px -54px;}
			span.icon72 {background-position: -198px -54px;}
			span.icon73 {background-position: -216px -54px;}
			span.icon74 {background-position: -234px -54px;}
			span.icon75 {background-position: -252px -54px;}
			span.icon76 {background-position: -270px -54px;}
			span.icon77 {background-position: -288px -54px;}
			span.icon78 {background-position: -306px -54px;}
			span.icon79 {background-position: -324px -54px;}
			span.icon80 {background-position: -342px -54px;}

			/* Sprite Row 5 */
			span.icon81 {background-position: -0px -72px;}
			span.icon82 {background-position: -18px -72px;}
			span.icon83 {background-position: -36px -72px;}
			span.icon84 {background-position: -54px -72px;}
			span.icon85 {background-position: -72px -72px;}
			span.icon86 {background-position: -90px -72px;}
			span.icon87 {background-position: -108px -72px;}
			span.icon88 {background-position: -126px -72px;}
			span.icon89 {background-position: -144px -72px;}
			span.icon90 {background-position: -162px -72px;}
			span.icon91 {background-position: -180px -72px;}
			span.icon92 {background-position: -198px -72px;}
			span.icon93 {background-position: -216px -72px;}
			span.icon94 {background-position: -234px -72px;}
			span.icon95 {background-position: -252px -72px;}
			span.icon96 {background-position: -270px -72px;}
			span.icon97 {background-position: -288px -72px;}
			span.icon98 {background-position: -306px -72px;}
			span.icon99 {background-position: -324px -72px;}
			span.icon100 {background-position: -342px -72px;}

			/* Sprite Row 6 */
			span.icon101 {background-position: -0px -90px;}
			span.icon102 {background-position: -18px -90px;}
			span.icon103 {background-position: -36px -90px;}
			span.icon104 {background-position: -54px -90px;}
			span.icon105 {background-position: -72px -90px;}
			span.icon106 {background-position: -90px -90px;}
			span.icon107 {background-position: -108px -90px;}
			span.icon108 {background-position: -126px -90px;}
			span.icon109 {background-position: -144px -90px;}
			span.icon110 {background-position: -162px -90px;}
			span.icon111 {background-position: -180px -90px;}
			span.icon112 {background-position: -198px -90px;}
			span.icon113 {background-position: -216px -90px;}
			span.icon114 {background-position: -234px -90px;}
			span.icon115 {background-position: -252px -90px;}
			span.icon116 {background-position: -270px -90px;}
			span.icon117 {background-position: -288px -90px;}
			span.icon118 {background-position: -306px -90px;}
			span.icon119 {background-position: -324px -90px;}
			span.icon120 {background-position: -342px -90px;}

			/* Sprite Row 7 */
			span.icon121 {background-position: -0px -108px;}
			span.icon122 {background-position: -18px -108px;}
			span.icon123 {background-position: -36px -108px;}
			span.icon124 {background-position: -54px -108px;}
			span.icon125 {background-position: -72px -108px;}
			span.icon126 {background-position: -90px -108px;}
			span.icon127 {background-position: -108px -108px;}
			span.icon128 {background-position: -126px -108px;}
			span.icon129 {background-position: -144px -108px;}
			span.icon130 {background-position: -162px -108px;}
			span.icon131 {background-position: -180px -108px;}
			span.icon132 {background-position: -198px -108px;}
			span.icon133 {background-position: -216px -108px;}
			span.icon134 {background-position: -234px -108px;}
			span.icon135 {background-position: -252px -108px;}
			span.icon136 {background-position: -270px -108px;}
			span.icon137 {background-position: -288px -108px;}
			span.icon138 {background-position: -306px -108px;}
			span.icon139 {background-position: -324px -108px;}
			span.icon140 {background-position: -342px -108px;}

			/* Sprite Row 8 */
			span.icon141 {background-position: -0px -126px;}
			span.icon142 {background-position: -18px -126px;}
			span.icon143 {background-position: -36px -126px;}
			span.icon144 {background-position: -54px -126px;}
			span.icon145 {background-position: -72px -126px;}
			span.icon146 {background-position: -90px -126px;}
			span.icon147 {background-position: -108px -126px;}
			span.icon148 {background-position: -126px -126px;}
			span.icon149 {background-position: -144px -126px;}
			span.icon150 {background-position: -162px -126px;}
			span.icon151 {background-position: -180px -126px;}
			span.icon152 {background-position: -198px -126px;}
			span.icon153 {background-position: -216px -126px;}
			span.icon154 {background-position: -234px -126px;}
			span.icon155 {background-position: -252px -126px;}
			span.icon156 {background-position: -270px -126px;}
			span.icon157 {background-position: -288px -126px;}
			span.icon158 {background-position: -306px -126px;}
			span.icon159 {background-position: -324px -126px;}
			span.icon160 {background-position: -342px -126px;}

			/* Sprite Row 9 */
			span.icon161 {background-position: -0px -144px;}
			span.icon162 {background-position: -18px -144px;}
			span.icon163 {background-position: -36px -144px;}
			span.icon164 {background-position: -54px -144px;}
			span.icon165 {background-position: -72px -144px;}
			span.icon166 {background-position: -90px -144px;}
			span.icon167 {background-position: -108px -144px;}
			span.icon168 {background-position: -126px -144px;}
			span.icon169 {background-position: -144px -144px;}
			span.icon170 {background-position: -162px -144px;}
			span.icon171 {background-position: -180px -144px;}
			span.icon172 {background-position: -198px -144px;}
			span.icon173 {background-position: -216px -144px;}
			span.icon174 {background-position: -234px -144px;}
			span.icon175 {background-position: -252px -144px;}
			span.icon176 {background-position: -270px -144px;}
			span.icon177 {background-position: -288px -144px;}
			span.icon178 {background-position: -306px -144px;}
			span.icon179 {background-position: -324px -144px;}
			span.icon180 {background-position: -342px -144px;}

			/* Sprite Row 10 */
			span.icon181 {background-position: -0px -162px;}
			span.icon182 {background-position: -18px -162px;}
			span.icon183 {background-position: -36px -162px;}
			span.icon184 {background-position: -54px -162px;}
			span.icon185 {background-position: -72px -162px;}
			span.icon186 {background-position: -90px -162px;}
			span.icon187 {background-position: -108px -162px;}
			span.icon188 {background-position: -126px -162px;}
			span.icon189 {background-position: -144px -162px;}
			span.icon190 {background-position: -162px -162px;}
			span.icon191 {background-position: -180px -162px;}
			span.icon192 {background-position: -198px -162px;}
			span.icon193 {background-position: -216px -162px;}
			span.icon194 {background-position: -234px -162px;}
			span.icon195 {background-position: -252px -162px;}
			span.icon196 {background-position: -270px -162px;}
			span.icon197 {background-position: -288px -162px;}
			span.icon198 {background-position: -306px -162px;}
			span.icon199 {background-position: -324px -162px;}
			span.icon200 {background-position: -342px -162px;}
		

效果:

八、Tip按钮

制作这种按钮效果,就需jQuery版本库以及TipTip jQuery Plugin(你可以到下载)。如果你准备好了这些东东,我们就开如下面的制作。

HTML Markup

			<div class="buttons">
			  <div class="tiptip">
			    <a class="button" title="Home"><span class="icon icon108"></span></a>
			  </div>
			</div>
		

这里有一个关键之处,那就是需要在“.button”元素中增加一个“title”属性,其属性值就是你希望在“tooltip”中显示的内容。如上面的代码所示,在“.button”元素中增加一个“title”属性,并且将其值设置为“Home”。

有了上面的结构后,还需要在“HTML”中调用前面准备好的jQuery版本库以及TipTip jQuery Plugin。具体放哪,大家都知道,我就不多说了。

			<script src="js/jquery-1.6.2.js"></script>
			<script src="js/jquery.tiptip.js"></script>
		

这些准备好以后,就需要在有“tooltip按钮”地方调用“.tipTip()”函数。

			<script type="text/javascript">
				$(function(){
					//Launch TipTip tooltip
					$(".tiptip a.button, .tiptip button").tipTip();
				});
			</script>
		

上面是完成了“tooltip”功能,那么我们还需要给这些“tooltip按钮”赋予相应的样式。

CSS Code

			/* TipTip CSS - Version 1.2 (Modified) */

			#tiptip_holder {
				display: none;
				position: absolute;
				top: 0;
				left: 0;
				z-index: 99999;
			}

			#tiptip_holder.tip_top {
				padding-bottom: 5px;
			}

			#tiptip_holder.tip_bottom {
				padding-top: 5px;
			}

			#tiptip_holder.tip_right {
				padding-left: 5px;
			}

			#tiptip_holder.tip_left {
				padding-right: 5px;
			}

			#tiptip_content {
				font: bold 11px Helvetica, Arial, sans-serif;
				color: #FFF;
				padding: 7px;
				background: #000;
				border: 1px solid #FFF;
			}

			#tiptip_arrow, #tiptip_arrow_inner {
				position: absolute;
				border-color: transparent;
				border-style: solid;
				border-width: 6px;
				height: 0;
				width: 0;
			}

			#tiptip_holder.tip_top #tiptip_arrow {
				border-top-color: #fff;
			}

			#tiptip_holder.tip_bottom #tiptip_arrow {
				border-bottom-color: #fff;
			}

			#tiptip_holder.tip_right #tiptip_arrow {
				border-right-color: #fff;
			}

			#tiptip_holder.tip_left #tiptip_arrow {
				border-left-color: #fff;
			}

			#tiptip_holder.tip_top #tiptip_arrow_inner {
				margin-top: -7px;
				margin-left: -6px;
				border-top-color: #000;
			}

			#tiptip_holder.tip_bottom #tiptip_arrow_inner {
				margin-top: -5px;
				margin-left: -6px;
				border-bottom-color: #000;
			}

			#tiptip_holder.tip_right #tiptip_arrow_inner {
				margin-top: -6px;
				margin-left: -5px;
				border-right-color: #000;
			}

			#tiptip_holder.tip_left #tiptip_arrow_inner {
				margin-top: -6px;
				margin-left: -7px;
				border-left-color: #000;
			}

			/* Webkit Hacks  */
			@media screen and (-webkit-min-device-pixel-ratio:0) {	
				#tiptip_content {
					padding: 4px 8px 5px 8px;
					background-color: #000;
				}
				#tiptip_holder.tip_bottom #tiptip_arrow_inner { 
					border-bottom-color: #000;
				}
				#tiptip_holder.tip_top #tiptip_arrow_inner { 
					border-top-color: #000;
				}
			}
		

效果

九、带有标签的Icon按钮

这个效果只是结合了“默认按钮”和“Icon按钮”的风格。只需要在HTML做出一定的修改就Ok了。

HTML Markup

			<div class="buttons">
			  <a class="button" href="#"><span class="icon icon4"></span><span class="label">Profile</span></a>
			</div>
		

效果

十、下拉菜单按钮

制作这个效果,需要配合jQuery代码。首先我们看看其结构上的变化吧。

HTML Markup

			<div class="buttons">
			  <div class="dropdown">
			    <a href="#" class="button"><span class="label">File</span><span class="toggle"></span></a>
			    <div class="dropdown-slider">
			      <a href="#" class="ddm"><span class="label">New</span></a>
			      <a href="#" class="ddm"><span class="label">Save</span></a>
			    </div> 
			  </div>
			</div>
		

CSS Code

			div.dropdown {
				float: left;
				position: relative;
			}

			div.dropdown span.toggle {
				width: 19px;
				height: 16px;
				
				margin-left: 7px;
				margin-top: 1px;
				margin-right: 2px;
				padding-left: 8px;
				
				float: right;
				
				background: url(../images/toggle.png) top right no-repeat;
				border-left: 1px solid #D9D9D9;
				
				-webkit-transition: border-color .20s;
				-moz-transition: border .20s;
				-o-transition: border-color .20s;
				transition: border-color .20s;
			}
			div.dropdown span.toggle.active {
				background: url(../images/toggle.png) bottom right no-repeat;
			}
			div.dropdown 
			button:hover span.toggle, 
			.button:hover span.toggle {
				border-color: #C0C0C0;
			}

			div.dropdown-slider {
				display: none;
				
				overflow: hidden;
				
				margin: 0 7px 5px 7px;
				position: absolute;
				top: 34px;
				right: 0;
				
				background: #F2F2F2;
				
				border-right: solid 1px #D9D9D9;
				border-bottom: solid 1px #D9D9D9;
				border-left: solid 1px #D9D9D9;
				
				-webkit-border-bottom-right-radius: 2px;
				-webkit-border-bottom-left-radius: 2px;
				-moz-border-radius-bottomright: 2px;
				-moz-border-radius-bottomleft: 2px;
				border-bottom-right-radius: 2px;
				border-bottom-left-radius: 2px;
				
				-webkit-transition: border-color .20s;
				-moz-transition: border .20s;
				-o-transition: border-color .20s;
				transition: border-color .20s;
			}
			.left div.dropdown-slider {
				margin: 0 1px 5px 7px;
			}
			.middle div.dropdown-slider {
				margin: 0 1px 5px 1px;
			}
			.right div.dropdown-slider {
				margin: 0 7px 5px 1px;
			}
			div.dropdown-slider .ddm {
				display: block;
				background: #F2F2F2;
				color: #585858;
				
				text-decoration: none;
				text-shadow: 0 1px 0 #fff;
				font: bold 11px Helvetica, Arial, sans-serif;
				line-height: 18px;
				height: 18px;
				
				margin: 0;
				padding: 5px 6px 4px 6px;
				width: 100%;
				float: left;
				
				border-top: 1px solid #FFF;
				border-bottom: 1px solid #D9D9D9;
			}
			div.dropdown-slider .ddm:hover {
				background: #F4F4F4;
				border-bottom-color: #C0C0C0;
			}
			div.dropdown-slider .ddm:active {
				border-bottom-color: #4D90FE;
				color: #4D90FE;
				
				-moz-box-shadow:inset 0 0 10px #D4D4D4;
				-webkit-box-shadow:inset 0 0 10px #D4D4D4;
				box-shadow:inset 0 0 10px #D4D4D4;
			}
			div.dropdown-slider .ddm:last-child {
				border-bottom: none;
			} 
		

jQuery Code

			<script type="text/javascript">
					$(function(){
							// Toggle the dropdown menu's
							$(".dropdown .button, .dropdown button").click(function () {
								if (!$(this).find('span.toggle').hasClass('active')) {
									$('.dropdown-slider').slideUp();
									$('span.toggle').removeClass('active');
								}
							 
								// open selected dropown
								$(this).parent().find('.dropdown-slider').slideToggle('fast');
								$(this).find('span.toggle').toggleClass('active');
								
								return false;
							});		
							
						});
						
						// Close open dropdown slider by clicking elsewhwere on page
						$(document).bind('click', function (e) {
							if (e.target.id != $('.dropdown').attr('class')) {
								$('.dropdown-slider').slideUp();
								$('span.toggle').removeClass('active');
							}
						});
			</script>
		

效果

那么到此有关于Google+的“UI Button”到此就全部分解完了。最后我将所应用到的所有CSS代码贴在这里以供大家参考。(里面附上相关的HTML Markup)

			/*==============================================
			 *		Button Wrapper => class="buttons"
			 *		HTML MARKUP
			 *		<div class="buttons">
			 *			<a class="button" href="#"><span class="label">button</span></a>
			 *			<a class="button" href="#"><span class="label">button</span></a>
			 *		</div>
			 *==============================================*/
			 .buttons {
					/* Style as you wish (toolbar)*/
			 }
			 .buttons:before,
			 .buttons:after {
					content:"";
					display: table;
			 }
			 .buttons:after {
					clear: both;
			 }
			 .buttons {
					zoom:1;
			 }
			 
			 /*================================================
				* 	BASE STYLE FOR BUTTON
				*				HTML MARKUP	
				*		<button>
				*			<span class="label">Button</span>
				*		</button>
				*		OR
				*		<a class="button">
				*			<span class="label">Button</span>
				*		</a>
				*===============================================*/
			/*Default style*/
			button,
			.button {
				text-decoration: none;
				text-shadow: 0 1px 0 #fff;
				
				font: bold 11px Helvetica, Arial, sans-serif;
				color: #444;
				line-height: 17px;
				height: 18px;
				
				display: inline-block;
				float: left;
				
				margin: 5px;
				padding: 5px 6px 4px 6px;
				
				background: #F3F3F3;
				border: solid 1px #D9D9D9;
				
				-webkit-border-radius: 2px;
				-moz-border-radius: 2px;
				border-radius: 2px;
				
				-webkit-transition: border-color .20s;
				-moz-transition: border-color .20s;
				-o-transition: border-color .20s;
				transition: border-color .20s;
			}
			button {
				height: 29px !important;
				cursor: pointer;
			}
			/*============================
			 *	INLINE BUTTONS
			 *  HTML MARKUP
			 *  <a href="#" class="button left"><span class="label">Left</span></a>
			 *  <a href="#" class="button middle"><span class="label">Middle</span></a>
			 *  <a href="#" class="button right"><span class="label">right</span></a>
			 *==========OR=============
			 *  <button class="left"><span class="label">Left</span></button>
			 *  <button class="middle"><span class="label">Middle</span></button>
			 *  <button class="right"><span class="label">Right</span></button>
			 *============================*/
			button.left, 
			.button.left {
				margin: 5px 0 5px 5px;
				
				border-top-right-radius: 0;
				-webkit-border-top-right-radius: 0;
				-moz-border-radius-topright: 0;
				
				border-bottom-right-radius: 0;
				-webkit-border-bottom-right-radius: 0;
				-moz-border-radius-bottomright: 0;
			}

			button.middle, 
			.button.middle {
				margin: 5px 0;
				
				border-left-color: #F4F4F4;
				
				border-radius: 0;
				-webkit-border-radius: 0;
				-moz-border-radius: 0;
			}
			button.right, 
			.button.right {
				margin: 5px 5px 5px 0;
				
				border-left-color: #F4F4F4;
				
				border-top-left-radius: 0;
				-webkit-border-top-left-radius: 0;
				-moz-border-radius-topleft: 0;
				
				border-bottom-left-radius: 0;
				-webkit-border-bottom-left-radius: 0;
				-moz-border-radius-bottomleft: 0;
			}
			/*Suspended state style (:hover)*/
			button:hover,
			.button:hover {
				background: #F4F4F4;
				border-color: #C0C0C0;
				color: #333;
				text-decoration: none;
			}	

			/*Click on the state effect(:active)*/
			button:active, 
			.button:active {
				border-color: #4D90FE;
				color: #4D90FE;
				
				-moz-box-shadow:inset 0 0 10px #D4D4D4;
				-webkit-box-shadow:inset 0 0 10px #D4D4D4;
				box-shadow:inset 0 0 10px #D4D4D4;
			}

			/*=====================================
			 *  $BUTTON LABEL STYLE
			 *====================================*/

			/*====================================
			 *	Dropdown Menu Buttons
			 *	HTML MARKUP
			 *==========DROPDOWN BUTTONS=========
			 *	<div class="dropdown">
			 *    <a href="#" class="button"><span class="label">File</span><span class="toggle"></span></a>
			 *    <div class="dropdown-slider">
			 *      <a href="#" class="ddm"><span class="label">New</span></a>
			 *       <a href="#" class="ddm"><span class="label">Save</span></a>
			 *     </div> <!-- /.dropdown-slider -->
			 *   </div> <!-- /.dropdown -->
			 *========Default Button Label=========
			 *		<button>
			 *			<span class="label">Button</span>
			 *		</button>
			 *=====OR======
			 *		<a class="button">
			 *			<span class="label">Button</span>
			 *		</a>
			 *
			 *==================================*/
			.ddm span.label, 
			button span.label, 
			.button span.label {
				display: inline-block;
				float: left;
				line-height: 17px;
				height: 18px;
				padding: 0 1px;
				overflow: hidden;
				color: #444;
				
				-webkit-transition: color .20s;
				-moz-transition: color .20s;
				-o-transition: color .20s;
				transition: color .20s;
			} 
			button span.label {
				line-height: 15px !important;
			}
			.ddm:active span.label, 
			button:active span.label, 
			.button:active span.label {
					color: #4D90FE;
			}

			button:hover .label, 
			.button:hover .label {
					color: #333;
			}

			button:hover .label.red, 
			.button:hover .label.red {
					color: #DB4A37;
			}
			button:hover .label.blue, 
			.button:hover .label.blue {
					color: #7090C8;
			}
			button:hover .label.green, 
			.button:hover .label.green {
					color: #42B449;
			}
			button:hover .label.yellow, 
			.button:hover .label.yellow {
					color: #F7CB38;
			}

			button.blue .label, 
			.button.blue .label {
				color: #FFF !important;
				text-shadow: 0 1px 0 #2F5BB7 !important;
			}
			button.green .label, 
			.button.green .label {
				color: #FFF !important;
				text-shadow: 0 1px 0 #2D6200 !important;
			}
			button.red .label, 
			.button.red .label {
				color: #FFF !important;
				text-shadow: 0 1px 0 #B0281A !important;
			}
			button.action .label, 
			.button.action .label {
				padding: 0 17px !important;
			}

			button.action:active .label, 
			.button.action:active .label {
				color: #333 !important;
			}

			button.blue:active .label, 
			button.green:active .label, 
			button.red:active .label, 
			.button.blue:active .label, 
			.button.green:active .label, 
			.button.red:active .label {
				color: #FFF !important;
			}

			/*===========================================
			 *		ON BUTTON STYLE
			 *		HTML MARKUP
			 *	<button class="on">
			 *		<span class="label">On Button</span>
			 *	</button>
			 *====	OR  ====
			 *	<a class="button on">
			 *		<span class="label">On Button</span>
			 *	</a>
			 *==========================================*/

			button.on, 
			.button.on {
				border-color: #BBB;
				
				-moz-box-shadow:inset 0 0 10px #D4D4D4;
				-webkit-box-shadow:inset 0 0 10px #D4D4D4;
				box-shadow:inset 0 0 10px #D4D4D4;
			}
			button.on:hover, 
			.button.on:hover {
				border-color: #BBB;
				
				-moz-box-shadow:inset 0 0 10px #D4D4D4;
				-webkit-box-shadow:inset 0 0 10px #D4D4D4;
				box-shadow:inset 0 0 10px #D4D4D4;
			}
			button.on:active, 
			.button.on:active {
				border-color: #4D90FE;
			} 

			/*===========================================
			 *		ACTION BUTTON STYLE
			 *		HTML MARKUP
			 *	<button class="action">
			 *		<span class="label">Action</span>
			 *	</button>
			 *====	OR  ====
			 *	<a class="button action">
			 *		<span class="label">Action</span>
			 *	</a>
			 *==========================================*/

			button.action, 
			.button.action {
				border: 1px solid #D8D8D8 !important;
				
				background: #F2F2F2;
				background: -webkit-linear-gradient(top, #F5F5F5, #F1F1F1);
				background: -moz-linear-gradient(top, #F5F5F5, #F1F1F1);
				background: -ms-linear-gradient(top, #F5F5F5, #F1F1F1);
				background: -o-linear-gradient(top, #F5F5F5, #F1F1F1);
				
				-webkit-transition: border .20s;
				-moz-transition: border .20s;
				-o-transition: border .20s;
				transition: border .20s;
			}
			button.action:hover, 
			.button.action:hover {
				border: 1px solid #C6C6C6 !important;
				
				background: #F3F3F3;
				background: -webkit-linear-gradient(top, #F8F8F8, #F1F1F1);
				background: -moz-linear-gradient(top, #F8F8F8, #F1F1F1);
				background: -ms-linear-gradient(top, #F8F8F8, #F1F1F1);
				background: -o-linear-gradient(top, #F8F8F8, #F1F1F1);

				-moz-box-shadow: 0 1px 0px #DDD;
				-webkit-box-shadow: 0 1px 0px #DDD;
				box-shadow:iset 0 1px 0px #DDD;
			}
			button.action:active, 
			.button.action:active {
				-moz-box-shadow: none !important;
				-webkit-box-shadow: none !important;
				box-shadow: none !important;
				border-color: #C6C6C6 !important;
			}
			/*===========================================
			 *		COLOR BUTTON STYLE
			 *		HTML MARKUP
			 *	<button class="colorName">
			 *		<span class="label">Color's name</span>
			 *	</button>
			 *====	OR  ====
			 *	<a class="button colorName">
			 *		<span class="label">color's name</span>
			 *	</a>
			 *==========================================*/
			/*Blue Button*/
			button.blue, 
			.button.blue {
				border: 1px solid #3079ED !important;
				
				background: #4B8DF8;
				background: -webkit-linear-gradient(top, #4C8FFD, #4787ED);
				background: -moz-linear-gradient(top, #4C8FFD, #4787ED);
				background: -ms-linear-gradient(top, #4C8FFD, #4787ED);
				background: -o-linear-gradient(top, #4C8FFD, #4787ED);
				
				-webkit-transition: border .20s;
				-moz-transition: border .20s;
				-o-transition: border .20s;
				transition: border .20s;
			}
			button.blue:hover, 
			.button.blue:hover {
				border: 1px solid #2F5BB7 !important;
				
				background: #3F83F1;
				background: -webkit-linear-gradient(top, #4D90FE, #357AE8);
				background: -moz-linear-gradient(top, #4D90FE, #357AE8);
				background: -ms-linear-gradient(top, #4D90FE, #357AE8);
				background: -o-linear-gradient(top, #4D90FE, #357AE8);
			}
			button.blue:active, 
			.button.blue:active {
				border-color: #2F5BB7 !important;
			}

			/*green button*/
			button.green, 
			.button.green {
				border: 1px solid #29691D !important;
				
				background: #3A8E00;
				background: -webkit-linear-gradient(top, #3C9300, #398A00);
				background: -moz-linear-gradient(top, #3C9300, #398A00);
				background: -ms-linear-gradient(top, #3C9300, #398A00);
				background: -o-linear-gradient(top, #3C9300, #398A00);
				
				-webkit-transition: border .20s;
				-moz-transition: border .20s;
				-o-transition: border .20s;
				transition: border .20s;
			}
			button.green:hover, 
			.button.green:hover {
				border: 1px solid #2D6200 !important;
				
				background: #3F83F1;
				background: -webkit-linear-gradient(top, #3C9300, #368200);
				background: -moz-linear-gradient(top, #3C9300, #368200);
				background: -ms-linear-gradient(top, #3C9300, #368200);
				background: -o-linear-gradient(top, #3C9300, #368200);
			}
			button.green:active, 
			.button.green:active {
				border-color: #2D6200 !important;
			}

			/*red button*/
			button.red, 
			.button.red {
				border: 1px solid #D14836 !important;
				
				background: #D64937;
				background: -webkit-linear-gradient(top, #DC4A38, #D14836);
				background: -moz-linear-gradient(top, #DC4A38, #D14836);
				background: -ms-linear-gradient(top, #DC4A38, #D14836);
				background: -o-linear-gradient(top, #DC4A38, #D14836);
				
				-webkit-transition: border .20s;
				-moz-transition: border .20s;
				-o-transition: border .20s;
				transition: border .20s;
			}
			button.red:hover, 
			.button.red:hover {
				border: 1px solid #B0281A !important;
				
				background: #D14130;
				background: -webkit-linear-gradient(top, #DC4A38, #C53727);
				background: -moz-linear-gradient(top, #DC4A38, #C53727);
				background: -ms-linear-gradient(top, #DC4A38, #C53727);
				background: -o-linear-gradient(top, #DC4A38, #C53727);
			}
			button.red:active, 
			.button.red:active {
				border-color: #B0281A !important;
			}
			/*==============================
			 * NEGATIVE AND POSITION BUTTON
			 *	HTML MARKUP
			 * <a class="button positive" href="#"><span class="label">Positive</span></a>
			 * <a class="button negative" href="#"><span class="label">Negative</span></a>
			 *=========================*/
			.button.negative:hover {
				border: solid 1px #ff3333;
				text-shadow: 0 1px 0 #FCC;
				background: #ffcccc;
				background: -webkit-linear-gradient(top, #ff9999, #DD5555);
				background: -moz-linear-gradient(top, #ff9999, #DD5555);
				background: -ms-linear-gradient(top, #ff9999, #DD5555);
				background: -o-linear-gradient(top, #ff9999, #DD5555);
			}
			.button.positive:hover {
				border: solid 1px #009900;
				text-shadow: 0 1px 0 #CFC;
				background: #ccffcc;
				background: -webkit-linear-gradient(top, #99ff99, #559955);
				background: -moz-linear-gradient(top, #99ff99, #559955);
				background: -ms-linear-gradient(top, #99ff99, #559955);
				background: -o-linear-gradient(top, #99ff99, #559955);
			}
			.button.negative:active {
				border: solid 1px #FF3333;
				background: #ffaaaa;
				text-shadow: 0 1px 0 #CC7777;
				background: -webkit-gradient(linear, left top, left bottom, from(#BB3333), color-stop(0.15, #DD5555), to(#CC5555));
				background: -webkit-linear-gradient(top, #BB3333, #DD5555 15%, #CC5555);
				background: -moz-linear-gradient(top, #BB3333, #DD5555 15%, #CC5555);
				background: -ms-linear-gradient(top, #BB3333, #DD5555 15%, #CC5555);
				background: -o-linear-gradient(top, #BB3333, #DD5555 15%, #CC5555);
			}
			.button.positive:active {
				border: solid 1px #009900;
				background: #aaffaa;
				text-shadow: 0 1px 0 #77CC77;
				background: -webkit-gradient(linear, left top, left bottom, from(#337733), color-stop(0.15, #559955), to(#77CC77));
				background: -webkit-linear-gradient(top, #337733, #559955 15%, #77CC77);
				background: -moz-linear-gradient(top, #337733, #559955 15%, #77CC77);
				background: -ms-linear-gradient(top, #337733, #559955 15%, #77CC77);
				background: -o-linear-gradient(top, #337733, #559955 15%, #77CC77);
			} 

			/*====================================
			 * ICON BUTTON
			 * HTML MARKUP
			 * <a class="button"><span class="icon icon1"></span></a>
			 *===========OR=========
			 * <button><span class="icon icon1"></span></button>
			 *===================================*/
			.ddm span.icon, 
			button span.icon, 
			.button span.icon {
				background-image: url(../images/google+-ui-sprite-gray.png);
				
				display: inline-block;
				margin: 0 7px;
				float: left;
				
				line-height: 18px;
				height: 18px;
				width: 18px;
				max-width: 18px;
				
				overflow: hidden;
				text-indent: -9999px;
				
				background-repeat: no-repeat;
				
				-webkit-transition: background-image 0.20s linear;
				-moz-transition: background-image 0.20s linear;
				-o-transition: background-image 0.20s linear;
				transition: background-image 0.20s linear;
			}
			.ddm:hover span.icon, 
			button:hover span.icon, 
			.button:hover span.icon {
				background-image: url(../images/google+-ui-sprite-colour.png);
			}
			/*=========================
			 * ICON BACKGROUND POSITION
			 *=======================*/
			 /* Sprite Row 1 */
			span.icon1 {background-position: -0px -0px;}
			span.icon2 {background-position: -18px -0px;}
			span.icon3 {background-position: -36px -0px;}
			span.icon4 {background-position: -54px -0px;}
			span.icon5 {background-position: -72px -0px;}
			span.icon6 {background-position: -90px -0px;}
			span.icon7 {background-position: -108px -0px;}
			span.icon8 {background-position: -126px -0px;}
			span.icon9 {background-position: -144px -0px;}
			span.icon10 {background-position: -162px -0px;}
			span.icon11 {background-position: -180px -0px;}
			span.icon12 {background-position: -198px -0px;}
			span.icon13 {background-position: -216px -0px;}
			span.icon14 {background-position: -234px -0px;}
			span.icon15 {background-position: -252px -0px;}
			span.icon16 {background-position: -270px -0px;}
			span.icon17 {background-position: -288px -0px;}
			span.icon18 {background-position: -306px -0px;}
			span.icon19 {background-position: -324px -0px;}
			span.icon20 {background-position: -342px -0px;}

			/* Sprite Row 2 */
			span.icon21 {background-position: -0px -18px;}
			span.icon22 {background-position: -18px -18px;}
			span.icon23 {background-position: -36px -18px;}
			span.icon24 {background-position: -54px -18px;}
			span.icon25 {background-position: -72px -18px;}
			span.icon26 {background-position: -90px -18px;}
			span.icon27 {background-position: -108px -18px;}
			span.icon28 {background-position: -126px -18px;}
			span.icon29 {background-position: -144px -18px;}
			span.icon30 {background-position: -162px -18px;}
			span.icon31 {background-position: -180px -18px;}
			span.icon32 {background-position: -198px -18px;}
			span.icon33 {background-position: -216px -18px;}
			span.icon34 {background-position: -234px -18px;}
			span.icon35 {background-position: -252px -18px;}
			span.icon36 {background-position: -270px -18px;}
			span.icon37 {background-position: -288px -18px;}
			span.icon38 {background-position: -306px -18px;}
			span.icon39 {background-position: -324px -18px;}
			span.icon40 {background-position: -342px -18px;}

			/* Sprite Row 3 */
			span.icon41 {background-position: -0px -36px;}
			span.icon42 {background-position: -18px -36px;}
			span.icon43 {background-position: -36px -36px;}
			span.icon44 {background-position: -54px -36px;}
			span.icon45 {background-position: -72px -36px;}
			span.icon46 {background-position: -90px -36px;}
			span.icon47 {background-position: -108px -36px;}
			span.icon48 {background-position: -126px -36px;}
			span.icon49 {background-position: -144px -36px;}
			span.icon50 {background-position: -162px -36px;}
			span.icon51 {background-position: -180px -36px;}
			span.icon52 {background-position: -198px -36px;}
			span.icon53 {background-position: -216px -36px;}
			span.icon54 {background-position: -234px -36px;}
			span.icon55 {background-position: -252px -36px;}
			span.icon56 {background-position: -270px -36px;}
			span.icon57 {background-position: -288px -36px;}
			span.icon58 {background-position: -306px -36px;}
			span.icon59 {background-position: -324px -36px;}
			span.icon60 {background-position: -342px -36px;}

			/* Sprite Row 4 */
			span.icon61 {background-position: -0px -54px;}
			span.icon62 {background-position: -18px -54px;}
			span.icon63 {background-position: -36px -54px;}
			span.icon64 {background-position: -54px -54px;}
			span.icon65 {background-position: -72px -54px;}
			span.icon66 {background-position: -90px -54px;}
			span.icon67 {background-position: -108px -54px;}
			span.icon68 {background-position: -126px -54px;}
			span.icon69 {background-position: -144px -54px;}
			span.icon70 {background-position: -162px -54px;}
			span.icon71 {background-position: -180px -54px;}
			span.icon72 {background-position: -198px -54px;}
			span.icon73 {background-position: -216px -54px;}
			span.icon74 {background-position: -234px -54px;}
			span.icon75 {background-position: -252px -54px;}
			span.icon76 {background-position: -270px -54px;}
			span.icon77 {background-position: -288px -54px;}
			span.icon78 {background-position: -306px -54px;}
			span.icon79 {background-position: -324px -54px;}
			span.icon80 {background-position: -342px -54px;}

			/* Sprite Row 5 */
			span.icon81 {background-position: -0px -72px;}
			span.icon82 {background-position: -18px -72px;}
			span.icon83 {background-position: -36px -72px;}
			span.icon84 {background-position: -54px -72px;}
			span.icon85 {background-position: -72px -72px;}
			span.icon86 {background-position: -90px -72px;}
			span.icon87 {background-position: -108px -72px;}
			span.icon88 {background-position: -126px -72px;}
			span.icon89 {background-position: -144px -72px;}
			span.icon90 {background-position: -162px -72px;}
			span.icon91 {background-position: -180px -72px;}
			span.icon92 {background-position: -198px -72px;}
			span.icon93 {background-position: -216px -72px;}
			span.icon94 {background-position: -234px -72px;}
			span.icon95 {background-position: -252px -72px;}
			span.icon96 {background-position: -270px -72px;}
			span.icon97 {background-position: -288px -72px;}
			span.icon98 {background-position: -306px -72px;}
			span.icon99 {background-position: -324px -72px;}
			span.icon100 {background-position: -342px -72px;}

			/* Sprite Row 6 */
			span.icon101 {background-position: -0px -90px;}
			span.icon102 {background-position: -18px -90px;}
			span.icon103 {background-position: -36px -90px;}
			span.icon104 {background-position: -54px -90px;}
			span.icon105 {background-position: -72px -90px;}
			span.icon106 {background-position: -90px -90px;}
			span.icon107 {background-position: -108px -90px;}
			span.icon108 {background-position: -126px -90px;}
			span.icon109 {background-position: -144px -90px;}
			span.icon110 {background-position: -162px -90px;}
			span.icon111 {background-position: -180px -90px;}
			span.icon112 {background-position: -198px -90px;}
			span.icon113 {background-position: -216px -90px;}
			span.icon114 {background-position: -234px -90px;}
			span.icon115 {background-position: -252px -90px;}
			span.icon116 {background-position: -270px -90px;}
			span.icon117 {background-position: -288px -90px;}
			span.icon118 {background-position: -306px -90px;}
			span.icon119 {background-position: -324px -90px;}
			span.icon120 {background-position: -342px -90px;}

			/* Sprite Row 7 */
			span.icon121 {background-position: -0px -108px;}
			span.icon122 {background-position: -18px -108px;}
			span.icon123 {background-position: -36px -108px;}
			span.icon124 {background-position: -54px -108px;}
			span.icon125 {background-position: -72px -108px;}
			span.icon126 {background-position: -90px -108px;}
			span.icon127 {background-position: -108px -108px;}
			span.icon128 {background-position: -126px -108px;}
			span.icon129 {background-position: -144px -108px;}
			span.icon130 {background-position: -162px -108px;}
			span.icon131 {background-position: -180px -108px;}
			span.icon132 {background-position: -198px -108px;}
			span.icon133 {background-position: -216px -108px;}
			span.icon134 {background-position: -234px -108px;}
			span.icon135 {background-position: -252px -108px;}
			span.icon136 {background-position: -270px -108px;}
			span.icon137 {background-position: -288px -108px;}
			span.icon138 {background-position: -306px -108px;}
			span.icon139 {background-position: -324px -108px;}
			span.icon140 {background-position: -342px -108px;}

			/* Sprite Row 8 */
			span.icon141 {background-position: -0px -126px;}
			span.icon142 {background-position: -18px -126px;}
			span.icon143 {background-position: -36px -126px;}
			span.icon144 {background-position: -54px -126px;}
			span.icon145 {background-position: -72px -126px;}
			span.icon146 {background-position: -90px -126px;}
			span.icon147 {background-position: -108px -126px;}
			span.icon148 {background-position: -126px -126px;}
			span.icon149 {background-position: -144px -126px;}
			span.icon150 {background-position: -162px -126px;}
			span.icon151 {background-position: -180px -126px;}
			span.icon152 {background-position: -198px -126px;}
			span.icon153 {background-position: -216px -126px;}
			span.icon154 {background-position: -234px -126px;}
			span.icon155 {background-position: -252px -126px;}
			span.icon156 {background-position: -270px -126px;}
			span.icon157 {background-position: -288px -126px;}
			span.icon158 {background-position: -306px -126px;}
			span.icon159 {background-position: -324px -126px;}
			span.icon160 {background-position: -342px -126px;}

			/* Sprite Row 9 */
			span.icon161 {background-position: -0px -144px;}
			span.icon162 {background-position: -18px -144px;}
			span.icon163 {background-position: -36px -144px;}
			span.icon164 {background-position: -54px -144px;}
			span.icon165 {background-position: -72px -144px;}
			span.icon166 {background-position: -90px -144px;}
			span.icon167 {background-position: -108px -144px;}
			span.icon168 {background-position: -126px -144px;}
			span.icon169 {background-position: -144px -144px;}
			span.icon170 {background-position: -162px -144px;}
			span.icon171 {background-position: -180px -144px;}
			span.icon172 {background-position: -198px -144px;}
			span.icon173 {background-position: -216px -144px;}
			span.icon174 {background-position: -234px -144px;}
			span.icon175 {background-position: -252px -144px;}
			span.icon176 {background-position: -270px -144px;}
			span.icon177 {background-position: -288px -144px;}
			span.icon178 {background-position: -306px -144px;}
			span.icon179 {background-position: -324px -144px;}
			span.icon180 {background-position: -342px -144px;}

			/* Sprite Row 10 */
			span.icon181 {background-position: -0px -162px;}
			span.icon182 {background-position: -18px -162px;}
			span.icon183 {background-position: -36px -162px;}
			span.icon184 {background-position: -54px -162px;}
			span.icon185 {background-position: -72px -162px;}
			span.icon186 {background-position: -90px -162px;}
			span.icon187 {background-position: -108px -162px;}
			span.icon188 {background-position: -126px -162px;}
			span.icon189 {background-position: -144px -162px;}
			span.icon190 {background-position: -162px -162px;}
			span.icon191 {background-position: -180px -162px;}
			span.icon192 {background-position: -198px -162px;}
			span.icon193 {background-position: -216px -162px;}
			span.icon194 {background-position: -234px -162px;}
			span.icon195 {background-position: -252px -162px;}
			span.icon196 {background-position: -270px -162px;}
			span.icon197 {background-position: -288px -162px;}
			span.icon198 {background-position: -306px -162px;}
			span.icon199 {background-position: -324px -162px;}
			span.icon200 {background-position: -342px -162px;}

			/*=============================
			 * TIP BUTTONS
			 * HTML MARKUP
			 * <div class="tiptip">
			 *  <a class="button" title="Home"><span class="icon icon108"></span></a>
			 * </div>
			 *=========OR=========
			 * <div class="tiptip">
			 *  <button title="Home"><span class="icon icon108"></span></button>
			 * </div>
			 *============================*/
			/* TipTip CSS - Version 1.2 (Modified) */

			#tiptip_holder {
				display: none;
				position: absolute;
				top: 0;
				left: 0;
				z-index: 99999;
			}

			#tiptip_holder.tip_top {
				padding-bottom: 5px;
			}

			#tiptip_holder.tip_bottom {
				padding-top: 5px;
			}

			#tiptip_holder.tip_right {
				padding-left: 5px;
			}

			#tiptip_holder.tip_left {
				padding-right: 5px;
			}

			#tiptip_content {
				font: bold 11px Helvetica, Arial, sans-serif;
				color: #FFF;
				padding: 7px;
				background: #000;
				border: 1px solid #FFF;
			}

			#tiptip_arrow, #tiptip_arrow_inner {
				position: absolute;
				border-color: transparent;
				border-style: solid;
				border-width: 6px;
				height: 0;
				width: 0;
			}

			#tiptip_holder.tip_top #tiptip_arrow {
				border-top-color: #fff;
			}

			#tiptip_holder.tip_bottom #tiptip_arrow {
				border-bottom-color: #fff;
			}

			#tiptip_holder.tip_right #tiptip_arrow {
				border-right-color: #fff;
			}

			#tiptip_holder.tip_left #tiptip_arrow {
				border-left-color: #fff;
			}

			#tiptip_holder.tip_top #tiptip_arrow_inner {
				margin-top: -7px;
				margin-left: -6px;
				border-top-color: #000;
			}

			#tiptip_holder.tip_bottom #tiptip_arrow_inner {
				margin-top: -5px;
				margin-left: -6px;
				border-bottom-color: #000;
			}

			#tiptip_holder.tip_right #tiptip_arrow_inner {
				margin-top: -6px;
				margin-left: -5px;
				border-right-color: #000;
			}

			#tiptip_holder.tip_left #tiptip_arrow_inner {
				margin-top: -6px;
				margin-left: -7px;
				border-left-color: #000;
			}

			/* Webkit Hacks  */
			@media screen and (-webkit-min-device-pixel-ratio:0) {	
				#tiptip_content {
					padding: 4px 8px 5px 8px;
					background-color: #000;
				}
				#tiptip_holder.tip_bottom #tiptip_arrow_inner { 
					border-bottom-color: #000;
				}
				#tiptip_holder.tip_top #tiptip_arrow_inner { 
					border-top-color: #000;
				}
			}

			/*==================================
			 *  ICON BUTTONS WITH LABEL
			 *  HTML MARKUP
			 *  <a class="button" href="#"><span class="icon icon4"></span><span class="label">Profile</span></a>
			 * ==========OR=======
			 * <button href="#"><span class="icon icon4"></span><span class="label">Profile</span></button>
			 *=================================*/
			 
			/*=================================
			 * DROPDOWN MENU
			 * HTML MARKUP
			 * <div class="dropdown">
			 *	<a href="#" class="button"><span class="label">File</span><span class="toggle"></span></a>
			 *	<div class="dropdown-slider">
			 *		<a href="#" class="ddm"><span class="label">New</span></a>
			 *		<a href="#" class="ddm"><span class="label">Save</span></a>
			 *	</div> 
			 * </div>
			 *============OR===========
			 * <div class="dropdown">
			 *   <a href="#" class="button"><span class="icon icon55"></span><span class="label">File</span><span class="toggle"></span></a>
			 *   <div class="dropdown-slider">
			 *     <a href="#" class="ddm"><span class="icon icon68"></span><span class="label">New</span></a>
			 *     <a href="#" class="ddm"><span class="icon icon92"></span><span class="label">Open</span></a>
			 *     <a href="#" class="ddm"><span class="icon icon67"></span><span class="label">Save</span></a>
			 *   </div> 
			 *  </div> 
			 *================================*/
			div.dropdown {
				float: left;
				position: relative;
			}

			div.dropdown span.toggle {
				width: 19px;
				height: 16px;
				
				margin-left: 7px;
				margin-top: 1px;
				margin-right: 2px;
				padding-left: 8px;
				
				float: right;
				
				background: url(../images/toggle.png) top right no-repeat;
				border-left: 1px solid #D9D9D9;
				
				-webkit-transition: border-color .20s;
				-moz-transition: border .20s;
				-o-transition: border-color .20s;
				transition: border-color .20s;
			}
			div.dropdown span.toggle.active {
				background: url(../images/toggle.png) bottom right no-repeat;
			}
			div.dropdown 
			button:hover span.toggle, 
			.button:hover span.toggle {
				border-color: #C0C0C0;
			}

			div.dropdown-slider {
				display: none;
				
				overflow: hidden;
				
				margin: 0 7px 5px 7px;
				position: absolute;
				top: 34px;
				right: 0;
				
				background: #F2F2F2;
				
				border-right: solid 1px #D9D9D9;
				border-bottom: solid 1px #D9D9D9;
				border-left: solid 1px #D9D9D9;
				
				-webkit-border-bottom-right-radius: 2px;
				-webkit-border-bottom-left-radius: 2px;
				-moz-border-radius-bottomright: 2px;
				-moz-border-radius-bottomleft: 2px;
				border-bottom-right-radius: 2px;
				border-bottom-left-radius: 2px;
				
				-webkit-transition: border-color .20s;
				-moz-transition: border .20s;
				-o-transition: border-color .20s;
				transition: border-color .20s;
			}
			.left div.dropdown-slider {
				margin: 0 1px 5px 7px;
			}
			.middle div.dropdown-slider {
				margin: 0 1px 5px 1px;
			}
			.right div.dropdown-slider {
				margin: 0 7px 5px 1px;
			}
			div.dropdown-slider .ddm {
				display: block;
				background: #F2F2F2;
				color: #585858;
				
				text-decoration: none;
				text-shadow: 0 1px 0 #fff;
				font: bold 11px Helvetica, Arial, sans-serif;
				line-height: 18px;
				height: 18px;
				
				margin: 0;
				padding: 5px 6px 4px 6px;
				width: 100%;
				float: left;
				
				border-top: 1px solid #FFF;
				border-bottom: 1px solid #D9D9D9;
			}
			div.dropdown-slider .ddm:hover {
				background: #F4F4F4;
				border-bottom-color: #C0C0C0;
			}
			div.dropdown-slider .ddm:active {
				border-bottom-color: #4D90FE;
				color: #4D90FE;
				
				-moz-box-shadow:inset 0 0 10px #D4D4D4;
				-webkit-box-shadow:inset 0 0 10px #D4D4D4;
				box-shadow:inset 0 0 10px #D4D4D4;
			}
			div.dropdown-slider .ddm:last-child {
				border-bottom: none;
			} 

		

最后希望大家喜欢这个“UI Button”。很抱歉上面没有附上DEMO效果,如果你喜欢的话可以点击下面的相应地址获取相关资源:

  1. DEMO在线地址:Google+ Styled Buttons
  2. GitHub下载地址:Downloads
  3. 本文代码下载地址:googlePlusButtons.rar
  4. 源码教程地址:Google+ UI Button教程
  5. 200Icons设计者:WebDesignShock

为了大家更好的学习有关于Button的制作,下面在为大家提供一些本站所汲及到有关Button制作的教程:

  1. CSS3 Gradient Buttons
  2. CSS3和HTML实体符制作带图片效果的Buttons
  3. LESS和CSS3动态制作按钮
  4. CSS3 Buttons框架
  5. CSS3伪元素应用——CSS3 Button
  6. Bootstrap Buttons
  7. input 按钮在IE下兼容问题
  8. 表单button的text-indent问题
  9. 表单button的outline问题
  10. 表单button的行高问题

那今天有关于“Google+ UI Button”就介绍到这里,如果你对按钮制作有更好的方法或者建议,请在下面的评论中直接与我们共享。

如需转载烦请注明出处:W3CPLUS

CSS制作图形速查表

$
0
0

前面在《纯CSS制作的图形效果》一文中介绍了十六种CSS画各种不同图形的方法。今天花了点时间将这方面的制作成一份清单,方便大家急用时有地方可查。别的不多说了,直接看代码。

为了节省时间,下面图形都采用的一个标签,可以是块元素也可以是行内元素,不过行内元素需要加上“display:block;”,唯一不同的是,在此用了不同的类名来区别,相关类名我放在了标题的后面,以便大家对应查看。

1、正方形(square):

CSS Code:

		.square {
			width: 100px;
			height:100px;
			background: #E5C3B2;
		}
	

上面的方法是,设置宽度和高度一致就可以实现正方形的效果,下面展示一种boder制作正方形的效果:

		.square {
			width:0;
			height:0;
			border: 50px solid  #E5C3B2;/*边框大小等于正方形宽度(或高度)的一半*/
		}
	

效果:

2、平行四边形(parallelogram)

CSS Code:

		.parallelogram {
			width: 100px;
			height: 70px;
			-webkit-transform: skew(20deg);
			-moz-transform: skew(20deg);
			-o-transform: skew(20deg);
			-ms-transform: skew(20deg);
			transform: skew(20deg);
			background: #E5C3B2;
		}
	

效果:

我们可以通过“skew”的值大小来控制角度,如果其值为负值,将会改变扭曲方向:

		.parallelogram2 {
			width: 100px;
			height: 70px;
			-webkit-transform: skew(-20deg);
			-moz-transform: skew(-20deg);
			-o-transform: skew(-20deg);
			-ms-transform: skew(-20deg);
			transform: skew(-20deg);
			background: #E5C3B2;
		}
	

效果:

3、菱形(diamond)

CSS Code:

		.diamond {
			width: 80px;
			height: 80px;
			margin: 40px 0 0 40px;
			-webkit-transform-origin: 0 100%;
			-moz-transform-origin: 0 100%;
			-o-transform-origin: 0 100%;
			-ms-transform-origin: 0 100%;
			transform-origin: 0 100%;
			-webkit-transform:rotate(-45deg);
			-moz-transform:rotate(-45deg);
			-o-transform:rotate(-45deg);
			-ms-transform:rotate(-45deg);
			transform:rotate(-45deg);
			background: #E5C3B2;
		}
	

效果:

4、长方形()

CSS Code:

		.rectangle {
			width: 100px;
			height: 50px;
			background: #E5C3B2;
		}
	

效果:

5、梯形(trapezoid)

梯形一

CSS Code:

		.trapezoid-1 {
			height: 0;
			width: 100px;
			border-bottom: 100px solid #e5c3b2;
			border-left: 60px solid transparent;
			border-right: 60px solid transparent;
		}
	

效果:

梯形二

CSS Code:

		.trapezoid-2 {
			height: 0;
			width: 100px;
			border-top: 100px solid #e5c3b2;
			border-left: 60px solid transparent;
			border-right: 60px solid transparent;
		}
	

效果:

梯形三

CSS Code:

		.trapezoid-3 {
			height: 100px;
			width: 0;
			border-right: 100px solid #e5c3b2;
			border-top: 60px solid transparent;
			border-bottom: 60px solid transparent;
		}
	

效果:

梯形四

CSS Code:

		.trapezoid-4 {
			height: 100px;
			width: 0;
			border-left: 100px solid #e5c3b2;
			border-top: 60px solid transparent;
			border-bottom: 60px solid transparent;
		}
	

效果:

6、三角形(triangle)

三角形朝上

CSS Code:

		.triangle-up {
			height: 0;
			width: 0;			
			border: 50px solid #e5c3b2;
			border-color: transparent transparent #e5c3b2 transparent;
		}		
	

效果:

三角朝右

CSS Code:

		.triangle-rihgt {
			height: 0;
			width: 0;
			border: 50px solid #e5c3b2;
			border-color: transparent  transparent transparent #e5c3b2;
		}		
	

效果:

三角朝下

CSS Code:

		.triangle-down {
			height: 0;
			width: 0;
			border: 50px solid #e5c3b2;
			border-color: #e5c3b2 transparent  transparent transparent;
		}		
	

效果:

三角朝左

CSS Code:

		.triangle-left {
			height: 0;
			width: 0;
			border: 50px solid #e5c3b2;
			border-color:  transparent #e5c3b2 transparent transparent;
		}
	

效果:

7、半圆(semicircle)

上半圆

CSS Code:

		.semicircle-top {
			background: #e5c3b2;
			height: 25px;
			width: 50px;			
			-moz-border-radius: 50px 50px 0 0;
			-webkit-border-radius: 50px 50px 0 0;
			border-radius: 50px 50px 0 0;
		}		
	

效果:

右半圆

CSS Code:

		.semicircle-right {
			background: #e5c3b2;
			height: 50px;
			width: 25px;			
			-moz-border-radius: 0 0px 50px 0;
			-webkit-border-radius:0 50px 50px 0;
			border-radius:0 50px 50px 0;
		}		
	

效果:

下半圆

CSS Code:

		.semicircle-down {
			background: #e5c3b2;
			height: 25px;
			width: 50px;			
			-moz-border-radius:0 0 50px 50px;
			-webkit-border-radius:0 0 50px 50px;
			border-radius:0 0 50px 50px;
		}		
	

效果:

左半圆

CSS Code:

		.semicircle-left {
			background: #e5c3b2;
			height: 50px;
			width: 25px;			
			-moz-border-radius:50px 0 0 50px;
			-webkit-border-radius:50px 0 0 50px;
			border-radius:50px 0 0 50px;
		}		
	

效果:

8、圆(circle)

CSS Code:

		.circle {
			background: #e5c3b2;
			height: 50px;
			width: 50px;			
			-moz-border-radius: 25px;
			-webkit-border-radius:25px;
			border-radius: 25px;
		}		
	

效果:

9、椭圆(oval)

水平椭圆

CSS Code:

		.ovalHor {
			background: #e5c3b2;
			height: 40px;
			width: 80px;			
			-moz-border-radius: 40px/20px;
			-webkit-border-radius:40px/20px;
			border-radius: 40px/20px;
		}		
	

效果:

垂直椭圆

CSS Code:

		.ovalVert {
			background: #e5c3b2;
			height: 80px;
			width: 40px;			
			-moz-border-radius: 20px/40px;
			-webkit-border-radius:20px/40px;
			border-radius: 20px/40px;
		}		
	

效果:

10、表图(chartColorful)

CSS Code:

		.chartColorful {
			height: 0px;
			width: 0px;
			border: 50px solid red;
			border-color: purple red yellow orange;
			-moz-border-radius: 50px;
			-webkit-border-radius:50px;
			border-radius: 50px;
		}		
	

效果:

11、四分之一圆(quarterCircle)

四分之一圆(上)

CSS Code:

		.quarterCircleTop {
			background: #e5c3b2;
			height: 50px;
			width: 50px;			
			-moz-border-radius: 50px 0 0 0;
			-webkit-border-radius: 50px 0 0 0;
			border-radius: 50px 0 0 0;
		}		
	

效果:

四分之一圆(右)

CSS Code:

		.quarterCircleRight {
			background: #e5c3b2;
			height: 50px;
			width: 50px;			
			-moz-border-radius: 0 50px 0 0;
			-webkit-border-radius: 0 50px 0 0;
			border-radius:0 50px 0 0;
		}			
	

效果:

四分之一圆(下)

CSS Code:

		.quarterCircleBottom {
			background: #e5c3b2;
			height: 50px;
			width: 50px;			
			-moz-border-radius: 0  0 50px 0;
			-webkit-border-radius: 0  0 50px 0;
			border-radius:0  0 50px 0;
		}			
	

效果:

四分之一圆(左)

CSS Code:

		.quarterCircleLeft {
			background: #e5c3b2;
			height: 50px;
			width: 50px;			
			-moz-border-radius: 0  0 0 50px;
			-webkit-border-radius: 0  0 0 50px;
			border-radius:0  0 0 50px;
		}			
	

效果:

12、Chart(quarterCircle)

Chart(上)

CSS Code:

		.chartTop {
			height: 0px;
			width: 0px;
			border:50px solid #e5c3b2;
			border-top-color: transparent;
			-moz-border-radius: 50px;
			-webkit-border-radius: 50px;
			border-radius: 50px;
		}		
	

效果:

Chart(右)

CSS Code:

		.chartRight{
			height: 0px;
			width: 0px;
			border:50px solid #e5c3b2;
			border-right-color: transparent;			
			-moz-border-radius: 50px;
			-webkit-border-radius: 50px;
			border-radius: 50px;
		}			
	

效果:

Chart(下)

CSS Code:

		.chartBottom {
			height: 0px;
			width: 0px;
			border:50px solid #e5c3b2;
			border-bottom-color: transparent;		
			-moz-border-radius: 50px;
			-webkit-border-radius: 50px;
			border-radius: 50px;
		}			
	

效果:

Chart(左)

CSS Code:

		.chartLeft {
			height: 0px;
			width: 0px;
			border:50px solid #e5c3b2;
			border-left-color: transparent;			
			-moz-border-radius: 50px;
			-webkit-border-radius: 50px;
			border-radius: 50px;
		}			
	

效果:

13、心形(heart)

左心形

CSS Code

		.heartLeft{
			width: 0;
			height: 0;
			border-color: red;
			border-style: dotted;
			border-width: 0 40px 40px 0;
		}
	

效果:

右心形

CSS Code

		.heartRight{
			width: 0;
			height: 0;
			border-color: red;
			border-style: dotted;
			border-width: 0  0 40px 40px;
		}
	

效果:

14、彩带(ribbon)

CSS Code

		.ribbon {
			width: 0;
			height: 100px;
			border-left: 50px solid red;
			border-right: 50px solid red;
			border-bottom: 35px solid transparent
		}
	

效果:

上面就用CSS制作的32种图形效果,当然大家还可以发挥你的想像和创造,制作一些更精美的图形。

扩展阅读:

  1. The Shapes of CSS
  2. Drawing with CSS3 Tips & little more
  3. 纯CSS制作的图形效果

那么今天就说到这里了,如果大家有更多的效果制作方法,请在下面的评论中分享。

如需转载烦清注明出处:W3CPLUS

CSS3和jQuery制作翻转表单

$
0
0

CSS3中的Transform应用可以说比较广泛了,但其中的3D Transforms去年就听说了,但一直没有使用过。今天在Tutorialzine看到了一篇这方面的教程《http://tutorialzine.com/2012/02/apple-like-login-form/》。自己动手试了一回,效果蛮好的。现在贴上来与大家一起分享。

这篇教程主要使用了CSS3中的3D transform属性和jQuery制作了一个翻转表单的效果。

思路

首先有两个表单(此处是“登录表单”和“找回密码表单”),高明之处是,仅仅只有一个表单呈现在大家面前。但当你点击了“ribbons”(本例中的“forget?”链接),将会触发表单在Y轴上旋转,此时背面的表单旋转到正面显示出来,当你在点击一次链接时,回到当初的表单,具体如下图所示:

在这个链接点击时,将使用jQuery事件给这两个“表单”的容器上添加一个类名,用来控制他们显示与隐藏。具体的请看下面的代码。

HTML Markup

结构很简单,只要两个“form”,具体“form”中的内容是什么?大家可以根据自己的需求去写,这里使用了“登录”和“找回密码”的两个表单:

		<div id="formContainer">
		  <form id="login" method="post" action="./">
		    <a href="#" id="flipToRecover" class="flipLink">Forgot?</a>
		    <input type="text" name="loginEmail" id="loginEmail" placeholder="Email" />
		    <input type="password" name="loginPass" id="loginPass" placeholder="Password" />
		    <input type="submit" name="submit" value="Login" />
		  </form>
		  <form id="recover" method="post" action="./">
		    <a href="#" id="flipToLogin" class="flipLink">Forgot?</a>
		    <input type="text" name="recoverEmail" id="recoverEmail" placeholder="Your Email" />
		    <input type="submit" name="submit" value="Recover" />
		  </form>
		</div>
	

CSS Code

		/*-------------------------
		Simple reset
		--------------------------*/
		*{
		margin:0;
		padding:0;
		}
		/*-------------------------
		General Styles
		--------------------------*/
		html{
		background:#161718;
		}
		body{
		min-height: 600px;
		padding: 200px 0 0;
		font:14px/1.3 'Segoe UI',Arial, sans-serif;
		}
		a, a:visited {
		text-decoration:none;
		outline:none;
		color:#54a6de;
		}
		a:hover{
		text-decoration:underline;
		}
		/*----------------------*\
		Form style
		\*----------------------*/

		#formContainer {
			width: 288px;
			height: 321px;
			margin: 0 auto;
			position: relative;
			-moz-perspective: 800px;
			-webkit-perspective: 800px;
			perspective: 800px;
		}
		#formContainer form {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			/*enabling 3d space for the transforms*/
			-moz-transform-style: preserve-3d;
			-webkit-transform-style: preserve-3d;
			transform-style: preserve-3d;
			/*when the forms are flipped, they will be hidden*/
			-moz-backface-visibility: hidden;
			-webkit-backface-visibility: hidden;
			backface-visibility: hidden;
			/*enabling a smooth animated transition*/
			-moz-transition: 0.8s;
			-webkit-transition: 0.8s;
			transition: 0.8s;
			/*configure a keyframe animation*/
			-moz-animation: pulse 2s infinite;
			-webkit-animation: pulse 2s infinite;
			animation: pulse 2s infinite;
		}
		#login {
			background: url(login_form_bg.jpg) no-repeat;
			z-index: 100;
		}
		#recover {
			background: url(recover_form_bg.jpg) no-repeat;
			z-index:1;
			opacity:0;
			/*rotating the recover password form by default*/
			-moz-transform:rotateY(180deg);
			-webkit-transform:rotateY(180deg);
			transform:rotateY(180deg);
		}
		/*firefox keyframe animation*/
		@-moz-keyframes pulse{
			0%{
				box-shadow: 0 0 1px #008aff;
			}
			50%{
				box-shadow: 0 0 8px #008aff;
			}
			100%{
				box-shadow: 0 0 1px #008aff;
			}
		}
		/*webkit keyframe animation*/
		@-webkit-keyframes pulse{
			0%{
				box-shadow: 0 0 1px #008aff;
			}
			50%{
				box-shadow: 0 0 8px #008aff;
			}
			100%{
				box-shadow: 0 0 1px #008aff;
			}
		}
		#formContainer.flipped #login {
			opacity:0;
			/*rotating the login form when the flipped class is added to the container*/
			-moz-transform: rotateY(-180deg);
			-webkit-transform: rotateY(-180deg);
			transform: rotateY(-180deg);
		}
		#formContainer.flipped #recover {
			opacity:1;
			/*rotating the recover div into view*/
			-moz-transform: rotateY(0deg);
			-webkit-transform: rotateY(0deg);
			transform: rotateY(0deg);
		}
		/*-------------------------------*\
		inputs,buttons,links
		\*-------------------------------*/
		#login .flipLink,
		#recover .flipLink{
			height: 65px;
			overflow:hidden;
			position: absolute;
			right:0;
			text-indent: -9999px;
			top: 0;
			width: 65px;
		}
		#recover .flipLink{
			right: auto;
			left: 0;
		}
		#login::after {
			width: 115px;
			height: 16px;
			content:"Click here to spin!";
			position: absolute;
			right: -120px;
			top: 22px;
			color: #fff;
		}
		input[type=text],
		input[type=password]{
			font: 15px "Segoe UI",Arial,sans-serif;
			border: none 0;
			background: none;
			height: 36px;
			left: 26px;
			position: absolute;
			top: 176px;
			width:234px;
			text-indent:8px;
			text-shadow: 1px 1px 1px rgba(0,0,0,0.3);
			color: #eee;
			outline: none;
		}
		#loginPass {
			top: 215px;
		}
		#recoverEmail {
			top: 215px;
		}
		input[type=submit]{
			/* Submit button */
			opacity:0.9;
			position:absolute;
			top:262px;
			left:25px;
			width: 239px;
			height:36px;
			cursor:pointer;
			border-radius:6px;
			box-shadow:0 1px 1px #888;
			border:none;
			color:#fff;
			font:14px/36px 'Segoe UI Light','Segoe UI',Arial,sans-serif;
			/* CSS3 Gradients */
			background-image: linear-gradient(bottom, rgb(80,102,127) 50%, rgb(87,109,136) 50%, rgb(106,129,155) 100%);
			background-image: -o-linear-gradient(bottom, rgb(80,102,127) 50%, rgb(87,109,136) 50%, rgb(106,129,155) 100%);
			background-image: -moz-linear-gradient(bottom, rgb(80,102,127) 50%, rgb(87,109,136) 50%, rgb(106,129,155) 100%);
			background-image: -webkit-linear-gradient(bottom, rgb(80,102,127) 50%, rgb(87,109,136) 50%, rgb(106,129,155) 100%);
			background-image: -ms-linear-gradient(bottom, rgb(80,102,127) 50%, rgb(87,109,136) 50%, rgb(106,129,155) 100%);
			background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0.5, rgb(80,102,127)),color-stop(0.5, rgb(87,109,136)),color-stop(1, rgb(106,129,155)));
			}
			input[type=submit]:hover{
			opacity:1;
			}
			input::-webkit-input-placeholder {
			color:#eee;
			}
	

上面就是此例使用的所用样式代码,但有几点我特意拿出来与大写一起看看。

1、perspective 透视的应用

首先在“form”的容器上使用了一个“perspective”透视效果。这个属性对定位元素或者变换的子元素进行和变换函数“perspective(number)”相同的变换。数值越小越能看得清楚,数值越大越不明显,具体大家可以通过“firebug”将这个属性的值调大调小,这样你就明白他的功能了。(^-^具体我也说不明白,自己测试一下吧):

		#formContainer{
			width:288px;
			height:321px;
			margin:0 auto;
			position:relative;

			-moz-perspective: 800px;
			-webkit-perspective: 800px;
			perspective: 800px;
		}
	

2、preserve-3d和backface的应用

		#formContainer form{
			width:100%;
			height:100%;
			position:absolute;
			top:0;
			left:0;

			/* Enabling 3d space for the transforms */
			-moz-transform-style: preserve-3d;
			-webkit-transform-style: preserve-3d;
			transform-style: preserve-3d;

			/* When the forms are flipped, they will be hidden */
			-moz-backface-visibility: hidden;
			-webkit-backface-visibility: hidden;
			backface-visibility: hidden;

			/* Enabling a smooth animated transition */
			-moz-transition:0.8s;
			-webkit-transition:0.8s;
			transition:0.8s;

			/* Configure a keyframe animation for Firefox */
			-moz-animation: pulse 2s infinite;

			/* Configure it for Chrome and Safari */
			-webkit-animation: pulse 2s infinite;
		}

		#login{
			background:url('login_form_bg.jpg') no-repeat;
			z-index:100;
		}

		#recover{
			background:url('recover_form_bg.jpg') no-repeat;
			z-index:1;
			opacity:0;

			/* Rotating the recover password form by default */
			-moz-transform:rotateY(180deg);
			-webkit-transform:rotateY(180deg);
			transform:rotateY(180deg);
		}
	

“preserve-3d”是3D transform中的“transform-style”中的样式之一,他设置内嵌的元素在 3D 空间如何呈现:保留 3D ,主要是用来给子元素创建一个“3D”场景,不过想要起作用,还是要配合“perspective”一起使用。

backface这个属性在这里作用很重要,设置进行转换的元素的背面在面对用户时是否可见:隐藏

3、flipped后的Form样式

		#formContainer.flipped #login{
			opacity:0;
			/**
			 * Rotating the login form when the
			 * flipped class is added to the container
			 */

			-moz-transform:rotateY(-180deg);
			-webkit-transform:rotateY(-180deg);
			transform:rotateY(-180deg);
		}

		#formContainer.flipped #recover{

			opacity:1;

			/* Rotating the recover div into view */
			-moz-transform:rotateY(0deg);
			-webkit-transform:rotateY(0deg);
			transform:rotateY(0deg);
		}
	

点击“ribbons”链接后,给表单容器添加一个类名“flipped”,“flipped”下的样式,将用来控制表单“#login”和“recover”进行Y轴的180度旋转。当“#login”表单是正面时,点击“链接”后,“#recover”表单将会旋转到正面,当“#recover”在正面时,点击“链接”后,将“#login”表单旋转到正面,依此类推。大家可以仔细看看,我们此处是两个表单正反面的旋转,而并不是隐藏其中一个,显示另外一个。

jQuery Code

		<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
		<script type="text/javascript">
			$(function(){
				//checking for css 3d transformation support
				$.support.css3d = supportsCSS3D();
				var formContainer = $("#formContainer");
				//Listening for clicks on the ribbon links
				$(".flipLink").click(function(e){
					//flipping the forms
					formContainer.toggleClass("flipped");
					//if there is no css3 3d support, simply hide the login form (exposing the recover one)
					if(!$.support.css3d){
						$("#login").toggle();
					}
					e.preventDefault();
				});
				
				formContainer.find("form").submit(function(e){
					//Preventing form submissions.if you implement a backedn,you will want to remove this code
					e.preventDefault();
				});
				
				//a helper function that checks for the support of the 3d css3 transformations
				function supportsCSS3D(){
					var props = ["perspectiveProperty","WebkitPerspective","MozPerspective"],testDom = document.createElement("a");
					for(var i = 0; i < props.length; i++){
						if(props[i] in testDom.style){
							return true;
						}
					}
					return false;
				}
			});
			
		</script>
	

上面就是本例使用到的所有jQuery代码了。大家可以看看。(^-^)我不太懂,所以不多说,怕误人子弟。这部分大家看代码吧,要比我说的更明白。

浏览器支持

如果你不使用IE浏览器,而是使用的现代浏览器“safari”、“chrome”、“firefox”这些浏览器对CSS3 3D都支持的比较好了。

DEMO

如果您没有看明白我说的(说实在的,我自己对那几个属性也还不完全理解),不仿看看DEMO效果:

当然,大家还可以下载源码到本地慢慢研究。或者参阅原教程。

这个实例是本站第一个有关于3D旋转方面的教程,说的不太明了,希望大家能根据原文进行了解,如果您有更好的建议,或者上文有不对的地方,还请大家告诉我,您可以直接在下面的评论中留言。

最后再次感谢Martin Angelov给我发的教程《Apple-like Login Form with CSS 3D Transforms》。

如需转载烦请注明出处:W3CPLUS

CSS3制作分享按钮

$
0
0

Nicolas GallagherPure CSS GUI icons中使用纯CSS3制作的各种ICON的DEMO,让我再次领会了CSS3的强大。

大家看到这个DEMO一定也会觉得CSS3很强大吧,同时也会自叹自己怎么就没有Nicolas Gallagher这种水平呢?其实只是自己没有他那样的思维,不敢去想,也不敢去尝试。别的不多说,说了也没意思,还是切入今天的主题吧。今天我在Nicolas Gallagher思路上也仿制了几个常见共享按钮的效果,希望大家喜欢。

看到上面的效果,大家肯定想看看是怎么实现的吧,那还等什么呢?直接往下看。

HTML Markup

这里的结构就很简单了,上面的DEMO仅采用了一个标签,你可以是HTML中的任何标签,不过此处为了说明DEMO的实现,我采用的是一个列表形式。

			<ul>
			  <li class="facebook"><a href="#non" title="Share on Facebook">Facebook</a></li>
			  <li class="twitter"><a href="#non" title="Share on Twitter">Twitter</a></li>
			  <li class="rss"><a href="#non" title="Subscribe to the RSS feed">RSS</a></li>
			  <li class="flickr"><a href="#non" title="Share on Flickr">Flickr</a></li>
			  <li class="delicious"><a href="#non" title="Bookmark on Delicious">Delicious</a></li>
			  <li class="linkedin"><a href="#non" title="Share on LinkedIn">LinkedIn</a></li>
			  <li class="google"><a href="#non" title="Bookmark with Google">Google</a></li>
			  <li class="orkut"><a href="#non" title="Share on Orkut">Orkut</a></li>
			  <li class="technorati"><a href="#non" title="Add to Technorati">Technorati</a></li>
			  <li class="netvibes"><a href="#non" title="Add to NetVibes">NetVibes</a></li>
			  <li class="google-plus"><a href="#non" title="Add to google+">Google+</a></li>
			  <li class="yahoo"><a href="#non" title="Add to yahoo">Yahoo</a></li>
			  <li class="tumblr"><a href="#non" title="Add to tumblr">Tumblr</a></li>
			</ul>
		

在具体写每个按钮之前,先给这些按钮一些基本样式

Base Css

			body {
				padding:0; 
				margin:0; 
				font:1em/1.4 Cambria, Georgia, sans-serif; color:#333; 
				background:#fff;
			}
			ul {
				list-style:none;
				padding:0;
				margin:0;
				overflow:hidden;
				font:0.875em/1 Arial, sans-serif;
			}

			ul li {
				float:left;
				width:66px;
				height:66px;
				margin:20px 20px 0 0;
			}

			ul li a {
				display:block;
				width:64px;
				height:64px;
				overflow:hidden;
				border:1px solid transparent;
				line-height:64px;
				text-decoration:none;
				border-radius:5px; 
			}

			ul li a:hover,
			ul li a:focus,
			ul li a:active {
				opacity:0.8;
				border-color:#000;
			}
		

接下来分别看看每个按钮的代码:

一、Facebook

			.facebook a {
        position: relative;
        border-color: #3c5a98;
        text-transform: lowercase;
        text-indent: 34px;
        letter-spacing: 10px;
        font-weight: bold;
				font-size: 64px;
        line-height: 66px;
        color: #fff;
        background: #3c5a98;
        box-shadow: 0 0 4px rgba(0,0,0,0.4);
      }
		

Facebook这个按钮是相当的简单,没有什么特别之处。在这个效果中,采用了“text-indent”来控制文字的显示位置,“letter-spacing”配合“li”中的“overflow”来隐藏其他的字母(这样的使用在后面的按钮中都有或多或少的用到)。

二、Twitter

        .twitter a {
            position: relative;
            border-color: #a8eaec;
            text-indent: 20px;
            letter-spacing: 40px;
            font: bold 60px/1 Tahoma,sans-serif;
            line-height: 60px;
            background: #daf6f7;
            text-shadow: 3px 3px 1px #fff, -3px -3px 1px #fff, 3px -3px 1px #fff, -3px 3px 1px #fff;
            box-shadow: 0 0 4px rgba(0,0,0,0.4);
            background-image: -webkit-gradient(linear, left top,left bottom,from(#dbf7f8),to(#88e1e6));
            background-image: -webkit-linear-gradient(top,#dbf7f8,#88e1e6);
            background-image: -moz-linear-gradient(top,#dbf7f8,#88e1e6);
            background-image: -o-linear-gradient(top,#dbf7f8,#88e1e6);
            background-image: -ms-linear-gradient(top,#dbf7f8,#88e1e6);
            background-image: linear-gradient(top,#dbf7f8,#88e1e6);
            text-transform: lowercase;
            color: #76ddf8;
        }
		

Twitter按钮的效果有两个关键之处,给文字使用了多重文字阴影,而且背景使用的是渐变制作。

三、RSS

			.rss a {
            position: relative;
            width: 60px;
            padding: 0 2px;
            border-color: #ea6635;
            text-transform: lowercase;
            text-indent: -186px;
            font-size: 64px;
            font-weight: bold;
            background: #e36443;
            box-shadow: 0 0 4px rgba(0,0,0,0.4);
            background-image: -webkit-gradient(linear,left top, left bottom,from(#f19242),to(#e36443));
            background-image: -webkit-linear-gradient(top,#f19242,#e36443);
            background-image: -moz-linear-gradient(top,#f19242,#e36443);
            background-image: -o-linear-gradient(top,#f19242,#e36443);
            background-image: -ms-linear-gradient(top,#f19242,#e36443);
            background-image: linear-gradient(top,#f19242,#e36443);
        }
				/*圆点*/
        .rss a::before {
            content:"\00a0";
            position: absolute;
            bottom: 10px;
            left: 10px;
            width: 12px;
            height: 12px;
            background: #fff;
            border-radius: 12px;
        }
				/*弧形*/
        .rss a::after {
            content:"\00a0";
            position: absolute;
            bottom: 10px;
            left: 10px;
            height: 22px;
            width: 22px;
            border: 24px double #fff;
            border-width: 24px 24px 0 0;
            border-radius: 0 50px 0 0;
        }
		

RSS制作效果相对来说复杂一些了,在“a”元素上制作了按钮的背景色,而其中圆点和两个弧形是通过CSS3的伪元素实现的。

四、Flickr

       .flickr a {
            position:relative;
            border-color:#d2d2d2;
            text-indent:-9000px;
            font-size:108px;
            font-weight:bold;
            color:#fff;
            background:#fff;    
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#fff), to(#d2d2d2));
            background-image:-webkit-linear-gradient(top, #fff, #d2d2d2);
            background-image:-moz-linear-gradient(top, #fff, #d2d2d2);
            background-image:-o-linear-gradient(top, #fff, #d2d2d2);
            background-image:-ms-linear-gradient(top, #fff, #d2d2d2);
            background-image:linear-gradient(top, #fff, #d2d2d2);
        }
				/*蓝色圆点*/
        .flickr a::before {
            content:"\00a0";
            position:absolute;
            top:50%;
            left:30%;
            width:20px;
            height:20px;
            margin:-10px 0 0 -10px;
            background:#085ec5;
            border:1px solid #003c84;
            border-radius: 20px;
            background-image:-webkit-gradient(linear, left top, left bottom, from(#005cc6), to(#003d83));
            background-image:-webkit-linear-gradient(top, #005cc6, #003d83);
            background-image:-moz-linear-gradient(top, #005cc6, #003d83);
            background-image:-o-linear-gradient(top, #005cc6, #003d83);
            background-image:-ms-linear-gradient(top, #005cc6, #003d83);
            background-image:linear-gradient(top, #005cc6, #003d83);
        }
				/*红色圆点*/
        .flickr a::after {
            content:"\00a0";
            position:absolute;
            top:50%;
            right:30%;
            width:20px;
            height:20px;
            margin:-10px -10px 0 0;
            border:1px solid #ba0060;
            background:#fd1e93;
            border-radius:20px;
            background-image:-webkit-gradient(linear, left top, left bottom, from(#fd1e93), to(#cb026c));
            background-image:-moz-linear-gradient(top, #fd1e93, #cb026c);
            background-image: -webkit-linear-gradient(top, #fd1e93, #cb026c);
            background-image: -o-linear-gradient(top, #fd1e93, #cb026c);
            background-image: -ms-linear-gradient(top, #fd1e93, #cb026c);
            background-image: linear-gradient(top, #fd1e93, #cb026c);
        }
		

Flickr上的两上圆点效果也是通过伪元素实现:“::before”制作了蓝点,“::after”制作了粉红点。

五、Delicious

			.delicious a {
            position:relative;
            border-color:#d2d2d2;    
            text-align:center;
            text-indent:-9000px;
            font-size:108px;
            font-weight:bold;
            color:#fff;
            background:#fff;    
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#fff), to(#d1d1d1));
            background-image:-webkit-linear-gradient(top, #fff, #d1d1d1);
            background-image:-moz-linear-gradient(top, #fff, #d1d1d1);
            background-image:-o-linear-gradient(top, #fff, #d1d1d1);
            background-image:-ms-linear-gradient(top, #fff, #d1d1d1);
            background-image:linear-gradient(top, #fff, #d1d1d1);
        }
				/*右上角蓝色方块*/
        .delicious a::before {
            content:"\00a0";
            position:absolute;
            top:0;
            right:0;
            width:30px;
            height:30px;
            border:1px solid #0060ce;
            background:#085ec5;
            border-radius:0 4px 0 0;
            background-images:-webkit-gradient(linear, left top, left bottom, from(#0060ce)), to(#003b7f));
            background-images:-webkit-linear-gradient(top, #0060ce, #003b7f);
            background-images:-moz-linear-gradient(top, #0060ce, #003b7f);
            background-images:-o-linear-gradient(top, #0060ce, #003b7f);
            background-images:-ms-linear-gradient(top, #0060ce, #003b7f);
            background-images:linear-gradient(top, #0060ce, #003b7f);
        }
				/*左下角黑色方块*/
        .delicious a::after {
            content:"\00a0";
            position:absolute;
            bottom:0;
            left:0;
            width:30px;
            height:30px;
            border:1px solid #000;
            background:#000;
            border-radius: 0 0 0 4px;
            background-image:-webkit-gradient(linear, left top, left bottom, from(#212121), to(#000));
            background-image:-webkit-linear-gradient(top, #212121, #000);
            background-image:-moz-linear-gradient(top, #212121, #000);
            background-image:-o-linear-gradient(top, #212121, #000);
            background-image:-ms-linear-gradient(top, #212121, #000);
            background-image:linear-gradient(top, #212121, #000);
        }
		

六、Linkedin

			.linkedin a {
            position:relative;
            width:60px;
            overflow:hidden;
            padding:0 2px;
            border-color:#185c80;
            text-transform:lowercase;
            text-indent:-185px;
            font-size:64px;
            font-weight:bold;
            color:#fff;
            background:#0c6596;
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#5babcb), to(#0c6596));
            background-image:-webkit-linear-gradient(top, #5babcb, #0c6596);
            background-image:-moz-linear-gradient(top, #5babcb, #0c6596);
            background-image:-ms-linear-gradient(top, #5babcb, #0c6596);
            background-image:-o-linear-gradient(top, #5babcb, #0c6596);
            background-image:linear-gradient(top, #5babcb, #0c6596);
        }
		

七、Google

			.google a {
            position:relative;
            border-color:#26478d;
            text-transform:lowercase;
            text-indent:16px;
            letter-spacing:40px;
            font: 65px/44px Georgia, Times New Roman, Times, serif;
            color:#fff;
            background:#1e3c7f;
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#447aec), to(#1e3c7f));
            background-image:-webkit-linear-gradient(top, #447aec, #1e3c7f);
            background-image:-moz-linear-gradient(top, #447aec, #1e3c7f);
            background-image:-o-linear-gradient(top, #447aec, #1e3c7f);
            background-image:-ms-linear-gradient(top, #447aec, #1e3c7f);
            background-image:linear-gradient(top, #447aec, #1e3c7f);
        }
		

八、Orkut

			.orkut a {
            position:relative;
            border-color:#b4c4dd;
            text-indent:-9000px;
            font-size:108px;
            color:#b62b91;
            background:#fff;
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#fff), to(#ceddf6));
            background-image:-webkit-linear-gradient(top, #fff, #ceddf6);
            background-image:-moz-linear-gradient(top, #fff, #ceddf6);
            background-image:-o-linear-gradient(top, #fff, #ceddf6);
            background-image:-ms-linear-gradient(top, #fff, #ceddf6);
            background-image:linear-gradient(top, #fff, #ceddf6);
        }
				/*粉红色圆*/
        .orkut a::before {
            content:"\00a0";
            position:absolute;
            top:50%;
            left:50%;
            width:40px;
            height:40px;
            border:1px solid #b0699e;
            margin:-21px 0 0 -21px;
            background:#d779c0;
            border-radius:40px;
            box-shadow:0 0 2px rgba(0,0,0,0.6);
        }
				/*白色圆*/
        .orkut a::after {
            content:"\00a0";
            position:absolute;
            top:50%;
            left:50%;
            width:26px;
            height:26px;
            margin:-13px 0 0 -13px;
            background:#fff;
            border-radius:26px;
            box-shadow: 0 0 2px rgba(0,0,0,0.6);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#eff4fc), to(#dce6f8));
            background-image:-webkit-linear-gradient(top, #eff4fc, #dce6f8);
            background-image:-moz-linear-gradient(top, #eff4fc, #dce6f8);
            background-image:-o-linear-gradient(top, #eff4fc, #dce6f8);
            background-image:-ms-linear-gradient(top, #eff4fc, #dce6f8);
            background-image:linear-gradient(top, #eff4fc, #dce6f8);
        }
		

九、Technorati

			.technorati a {
            position:relative;
            border-color:#266F12;
            text-indent:-9000px;
            font-size:108px;
            color:#b62b91;
            background:#086B04;     
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#a3d679), to(#086b04));
            background-image:-webkit-linear-gradient(top, #a3d679, #086b04);
            background-image:-moz-linear-gradient(top, #a3d679, #086b04);
            background-image:-o-linear-gradient(top, #a3d679, #086b04);
            background-image:-ms-linear-gradient(top, #a3d679, #086b04);
            background-image:linear-gradient(top, #a3d679, #086b04);
        }
				/*白色圆*/
        .technorati a::before {
            content:"\00a0";
            position:absolute;
            top:5px;
            right:-5px;
            width:40px;
            height:25px;
            border:8px solid #f5f5f5;
            border-radius:45px / 35px;
            box-shadow:0 0 2px rgba(0,0,0,0.6);
        }
				/*白色三角*/
        .technorati a::after {
            content:"\00a0";
            position:absolute;
            top:40px;
            left:20px;
            width:0;
            height:0;
            border-width:0 0 18px 13px;
            border-style:solid;
            border-color:transparent #f5f5f5;
        }
		

十、Netvibes

			.netvibes a {
            position:relative;
            border-color:#0c5f0c;
            text-align:center;
            text-indent:-9000px;
            font-size: 178px;
            font-weight:bold;
            color:#fff;
            background:#138210;
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#68db21), to(#138210));
            background-image:-webkit-linear-gradient(top, #68db21, #138210);
            background-image:-moz-linear-gradient(top, #68db21, #138210);
            background-image:-o-linear-gradient(top, #68db21, #138210);
            background-image:-ms-linear-gradient(top, #68db21, #138210);
            background-image:linear-gradient(top, #68db21, #138210);
        }
				/*白色+号*/
        .netvibes a::after {
            content:"+";
            position:absolute;
            left:0;
            top:0;
            width:64px;
            text-indent:0;
            text-align:center;    
            font-size:88px;
            color:#fff;
        }
		

十一、Google+

			.google-plus a {
            position:relative;
            border-color:#C4695F;
            text-transform:lowercase;
            text-indent:-5px;
            letter-spacing:40px;
            font: 96px/31px Georgia, Times New Roman, Times, serif;
            color:#fff;
            background:#1e3c7f;
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#D43D2A), to(#A92B1D));
            background-image:-webkit-linear-gradient(top, #D43D2A, #A92B1D);
            background-image:-moz-linear-gradient(top, #D43D2A, #A92B1D);
            background-image:-o-linear-gradient(top, #D43D2A, #A92B1D);
            background-image:-ms-linear-gradient(top, #D43D2A, #A92B1D);
            background-image:linear-gradient(top, #D43D2A, #A92B1D);
        }
				/*右边+号*/
        .google-plus a::before {
            content: "+";
            font-size: 46px;
            left: 43px;
            position: absolute;
            top: -6px;
        }
		

十二、Yahoo

			.yahoo a {
            position:relative;
            border-color:#971278;
            text-transform:uppercase;
            text-indent:3px;
            letter-spacing:40px;
            font: 65px/66px Georgia, Times New Roman, Times, serif;
            color:#fff;
            background:#1e3c7f;
            box-shadow:0 0 4px rgba(0,0,0,0.4);
            background-image:-webkit-gradient(linear, left top, left bottom, from(#C639C2), to(#9E2999));
            background-image:-webkit-linear-gradient(top, #C639C2, #9E2999);
            background-image:-moz-linear-gradient(top, #C639C2, #9E2999);
            background-image:-o-linear-gradient(top, #C639C2, #9E2999);
            background-image:-ms-linear-gradient(top, #C639C2, #9E2999);
            background-image:linear-gradient(top, #C639C2, #9E2999);
        }
				/*右边!号*/
        .yahoo a::before {
            -moz-transform: rotate(19deg);
            -webkit-transform: rotate(19deg);
            -ms-transform: rotate(19deg);
            -o-transform: rotate(19deg);
            transform: rotate(19deg);
            content: "!";
            font-family: Arial;
            left: 34px;
            position: absolute;
            top: 7px;
        }
		

十三、Tumblr

			.tumblr a {
            position: relative;
            border-color: #425B6E;
            text-indent: 24px;
            letter-spacing: 40px;
            font:  60px/1 Tahoma,sans-serif;
            line-height: 60px;
            background: #daf6f7;
            text-shadow: 1px 0px 1px #FFFFFF, -2px -1px 1px #FFFFFF, 0px -1px 1px #FFFFFF, -2px -1px 1px #FFFFFF;
            box-shadow: 0 0 4px rgba(0,0,0,0.4);
            background-image: -webkit-gradient(linear, left top,left bottom,from(#29486A),to(#253F5B));
            background-image: -webkit-linear-gradient(top,#29486A,#253F5B);
            background-image: -moz-linear-gradient(top,#29486A,#253F5B);
            background-image: -o-linear-gradient(top,#29486A,#253F5B);
            background-image: -ms-linear-gradient(top,#29486A,#253F5B);
            background-image: linear-gradient(top,#29486A,#253F5B);
            text-transform: lowercase;
            color: #fff;
        }
		

上面给大家展示的是共享按钮中的十三个效果而以,大家也可以发挥自己的想像和创造力,去绘制更多的效果,就当是练习CSS3的属性运用吧。下面在给大家展示一个由TjRus用纯CSS3制作的iPhone4手机模型:

上面DEMO纯样式制作,没有图片的,是不是更让你自叹了,其实没事的,你要相信自己,总有一天自己也行。如果你想一控究竟,那就快动手吧。

那么今天就说到这了,希望大家喜欢这个教程,如果你有更好的创建不仿在下面的评论中留下您的足迹与大家一起分享。

如需转载烦请注明出处:W3CPLUS

css3制作3D分页导航

$
0
0

前面本站介绍了站上分页导航效果,今天在给大家推荐一个纯CSS制作的分布导航效果,这个效果中没有使用任何图片,并使用jQuery实现了“active”的效果。还有一个特别之处就是使用了WebSymbolsRegular制作了向前向后的箭头效果。

目标

今天我们的目标就是使用纯CSS来制作上图的一个分面导航的效果。

HTML Markup

这个效果用到的HTML结构就相当的简单了,就是一个容器“div#pager”里面放了一些“a”链接标签:

			<div id="pager">
			  <a href="javascript:void(0)">(</a>
			  <a href="javascript:void(0)"  class="on">1</a>
			  <a href="javascript:void(0)">2</a>
			  <a href="javascript:void(0)">3</a>
			  <a href="javascript:void(0)">4</a>
			  <a href="javascript:void(0)">5</a>
			  <a href="javascript:void(0)">6</a>
			  <a href="javascript:void(0)">)</a>
			</div>
		

在当前页上加了一个“on”类名,当然大家也可以根据自己的习惯加别的类名,比如说“active”或者“current”等。

CSS Code

			@font-face{ 
			font-family: 'WebSymbolsRegular';
			src: url('fonts/websymbols-regular-webfont.eot');
			src: url('fonts/websymbols-regular-webfont.eot?#iefix') format('embedded-opentype'),
					 url('fonts/websymbols-regular-webfont.woff') format('woff'),
					 url('fonts/websymbols-regular-webfont.ttf') format('truetype'),
					 url('fonts/websymbols-regular-webfont.svg#WebSymbolsRegular') format('svg');
		}
		#pager {
    position:relative;
    display:block;
    overflow: visible;
    display: inline-block;
    }
		#pager a {
    font: bold 20px/30px Tahoma, Arial;
    cursor: pointer;
    text-decoration: none;
    color: #464646;
    display: block;
    float: left;
    margin-right: 1px;
    box-shadow:
    inset rgba(0,0,0,0.1) 0 1px 0,
    inset rgba(255,255,255,0.7) 0 2px 0,
    inset rgba(255,255,255,0.7) 0 -1px 0,
    inset rgba(255,255,255,0.7) 1px 0 0,
    inset rgba(255,255,255,0.7) -1px 0 0,
    rgba(0,0,0,0.3) 0 3px 0;
    padding: 2px 10px;
    min-width: 10px;
    text-align: center;
    position: relative;
    text-shadow: #fff 0 1px 0;
    background: #cdcdcd;
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(255,255,255,0.8)), to(rgba(200,200,200,0.9)));
    background: -webkit-linear-gradient(top, rgba(255,255,255,0.8), rgba(200,200,200,0.9));
    background: -moz-linear-gradient(top, rgba(255,255,255,0.8), rgba(200,200,200,0.9));
    background: -ms-linear-gradient(top, rgba(255,255,255,0.8), rgba(200,200,200,0.9));
    background: -o-linear-gradient(top, rgba(255,255,255,0.8), rgba(200,200,200,0.9));
    }
     
    #pager a:after {
    content: '';
    position: absolute;
    bottom: -3px;
    height: 100%;
    display: block;
    width: 100%;
    left: 0;
    box-shadow: inset rgba(255,255,255,0.2) 1px 0 0, inset rgba(255,255,255,0.2) -1px 0 0, rgba(0,0,0,0.4) 0 1px 0;
    }
     
    #pager a:first-child::after {
    border-radius: 500px 0 0 500px;
    }
     
    #pager a:last-child::after {
    border-radius: 0 50px 50px 0;
    }
     
    #pager a.on:after {
    bottom: -1px;
    }
     
    #pager a:before {
    content: '';
    position: absolute;
    top: 1px;
    height: 100%;
    box-shadow: rgba(0,0,0,0.4) 0 3px 0;
    width: 1px;
    display: block;
    background: rgba(0,0,0,0.4);
    right: -1px;
    }
     
    #pager a:last-child::before {
    display: none !important;
    }
     
    #pager a:first-child {
    border-radius:50px 0 0 50px;
    font-family: 'WebSymbolsRegular';
    }
     
    #pager a:last-child {
    border-radius:0 50px 50px 0;
    font-family: 'WebSymbolsRegular';
    }
     
    #pager a:hover {
    box-shadow:
    inset rgba(0,0,0,0.1) 0 1px 0,
    inset rgba(255,255,255,0.7) 0 2px 0,
    inset rgba(255,255,255,0.7) 0 -1px 0,
    inset rgba(255,255,255,0.7) 1px 0 0,
    inset rgba(255,255,255,0.7) -1px 0 0,
    inset rgba(255,255,255,1) 0 0 15px,
    rgba(0,0,0,0.2) 0 3px 0;    
    }
     
    #pager a:active {
    box-shadow:
    inset rgba(0,0,0,0.1) 0 1px 0,
    inset rgba(0,0,0,0.3) 1px 0 0px,
    inset rgba(0,0,0,0.3) -1px 0 0px,
    inset rgba(255,255,255,0.7) 0 2px 0,
    inset rgba(255,255,255,0.7) 0 -1px 0,
    inset rgba(0,0,0,0.1) 0 0 15px,
    rgba(0,0,0,0.2) 0 2px 0;
    top: 1px;
    text-shadow: #fff 0 0 15px;
    }
     
    #pager a:active:after {
    bottom:-2px;
    }
     
    #pager a:active:before {
    box-shadow: rgba(0,0,0,0.4) 0 2px 0;
    top: 0px;
    }
     
    #pager a.on {
    box-shadow:
    inset rgba(0,0,0,0.1) 0 1px 0,
    inset rgba(0,0,0,0.3) 1px 0 0px,
    inset rgba(0,0,0,0.3) -1px 0 0px,
    inset rgba(255,255,255,0.7) 0 2px 0,
    inset rgba(255,255,255,0.7) 0 -1px 0,
    inset rgba(0,0,0,0.1) 0 0 15px,
    rgba(0,0,0,0.3) 0 1px 0;
    top: 2px;
    text-shadow: #fff 0 0 15px;
    }
     
    #pager a.on:before {
    box-shadow: rgba(0,0,0,0.4) 0 3px 0;
    top: -1px;
    }
     
    #pager a.on:active:after {
    bottom:-1px;
    }
		

上面的样式,有几个关键之处想和大家一起分享:

1、web实体符

上面效果中的向前向后按钮,我们并没有使用任何图片,而是使用的web实体符。使用web实体符需要两点:首先在WebSymbolsRegular中下载WebSymbols-Font-Pack.zip文件包,你也可以下载WebSymbols-Regular.otf.zip字体包;然后使用@font-face调用web实体符字体

			@font-face{ 
				font-family: 'WebSymbolsRegular';
				src: url('fonts/websymbols-regular-webfont.eot');
				src: url('fonts/websymbols-regular-webfont.eot?#iefix') format('embedded-opentype'),
						 url('fonts/websymbols-regular-webfont.woff') format('woff'),
						 url('fonts/websymbols-regular-webfont.ttf') format('truetype'),
						 url('fonts/websymbols-regular-webfont.svg#WebSymbolsRegular') format('svg');
			}	
		

这样一来,你就可以在需要使用的地方调用这个“WebSymbolsRegular”字体:

			#pager a:first-child {
			border-radius:50px 0 0 50px;
			font-family: 'WebSymbolsRegular';
			}
			 
			#pager a:last-child {
			border-radius:0 50px 50px 0;
			font-family: 'WebSymbolsRegular';
			}
		

2、立体效果

大家都看到上面的导航具有立体效果,其实这也是CSS3中“box-shadow”实现的。如果您有关注本站的话,在前面的CSS3 Buttons框架中有介绍一个仿BonBon3D Css3 Buttons效果。其实我们此处的3D效果也是类似这样的原理:

			#pager a {
    font: bold 20px/30px Tahoma, Arial;
    cursor: pointer;
    text-decoration: none;
    color: #464646;
    display: block;
    float: left;
    margin-right: 1px;
		
    box-shadow:
    inset rgba(0,0,0,0.1) 0 1px 0,
    inset rgba(255,255,255,0.7) 0 2px 0,
    inset rgba(255,255,255,0.7) 0 -1px 0,
    inset rgba(255,255,255,0.7) 1px 0 0,
    inset rgba(255,255,255,0.7) -1px 0 0,
    rgba(0,0,0,0.3) 0 3px 0;
		
    padding: 2px 10px;
    min-width: 10px;
    text-align: center;
    position: relative;
    text-shadow: #fff 0 1px 0;
    background: #cdcdcd;
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(255,255,255,0.8)), to(rgba(200,200,200,0.9)));
    background: -webkit-linear-gradient(top, rgba(255,255,255,0.8), rgba(200,200,200,0.9));
    background: -moz-linear-gradient(top, rgba(255,255,255,0.8), rgba(200,200,200,0.9));
    background: -ms-linear-gradient(top, rgba(255,255,255,0.8), rgba(200,200,200,0.9));
    background: -o-linear-gradient(top, rgba(255,255,255,0.8), rgba(200,200,200,0.9));
    }
     
    #pager a:after {
    content: '';
    position: absolute;
    bottom: -3px;
    height: 100%;
    display: block;
    width: 100%;
    left: 0;
		
    box-shadow: inset rgba(255,255,255,0.2) 1px 0 0, inset rgba(255,255,255,0.2) -1px 0 0, rgba(0,0,0,0.4) 0 1px 0;
			
		}
    #pager a:before {
    content: '';
    position: absolute;
    top: 1px;
    height: 100%;
		
    box-shadow: rgba(0,0,0,0.4) 0 3px 0;
		
    width: 1px;
    display: block;
    background: rgba(0,0,0,0.4);
    right: -1px;
    }
		

3、hover和active效果

另外使用伪类制作了悬浮和按下那刻的效果。

			#pager a:hover {
				box-shadow:
				inset rgba(0,0,0,0.1) 0 1px 0,
				inset rgba(255,255,255,0.7) 0 2px 0,
				inset rgba(255,255,255,0.7) 0 -1px 0,
				inset rgba(255,255,255,0.7) 1px 0 0,
				inset rgba(255,255,255,0.7) -1px 0 0,
				inset rgba(255,255,255,1) 0 0 15px,
				rgba(0,0,0,0.2) 0 3px 0;    
				}
				 
				#pager a:active {
				box-shadow:
				inset rgba(0,0,0,0.1) 0 1px 0,
				inset rgba(0,0,0,0.3) 1px 0 0px,
				inset rgba(0,0,0,0.3) -1px 0 0px,
				inset rgba(255,255,255,0.7) 0 2px 0,
				inset rgba(255,255,255,0.7) 0 -1px 0,
				inset rgba(0,0,0,0.1) 0 0 15px,
				rgba(0,0,0,0.2) 0 2px 0;
				top: 1px;
				text-shadow: #fff 0 0 15px;
				}
				 
				#pager a:active:after {
				bottom:-2px;
				}
				 
				#pager a:active:before {
				box-shadow: rgba(0,0,0,0.4) 0 2px 0;
				top: 0px;
				}
		

4、当前页的效果

这里使用jQuery的“click”事件,当你点击页面时会给点击项添加一个“on”类名,同时移除相邻元素的“on”类名,并配合相关样式实现了当前页的效果:

jQuery Code

			$(document).ready(function(){
			 $("#pager a").click(function(){
			  $(this).addClass("on").siblings().removeClass("on");
			 });
			});
		

接下来给“.on”添加不同的样式:

			#pager a.on {
    box-shadow:
    inset rgba(0,0,0,0.1) 0 1px 0,
    inset rgba(0,0,0,0.3) 1px 0 0px,
    inset rgba(0,0,0,0.3) -1px 0 0px,
    inset rgba(255,255,255,0.7) 0 2px 0,
    inset rgba(255,255,255,0.7) 0 -1px 0,
    inset rgba(0,0,0,0.1) 0 0 15px,
    rgba(0,0,0,0.3) 0 1px 0;
    top: 2px;
    text-shadow: #fff 0 0 15px;
    }
     
    #pager a.on:before {
    box-shadow: rgba(0,0,0,0.4) 0 3px 0;
    top: -1px;
    }
		#pager a.on:after {
    bottom: -1px;
    }
     
    #pager a.on:active:after {
    bottom:-1px;
    }
		

完成这段代码后,今天的目标就算是完成了,不知道你喜欢?最后给大家附上一份web实体符对照表:

要是你感兴趣可以狠狠点这里下载。有关于WebSymbolsRegular更详细的介绍或关注他的相关更新情况,您可以移步到这里

最后希望大家喜欢这两部分内容,如果您有更好的建议请在下面的评论中直接给我留言。

转载烦请注明出处:W3CPLUS

CSS3美化有序列表

$
0
0

好久没有逛Red Team的blog了,今天上去发现更新了几个好东东,自己动手做了一遍。觉得很有创意,有几个新知识点以前自己没有使用过,我想大家或许也没有使用过,整理了一下贴上来和大家分享。

今天主要是跟着Red Team中的CSS3 ordered list styles做了一遍,要是你也喜欢也跟着一起动手写一回吧。

列表的样式,要做各浏览器下兼容都是一个麻烦的事情,特别是使用列表自带的“列表类型”时,在不同的浏览器下总是风格不一致。

Red Team中的CSS3 ordered list styles一文中,他给我们介绍了一种使用CSS3调节你的有序列表样式风格,而且语义化也是相当的强。

技巧

今天第一次看到了一种新的美化有序列表序列号的方法,这种方法是Roger Johansson带来的,详细的大家可以阅读Roger Johansson的文章《Styling ordered list numbers》。这种技术的关键几个部分:

  1. list-style:none:禁用列表的默认编码
  2. counter-reset和counter-increment:创建一个计数范围和增加计数。CSS 2.1对这两个属性有过详细的介绍。
  3. content:在content中插入创建编码的索引号。
  4. ::beforeCSS3的伪元素的运用,添加“content”中插入的内容。

说实话这种技术真的好特别,也好NB,也特喜欢。下面两个DEMO中是Red Team使用上面的相关技术部分创建了两个有序列表的样式。非常美,我想你会和我一样非常喜欢的。

HTML Markup

HTML就不复杂,和我们平时写“ol”列表一样的,这里两个DEMO分别定义了一个类名“rounded-list”和“rectangle-list”:

			<ol class="rounded-list">
        <li><a href="">List item</a></li>
        <li><a href="">List item</a></li>
        <li><a href="">List item</a>
          <ol>
            <li><a href="">List sub item</a></li>
            <li><a href="">List sub item</a></li>
            <li><a href="">List sub item</a></li>
          </ol>
        </li>
        <li><a href="">List item</a></li>
        <li><a href="">List item</a></li>
			</ol>
		

CSS Code

在具体写样式之前,我们再强调一下这种技术的关键地方:

这种技术使用了自动计数和编码。基本上他是使用了CSS2中的两个属性中:“counter-reset”(自动计数)和“counter-increment”(增数),正如你下面看到的代码一样,“counter-increment”将配合CSS3的伪元素“::before”或“::after”中的“content”创建编码。

1、列表基本样式

			ol{
        counter-reset: li; /* 创建一个计数器 */
        list-style: none; /* 清除列表默认的编码*/
        *list-style: decimal; /* 让IE6/7具有默认的编码 */
        font: 15px 'trebuchet MS', 'lucida sans';
        padding: 0;
        margin-bottom: 4em;
        text-shadow: 0 1px 0 rgba(255,255,255,.5);
			}

			ol ol{
				margin: 0 0 0 2em; /* 给二级列表增加一定的左边距*/
			}
		

2、Rounded-shaped编号

			/*rounded shaped numbers*/
		.rounded-list a {
			position: relative;
			display: block;
			padding: 0.4em 0.4em 0.4em 2em;
			*padding: 0.4em;/*for ie6/7*/
			margin: 0.5em 0;
			background: #ddd;
			color: #444;
			text-decoration: none;
			/*CSS3属性*/
			border-radius: 0.3em;/*制作圆角*/
			/* transition动画效果*/
			-moz-transition: all 0.3s ease-out;
			-webkit-transition: all 0.3s ease-out;
			-o-transition: all 0.3s ease-out;
			-ms-transition: all 0.3s ease-out;
			transition: all 0.3s ease-out;
		}
		.rounded-list a:hover {
			background: #eee;
		}
		.rounded-list a:hover::before {
			/*悬停时旋转编码*/
			-moz-transform: rotate(360deg);
			-webkit-transform: rotate(360deg);
			-o-transform: rotate(360deg);
			-ms-transform: rotate(360deg);
			transform: rotate(360deg);
		}
		.rounded-list a::before {
			
			content: counter(li);
			counter-increment: li;
			
			position: absolute;
			left: -1.3em;
			top: 50%;
			margin-top: -1.3em;
			background: #87ceeb;
			height: 2em;
			width: 2em;
			line-height: 2em;
			border: 0.3em solid #fff;
			text-align: center;
			font-weight: bold;
			border-radius: 2em;
			-webkit-transition: all 0.3s ease-out;
			-moz-transition: all 0.3s ease-out;
			-ms-transition: all 0.3s ease-out;
			-o-transition: all 0.3s ease-out;
			transition: all 0.3s ease-out;
		}
		

2、Rectangle-shaped编号

			/*rectangle list*/
		.rectangle-list a {
			position: relative;
			display: block;
			padding: 0.4em 0.4em 0.4em 0.8em;
			*padding: 0.4em;
			margin: 0.5em 0 0.5em 2em;
			background: #ddd;
			color: #444;
			text-decoration: none;
			/*transition动画效果*/
			-webkit-transition: all 0.3s ease-out;
			-moz-transition: all 0.3s ease-out;
			-ms-transition: all 0.3s ease-out;
			-o-transition: all 0.3s ease-out;
			transition: all 0.3s ease-out;
		}
		.rectangle-list a:hover {
			background: #eee;
		}
		
		.rectangle-list a::before {
			
			content: counter(li);
			counter-increment: li;
			
			position: absolute;
			left: -2.5em;
			top: 50%;
			margin-top: -1em;
			background: #fa8072;
			width: 2em;
			height: 2em;
			line-height: 2em;
			text-align: center;
			-webkit-transition: all 0.3s ease-out;
			-moz-transition: all 0.3s ease-out;
			-o-transition: all 0.3s ease-out;
			-ms-transition: all 0.3s ease-out;
			transition: all 0.3s ease-out;
		}
		.rectangle-list a::after {
			position: absolute;
			content:"";
			border: 0.5em solid transparent;
			left: -1em;
			top: 50%;
			margin-top: -0.5em;
			-webkit-transition: all 0.3s ease-out;
			-moz-transition: all 0.3s ease-out;
			-o-transition: all 0.3s ease-out;
			-ms-transition: all 0.3s ease-out;
			transition: all 0.3s ease-out;
		}
		.rectangle-list a:hover::after {
			left: -0.5em;
			border-left-color: #fa8072;
		}
		

上面展示的是两种DEMO效果,DEMO中也使用了一些CSS3的属性制作一些动画效果,大家可以参才DEMO中的效果。不过transition目前在伪元素或者伪类的应用还不够完善,仅Firefox对他们支持比较友好,希望后续能进一步的得到提高

浏览器的兼容

大家或许还在考虑这样写在IE下的效果呢?其实在IE6-8下的效果虽然没有现代浏览器下那样的完美,但也还算是尽人意:

大家可以看看最后的DEMO效果,请使用Firefox浏览器效果更佳,使用Chrome,Safari,Opera在第一个效果中数字不会进行旋转,具体原因前面有讲述。

那么今天的学习就到此为止,最后在结束之时再次感谢Red Team给我们带来这么好的教程《CSS3 ordered list styles》,同时也要非常感谢Roger Johansson对《Styling ordered list numbers》的详细讲解,让我学会了一种新的技术。如果大家有更好的理解,欢迎在下面的评论中留言。

如需转载烦请注明出处:W3CPLUS


CSS3和jQuery制作Login栏

$
0
0

这两天制作了一个登入栏效果的案例,简单点说就是集成了以前本站介绍的几个效果。

1、CSS3制作Login栏

2、CSS3和jQuery制作翻转表单

3、CSS3伪元素应用——CSS3 Button

另个在这个案例增加了两部分新东西:

BootStrap的基本样式和Tooltip效果

CSS3的制作的下拉与收缩的panel效果

自我感觉效果还可以,兼容所有现代浏览器,于是整理了一下,放上来与大家分享。

HTML Markup

		<input type="checkbox" role="button" id="topBar"/>
		<label for="topBar" onclick="">
		  <span>Login | Signup</span>
		  <span>Login | Signup</span>
		</label>
		<aside id="loginWrap" class="loginBar" role="loginBar">
		  <section class="container">
		    <div id="formContainer">
		      <form action="./" method="post" id="login" class="form-horizontal">
		        <h1>Log In</h1>
		        <fieldset class="input-text">
		          <legend>LogIn</legend>
		          <div class="control-group">
		            <input type="text" required="" autofocus="" placeholder="Enter your name" id="login-username" class="span4">   
		            <input type="password" required="" placeholder="Enter your password" id="login-password" class="span4">
		          </div>						
		        </fieldset>
		        <fieldset class="input-actions">
		          <legend>Login Actions</legend>
		          <div class="form-actions">
		            <input type="submit" value="Log in" id="signup-submit" class="btn signupBtn">
		            <a href="#">Forgot your password?</a><a id="flipToSignup" class="flipLink" data-original-title="Click here, Flip To Sign Up" rel="tooltip">Sign up</a>
		          </div>
		        </fieldset>
		      </form>
		      <!-- End Login from -->
		      <form action="./" method="post" id="signup" class="form-horizontal">
		        <h1>Sign Up</h1>
		        <fieldset class="input-text">
		          <legend>Sign up</legend>
		          <div class="control-group">
		            <input type="text" required="" autofocus="" placeholder="Enter your name" id="signup-username" class="span4">
		            <input type="text" required="" autofocus="" placeholder="Enter your E-mail" id="signup-email" class="span4">  	
		            <input type="password" required="" placeholder="Enter your password" id="signup-password" class="span4">
		          </div>
		        </fieldset>
		        <fieldset class="input-actions">
		          <legend>Sign up Actions</legend>
		          <div class="form-actions">
		            <input type="submit" value="Sign up" id="login-submit" class="btn loginBtn">
		            <a id="flipToLogin" rel="tooltip" class="flipLink" data-original-title="Click here, Flip To Log In">Log In</a>
		            <label class="checkbox">
		              <input type="checkbox" disabled="" value="option1" id="optionsCheckbox2">
		              I agree to the w3cplus service
		            </label>							
		          </div>
		        </fieldset>
		      </form>
		    </div>
		  </section>
		</aside>
	

上面的结构大家都清楚,但有几个地方需要特别提出,因为这几个地方对我们实现效果有关键性的作用。

1、CSS3制作panel的效果

先来说一下CSS3制作panel效果,就是点击“label”后会选择中“input[type="checkbox"]”,从而触发整个“aside.loginBar”显示或隐藏的效果。那么这里三个标签有顺序问题:

		<input type="checkbox" role="button" id="topBar"/>
		<label for="topBar" onclick=""></label>
		<aside id="loginWrap" class="loginBar" role="loginBar"></aside>
	

这三个标签一定不能随意调换先后顺序,不然后面的效果我们就无法实现。

2、旋转表单效果

旋转表单的效果,这里有两点需要注意,其一将两个表单并列放在容器“div#formContainer”中,而且每个表单我们需要一个触发旋转的锚点

在login表单中放一个触发到signup表单的锚点

		<a id="flipToSignup" class="flipLink" data-original-title="Click here, Flip To Sign Up" rel="tooltip">Sign up</a>
	

而在signup表单中同样需要放置一个触发到login表单的锚点

		<a id="flipToLogin" rel="tooltip" class="flipLink" data-original-title="Click here, Flip To Log In">Log In</a>
	

3、tooltip提示效果

这个案例中,在触发表单旋转的两个锚点处使用了BootStraptooltip效果,那么使用这个效果,我们同样需要满足其结构和属性值设置的需求:

		<a id="flipToSignup" class="flipLink" data-original-title="Click here, Flip To Sign Up" rel="tooltip">Sign up</a>
		<a id="flipToLogin" class="flipLink" data-original-title="Click here, Flip To Log In" rel="tooltip" >Log In</a>
	

4、表单的结构

其实表单的结构没有什么好说的,大家可以根据自己的习惯去书写,不过这里为了尝试BootStrap的“form”效果,我还是按照BootStrap的“form”写的,具体的大家可以参考上面的代码。

理清了HTML后,我们就可以开始后面的工作了,就是写CSS效果。

CSS Code

样式我这里也分几个步骤来说:

1、BootStrap样式调用

在这个案例中采用了BootStrap样式,大家喜欢的话可以到这里下载,然后取得相应的“bootstrap.css”,调用到你的项目之中:

		<link rel="stylesheet" href="css/bootstrap.css" />
	

这样就具有了BootStrap前端框架的样式。

2、表单的样式

其实调用了BootStrap样式后,对于表单来说就有一个完美的效果了,只不过你的结构和类名需要和BootStrapForms一致。不过此处我还在Bootstrap的表单上做了一些修改:

/*formContainer*/
#formContainer {
	margin: 20px auto;
}
#formContainer form {
	background-color: #fff;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee));
	background-image: -webkit-linear-gradient(top, #fff, #eee);
	background-image: -moz-linear-gradient(top, #fff, #eee);
	background-image: -ms-linear-gradient(top, #fff, #eee);
	background-image: -o-linear-gradient(top, #fff, #eee);
	background-image: linear-gradient(top, #fff, #eee);
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#fff, endColorstr=#eee);
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#fff, endColorstr=#eee)";
	height: 300px;
	width: 407px;
	padding: 30px;
	border-radius: 3px;
	box-shadow:0 0 2px rgba(0, 0, 0, 0.2),0 1px 1px rgba(0, 0, 0, .2),0 3px 0 #fff,0 4px 0 rgba(0, 0, 0, .2),0 6px 0 #fff,0 7px 0 rgba(0, 0, 0, .2);
	position: relative;
}
#formContainer form::before {
	content: '';
	position: absolute;
	z-index: 1;
	border: 1px dashed #ccc;
	top: 5px;
	bottom: 5px;
	left: 5px;
	right: 5px;
	box-shadow: 0 0 0 1px #fff;
}
#formContainer form h1{
	text-shadow: 0 1px 0 rgba(255, 255, 255, .7), 0px 2px 0 rgba(0, 0, 0, .5);
	text-transform: uppercase;
	text-align: center;
	color: #666;
	margin: 0 0 30px 0;
	letter-spacing: 4px;
	font: normal 26px/1 Verdana, Helvetica;
	position: relative;
}
#formContainer form h1::after, 
#formContainer form h1::before	{
	background-color: #777;
	content: "";
	height: 1px;
	position: absolute;
	top: 15px;
	width: 120px;
}
#formContainer form h1::after{
	background-image: -webkit-gradient(linear, left top, right top, from(#777), to(#fff));
	background-image: -webkit-linear-gradient(left, #777, #fff);
	background-image: -moz-linear-gradient(left, #777, #fff);
	background-image: -ms-linear-gradient(left, #777, #fff);
	background-image: -o-linear-gradient(left, #777, #fff);
	background-image: linear-gradient(left, #777, #fff);
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#777, endColorstr=#fff);
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#777, endColorstr=#fff)";
	right: 0;
}
#formContainer form h1::before	{
	background-image: -webkit-gradient(linear, right top, left top, from(#777), to(#fff));
	background-image: -webkit-linear-gradient(right, #777, #fff);
	background-image: -moz-linear-gradient(right, #777, #fff);
	background-image: -ms-linear-gradient(right, #777, #fff);
	background-image: -o-linear-gradient(right, #777, #fff);
	background-image: linear-gradient(right, #777, #fff);
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#777, endColorstr=#fff);
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#777, endColorstr=#fff)";
	left: 0;
}
#formContainer form fieldset	{
	border: 0;
	padding: 0;
	margin: 0;
	position: relative;
	z-index:3;
}
#formContainer form legend {
	display: none;
}
#formContainer form .control-group {
	margin-top: 0;
}
.input-text  input{
	background: #f1f1f1 url(../image/login-sprite.png) no-repeat;
	padding: 15px 15px 15px 30px;
	margin: 0 0 10px 0;
	border: 1px solid #ccc;
	border-radius: 5px;
	box-shadow: 0 1px 1px #ccc inset, 0 1px 0 #fff;
}
#login-username,
#signup-username	{
	background-position: 5px 15px !important;
}
#login-password,
#signup-password	{
	background-position: 5px -34px !important;
}
#signup-email {
	background-position: 7px -82px !important;
}
.input-text  input:focus	{
	background-color: #fff;
	border-color: #e8c291;
	outline: none;
	box-shadow: 0 0 0 1px #e8c291 inset;
}
.input-actions	.form-actions{
	margin: 0;
	padding: 0;
	background: none;
	border: none;
}
.input-actions .btn	{
	background-color: #ffb94b;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#fddb6f), to(#ffb94b));
	background-image: -webkit-linear-gradient(top, #fddb6f, #ffb94b);
	background-image: -moz-linear-gradient(top, #fddb6f, #ffb94b);
	background-image: -ms-linear-gradient(top, #fddb6f, #ffb94b);
	background-image: -o-linear-gradient(top, #fddb6f, #ffb94b);
	background-image: linear-gradient(top, #fddb6f, #ffb94b);
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#fddb6f, endColorstr=#ffb94b);
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#fddb6f, endColorstr=#ffb94b)";
	-moz-border-radius: 3px;
	-webkit-border-radius: 3px;
	border-radius: 3px;
	text-shadow: 0 1px 0 rgba(255,255,255,0.5);
	box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
	border-width: 1px;
	border-style: solid;
	border-color: #d69e31 #e3a037 #d5982d #e3a037;
	float: left;
	height: 35px;
	padding: 0;
	width: 120px;
	cursor: pointer;
	font: bold 15px Arial, Helvetica;
	color: #8f5a0a;
}
.input-actions .btnt:hover,
.input-actions .btn:focus		{
	background-color: #fddb6f;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#ffb94b), to(#fddb6f));
	background-image: -webkit-linear-gradient(top, #ffb94b, #fddb6f);
	background-image: -moz-linear-gradient(top, #ffb94b, #fddb6f);
	background-image: -ms-linear-gradient(top, #ffb94b, #fddb6f);
	background-image: -o-linear-gradient(top, #ffb94b, #fddb6f);
	background-image: linear-gradient(top, #ffb94b, #fddb6f);
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#ffb94b, endColorstr=#fddb6f);
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#ffb94b, endColorstr=#fddb6f)";
}
.input-actions .btn:active {
	outline: none;
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
}
.input-actions	.form-actions a	{
	color: #3151A2;
	float: right;
	line-height: 35px;
	margin-left: 10px;
	text-decoration: underline;
}
.input-actions .checkbox {
	float: right;
	margin-top: 10px;
}
	

效果

表单的制作效果,详情大家还可以参考《CSS3制作Login栏》一文。

2、翻转表单样式

这个样式也是相当的关键,使用CSS3写的一个3D旋转效果

	/*formContainer*/
#formContainer {
	width: 467px;	
	margin: 20px auto;
	
	height: 381px;
	position: relative;
	-moz-perspective: 800px;
	-webkit-perspective: 800px;
	perspective: 800px;
	
}
#formContainer form {
	background-color: #fff;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee));
	background-image: -webkit-linear-gradient(top, #fff, #eee);
	background-image: -moz-linear-gradient(top, #fff, #eee);
	background-image: -ms-linear-gradient(top, #fff, #eee);
	background-image: -o-linear-gradient(top, #fff, #eee);
	background-image: linear-gradient(top, #fff, #eee);
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#fff, endColorstr=#eee);
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#fff, endColorstr=#eee)";
	height: 300px;
	width: 407px;
	padding: 30px;
	border-radius: 3px;
	box-shadow:0 0 2px rgba(0, 0, 0, 0.2),0 1px 1px rgba(0, 0, 0, .2),0 3px 0 #fff,0 4px 0 rgba(0, 0, 0, .2),0 6px 0 #fff,0 7px 0 rgba(0, 0, 0, .2);
	
	position: absolute;
	top: 0;
	left: 0;
	z-index: 2;
	/*enabling 3d space for the transforms*/
	-moz-transform-style: preserve-3d;
	-webkit-transform-style: preserve-3d;
	transform-style: preserve-3d;
	/*when the forms are flipped, they will be hidden*/
	-moz-backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;	
	-moz-transition: 0.8s;
	-webkit-transition: 0.8s;
	transition: 0.8s;
	
}
#login {
	z-index: 100;
}
#signup {
	z-index: 2;
	opacity: 0;
	/*rotating the recover password form by default*/
	-moz-transform:rotateY(180deg);
	-webkit-transform:rotateY(180deg);
	transform:rotateY(180deg);
}
#formContainer.flipped #login {
	opacity:0;
	/*rotating the login form when the flipped class is added to the container*/
	-moz-transform: rotateY(-180deg);
	-webkit-transform: rotateY(-180deg);
	transform: rotateY(-180deg);
}
#formContainer.flipped #signup {
	opacity:1;
	/*rotating the recover div into view*/
	-moz-transform: rotateY(0deg);
	-webkit-transform: rotateY(0deg);
	transform: rotateY(0deg);
}
	

上面的效果前段时间在《CSS3和JQuery制作翻转表单》有做过详细的介绍,感兴趣的同学可以去看看。

3、loginBar按钮的制作

接下来是制作loginBar的按钮效果

	
[for="topBar"] span {
	-moz-transition: all 0.125s linear 0s;
	-webkit-transition: all 0.125s linear 0s;
	-o-transition: all 0.125s linear 0s;
	-ms-transition: all 0.125s linear 0s;
	transition: all 0.125s linear 0s;
	color: #FFFFFF;
  font: 12px 'Kaushan Script',cursive;
  letter-spacing: 1px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6), 0 2px 0 rgba(0, 0, 0, 0.6);
}

[for="topBar"] span:nth-of-type(1),
#topBar:checked ~ [for="topBar"] span:nth-of-type(2) {
  padding:8px 10px;
	border: none;
	border-left:solid 1px rgba(0, 0, 0, 08);
	background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.5) 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0, 0, 0, 0.3)), color-stop(100%,rgba(0, 0, 0, 0.5))); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.3) 0%,rgba(0, 0, 0, 0.5) 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, rgba(0, 0, 0, 0.3) 0%,rgba(0, 0, 0, 0.5) 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, rgba(0, 0, 0, 0.3) 0%,rgba(0, 0, 0, 0.5) 100%); /* IE10+ */
	background: linear-gradient(top, rgba(0, 0, 0, 0.3) 0%,rgba(0, 0, 0, 0.5) 100%); /* W3C */
	border-radius: 0 0 5px 0;
	box-shadow: 0 1px 0 rgba(0, 0, 0, 0.8) inset, 0 5px 0 0 rgba(0, 0, 0, 0.6), 0 10px 5px rgba(0, 0, 0, 0.3);
}
[for="topBar"] span:nth-of-type(1):active ,
#topBar:checked ~ [for="topBar"] span:nth-of-type(2):active{
	top:3px;
	border-left-color:rgba(0,0,0,0.33);
	background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.13) 0%, rgba(0, 0, 0, 0.3) 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0, 0, 0, 0.13)), color-stop(100%,rgba(0, 0, 0, 0.3))); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.13) 0%,rgba(0, 0, 0, 0.3) 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, rgba(0, 0, 0, 0.13) 0%,rgba(0, 0, 0, 0.3) 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, rgba(0, 0, 0, 0.13) 0%,rgba(0, 0, 0, 0.3) 100%); /* IE10+ */
	background: linear-gradient(top, rgba(0, 0, 0, 0.13) 0%,rgba(0, 0, 0, 0.3) 100%); /* W3C */
	box-shadow: 0 1px 0 rgba(0,0,0,0.33) inset, 0 5px 0 0 rgba(0, 0, 0, 0.3), 0 10px 5px rgba(0, 0, 0, 0.23);
}

[for="topBar"] span:nth-of-type(1)::before,
#topBar:checked ~ [for="topBar"] span:nth-of-type(2)::before {
	background-color:rgba(0, 0, 0, 0.3);
	content:"⇓";
	width:35px;
	position:absolute;
	display:block;
	padding-top:8px;
	padding-bottom:6px;
	top:-7px;
	left:-36px;
	border-right:1px solid rgba(0, 0, 0, 0.3);
	background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.3) 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0, 0, 0, 0.5)), color-stop(100%,rgba(0, 0, 0, 0.3))); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%,rgba(0, 0, 0, 0.3) 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%,rgba(0, 0, 0, 0.3) 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%,rgba(0, 0, 0, 0.3) 100%); /* IE10+ */
	background: linear-gradient(top, rgba(0, 0, 0, 0.5) 0%,rgba(0, 0, 0, 0.3) 100%); /* W3C */
	border-radius: 0 0 0 5px;
	box-shadow:0 1px 0 rgba(0, 0, 0, 0.9) inset, 0 5px 0 0 rgba(0, 0, 0, 0.7), 0 10px 5px rgba(0, 0, 0, 0.3);
	text-align: center;
	color: #FFFFFF;
  font:20px/19px 'Kaushan Script',cursive
}
#topBar:checked ~ [for="topBar"] span:nth-of-type(2)::before {
	content:"⇑";
	top: -1px;
	padding-bottom: 9px;
}
[for="topBar"] span:nth-of-type(1):active::before,
#topBar:checked ~ [for="topBar"] span:nth-of-type(2):active::before {
	box-shadow:inset 0px 1px 0px rgba(0,0,0,0.8), 0px 5px 0px 0px rgba(0,0,0,0.3), 1px 1px 0px 0px rgba(0,0,0,0.25), 2px 2px 0px 0px rgba(0,0,0,0.25), 2px 5px 0px 0px rgba(0,0,0,0.25), 6px 4px 2px rgba(0,0,0,0.25), 0px 10px 5px rgba(0,0,0,0.15) ;
}
	

这里的样式属性没有什么特殊之处,只不过是一些CSS3的相关属性,这里唯一的亮点就是CSS3选择器的使用,上面使用了CSS3的属性选择器伪类选择器。最终按钮效果:

4、CSS3制作Panel效果

这个效果可以说是本次案例展示的一个亮点之一,通过CSS控制整个panel展开与收缩的效果,而且还要同时控制“loginBar”的位置与显示和隐藏(其中一个按钮是点击会展开panel而另一个按钮点击会折叠panel)。具体大家看下面的代码:

	

/*pannel面板效果*/
.loginBar {
	background: #ccc;
	margin: auto;
	height:0px;
	overflow: hidden;
	width: 100%;
	-moz-transition: all 0.125s linear 0s;
	-webkit-transition: all 0.125s linear 0s;
	-o-transition: all 0.125s linear 0s;
	-ms-transition: all 0.125s linear 0s;
	transition: all 0.125s linear 0s;
	box-shadow: 0px 0px 1px 0px rgba(0,0,0,0.8), 0 1px 2px 2px rgba(0, 0, 0, 0.2);
	border-bottom: 5px solid #1c252b;
	background-color: #d9dee2;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#ebeef2), to(#d9dee2));
	background-image: -webkit-linear-gradient(top, #ebeef2, #d9dee2);
	background-image: -moz-linear-gradient(top, #ebeef2, #d9dee2);
	background-image: -ms-linear-gradient(top, #ebeef2, #d9dee2);
	background-image: -o-linear-gradient(top, #ebeef2, #d9dee2);
	background-image: linear-gradient(top, #ebeef2, #d9dee2);
}
/*不显示checkbox样式*/
#topBar {
	border: 0 none !important;
	clip: rect(1px,1px,1px,1px);
	height: 1px !important;
	overflow: hidden !important;
	position: absolute !important;
	width: 1px !important;
}
/*控制按钮位置*/
[for="topBar"] {
	-moz-transition: all 0.25s ease-out 0s;
	-webkit-transition: all 0.25s ease-out 0s;
	-o-transition: all 0.25s ease-out 0s;
	-ms-transition: all 0.25s ease-out 0s;
	transition: all 0.25s ease-out 0s;
	cursor: pointer;
	position: absolute;
	top: 11px;
	right: 10%;
	z-index: 999;
}

[for="topBar"] span {
	-moz-transition: all 0.125s linear 0s;
	-webkit-transition: all 0.125s linear 0s;
	-o-transition: all 0.125s linear 0s;
	-ms-transition: all 0.125s linear 0s;
	transition: all 0.125s linear 0s;
	color: #FFFFFF;
  font: 12px 'Kaushan Script',cursive;
  letter-spacing: 1px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6), 0 2px 0 rgba(0, 0, 0, 0.6);
}

[for="topBar"] span:nth-of-type(1),
#topBar:checked ~ [for="topBar"] span:nth-of-type(2) {
  padding:8px 10px;
	border: none;
	border-left:solid 1px rgba(0, 0, 0, 08);
	background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.5) 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0, 0, 0, 0.3)), color-stop(100%,rgba(0, 0, 0, 0.5))); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.3) 0%,rgba(0, 0, 0, 0.5) 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, rgba(0, 0, 0, 0.3) 0%,rgba(0, 0, 0, 0.5) 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, rgba(0, 0, 0, 0.3) 0%,rgba(0, 0, 0, 0.5) 100%); /* IE10+ */
	background: linear-gradient(top, rgba(0, 0, 0, 0.3) 0%,rgba(0, 0, 0, 0.5) 100%); /* W3C */
	border-radius: 0 0 5px 0;
	box-shadow: 0 1px 0 rgba(0, 0, 0, 0.8) inset, 0 5px 0 0 rgba(0, 0, 0, 0.6), 0 10px 5px rgba(0, 0, 0, 0.3);
}
[for="topBar"] span:nth-of-type(1):active ,
#topBar:checked ~ [for="topBar"] span:nth-of-type(2):active{
	top:3px;
	border-left-color:rgba(0,0,0,0.33);
	background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.13) 0%, rgba(0, 0, 0, 0.3) 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0, 0, 0, 0.13)), color-stop(100%,rgba(0, 0, 0, 0.3))); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.13) 0%,rgba(0, 0, 0, 0.3) 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, rgba(0, 0, 0, 0.13) 0%,rgba(0, 0, 0, 0.3) 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, rgba(0, 0, 0, 0.13) 0%,rgba(0, 0, 0, 0.3) 100%); /* IE10+ */
	background: linear-gradient(top, rgba(0, 0, 0, 0.13) 0%,rgba(0, 0, 0, 0.3) 100%); /* W3C */
	box-shadow: 0 1px 0 rgba(0,0,0,0.33) inset, 0 5px 0 0 rgba(0, 0, 0, 0.3), 0 10px 5px rgba(0, 0, 0, 0.23);
}

[for="topBar"] span:nth-of-type(1)::before,
#topBar:checked ~ [for="topBar"] span:nth-of-type(2)::before {
	background-color:rgba(0, 0, 0, 0.3);
	content:"⇓";
	width:35px;
	position:absolute;
	display:block;
	padding-top:8px;
	padding-bottom:6px;
	top:-7px;
	left:-36px;
	border-right:1px solid rgba(0, 0, 0, 0.3);
	background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.3) 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0, 0, 0, 0.5)), color-stop(100%,rgba(0, 0, 0, 0.3))); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%,rgba(0, 0, 0, 0.3) 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%,rgba(0, 0, 0, 0.3) 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%,rgba(0, 0, 0, 0.3) 100%); /* IE10+ */
	background: linear-gradient(top, rgba(0, 0, 0, 0.5) 0%,rgba(0, 0, 0, 0.3) 100%); /* W3C */
	border-radius: 0 0 0 5px;
	box-shadow:0 1px 0 rgba(0, 0, 0, 0.9) inset, 0 5px 0 0 rgba(0, 0, 0, 0.7), 0 10px 5px rgba(0, 0, 0, 0.3);
	text-align: center;
	color: #FFFFFF;
  font:20px/19px 'Kaushan Script',cursive
}
#topBar:checked ~ [for="topBar"] span:nth-of-type(2)::before {
	content:"⇑";
	top: -1px;
	padding-bottom: 9px;
}
[for="topBar"] span:nth-of-type(1):active::before,
#topBar:checked ~ [for="topBar"] span:nth-of-type(2):active::before {
	box-shadow:inset 0px 1px 0px rgba(0,0,0,0.8), 0px 5px 0px 0px rgba(0,0,0,0.3), 1px 1px 0px 0px rgba(0,0,0,0.25), 2px 2px 0px 0px rgba(0,0,0,0.25), 2px 5px 0px 0px rgba(0,0,0,0.25), 6px 4px 2px rgba(0,0,0,0.25), 0px 10px 5px rgba(0,0,0,0.15) ;
}

/*pannel折叠时隐藏按钮二*/
[for="topBar"] span:nth-of-type(2) {
  display: none;
  visibility: hidden;
}
/*改变按钮悬停文字颜色*/
[for="topBar"] span:hover,
[for="topBar"] span:hover::before {
  color: #35CFD9;
}
/*
*点击label后,input[type="checkbox"]处于选择状态:checked
*使用通用兄弟选择器(E~F)控制panel展开
*/
#topBar:checked ~ .loginBar {
  height: auto;
}
/*
*点击label后,input[type="checkbox"]处于选择状态:checked
*使用通用兄弟选择器(E~F)改变按钮的位置
*/
#topBar:checked ~ [for="topBar"] {
  opacity: 1;
	top: 426px;
}
/*checkbox选中时,按钮一隐藏*/
#topBar:checked ~ [for="topBar"] span:nth-of-type(1) {
  display: none;
  visibility: hidden;
}
/*checkbox选中时,按钮二显示*/
#topBar:checked ~ [for="topBar"] span:nth-of-type(2) {
  display: block;
  visibility: visible;
}
/*checkbox选中时,改变按钮的悬停状态文本色*/
#topBar:checked ~ [for="topBar"] span:hover,
#topBar:checked ~ [for="topBar"] span:hover::before {
  color: #35CFD9;
}

	

这一部分可能复杂一些,因为大家并不常使用,而且还需要控制好怎么显示,如何显示。具体效果呆会大家可以下载DEMO看实际效果,这样或许更好理解。

那么到这里有关于样式的部分就全部完成了,大家可以仔细看看代码。需要有耐性哟(^…^)!

jQuery Code

全例中还使用了两个jQuery效果,一个呢是前面介绍过的翻转表单;另一个就是BootStrap中的Tooltip效果

1、jQuery写的翻转代码

		$(function(){
	//checking for css 3d transformation support
	$.support.css3d = supportsCSS3D();
	var formContainer = $("#formContainer");
	//Listening for clicks on the ribbon links
	$(".flipLink").click(function(e){
		//flipping the forms
		formContainer.toggleClass("flipped");
		//if there is no css3 3d support, simply hide the login form (exposing the recover one)
		if(!$.support.css3d){
			$("#login").toggle();
		}
		e.preventDefault();
	});
				
	formContainer.find("form").submit(function(e){
		//Preventing form submissions.if you implement a backedn,you will want to remove this code
			e.preventDefault();
		});
	
	//a helper function that checks for the support of the 3d css3 transformations
	function supportsCSS3D(){
		var props = ["perspectiveProperty","WebkitPerspective","MozPerspective"],testDom = document.createElement("a");
		for(var i = 0; i < props.length; i++){
			if(props[i] in testDom.style){
				return true;
			}
		}
		return false;
	}
});
	

2、Tooltip代码

大家可以下载到这里下载bootstrap的tooltip的插件,然后在页面中调用:

	$(function(){
		$('#formContainer').tooltip({
			selector: "a[rel=tooltip]"
		}) 
	});
	

这样tip效果就出来了。

花了老长的篇幅,到这里总算是完工了,你要是没有出错的话,我想你在你的本地就能看到下面这样的一效果了。

载入页面时效果:

面板展开时效果:

触发表单旋转处

大家感兴趣的话可以下载demo查看。

今天就说到这里了,最后希望大家喜欢这个效果,最好使用现代浏览器查看,IE下没有进行任何的测试。如果你有更好的想法,欢迎在下面的评论中留言。

如需转载烦请注明出处:W3CPLUS

CSS3制作iPhone的Checkbox

$
0
0

iPhone上的UI的确是精致,让人爱不释手。今天用CSS3写了一个Checkbox的效果,采用了两种不同的方法来实现,另外在此基础上写了一个我们常用的checkbox的效果。

众所周知,想要美化表单中的元件,都少不了jQuery的帮忙,有关于这方面的介绍,本站也有过几篇相关的文章,比如说《美化表单——自定义单选按钮和复选按钮》、《自定义表单——JQuery制作个性化Checkbox》和《美化表单——自定义Checkbox和Radio样式》。那么有没有办法不使用jQuery呢?就是大家所说的纯CSS?如果你看了这篇文章后,你就会说,原来也可以实现呀。

今天这篇教程,我就想摆脱jQuery,使用CSS3来制作一个类似iPhone上的Checkbox效果。

针对上面的DEMO效果,下面我给大家介绍两种实现方法:

方法一:标签实现

实现原理

通过label标签的for属性来控制checkbox选择状态,至于选择和不选择此处使用ON和OFF来分别代替,接着借助一个空的标签来制作一个盖板,使用定位来遮住ON或者OFF,从而实现Checkbox的选择与否的效果。

HTML Markup

		<div class="labelWrap">
		  <label for="onOff" id="sliderLabel">
		    <input type="checkbox" id="onOff" />
		    <span id="slider">
		      <span id="sliderOn">ON</span>
		      <span id="sliderOff">OFF</span>
		      <span id="slideBlock"></span>	
		    </span>
		  </label>
		  <span id="lableTitle">Wi-Fi</span>
		</div>
	

这里有一个关键处,不是label标签的for属性值要与input[type="checkbox"]的id属性值一致。

CSS Code

	/*-------------------------*\
	 *	Demo1
	\*-------------------------*/
	
	.labelWrap {
		width: 200px;
		margin: 0 auto;
		overflow: hidden;
	}
	/*==checkbox容器样式==*/
	#sliderLabel {
		border: 1px solid #555;
		border-radius: 4px;
		cursor: pointer;
		display: block;
		height: 30px;
		overflow: hidden;/*==这个值很重要,将超出容器部分隐藏==*/
		position: relative;
		width: 100px;
		float: left;
		margin-right: 10px;
	}
	/*==隐藏input[type="checkbox"]==*/
	#onOff {
		border: 0 none !important;
		clip: rect(1px,1px,1px,1px);
		height: 1px !important;
		overflow: hidden !important;
		position: absolute !important;
		width: 1px !important;
	}
	/*==checkbox处于默认状态位置(未选中)==*/
	#slider {
		left: -50px;/*定位在OFF位置*/
		position: absolute;
		top: 0;
		-moz-transition: left 0.25s ease-out;
		-webkit-transition: left 0.25s ease-out;
		-o-transition: left 0.25s ease-out;
		-ms-transition: left 0.25s ease-out;
		transition: left 0.25s ease-out;
	}
	/*==ON、OFF和盖板定位位置==*/
	#sliderOn, 
	#slideBlock, 
	#sliderOff  {
		display: block;
		font-family: arial, verdana,sans-serif;
		font-weight: bold;
		height: 30px;
		line-height: 30px;
		position: absolute;
		text-align: center;
		top: 0px;
		text-shadow: #093B5C 0px -1px 1px;
		color: #fff;
	}
	/*==ON按钮效果==*/
	#sliderOn {
		background: -webkit-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
		background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#14539C), to(#3095C7));
		background: -moz-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
		background: -o-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
		background: -ms-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 	
		background: linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
		width: 54px;
		left: 0;	/*处于left为0位置处*/
	}
	/*==覆盖按钮样式==*/
	#slideBlock {
		background: -webkit-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
		background: #fff -webkit-gradient(linear, 0% 0%, 0% 100%, from(#A1A1A1), to(#FFFFFF));
		background: -moz-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
		background: -ms-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
		background: -o-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
		background: linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
		border-radius: 3px;
		height: 28px;
		left: 50px;/*处于left为50px处,遮住ON按钮 */
		width: 48px;
		border: 1px solid #e5e5e5;
	}
	/*==OFF按钮风格==*/
	#sliderOff {
		background: -webkit-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
		background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#14539C), to(#3095C7));
		background: -moz-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
		background: -o-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
		background: -ms-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 	
		background: linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
		left: 96px;/*OFF按钮默认位置处*/
		width: 54px;
	}
	#lableTitle{
		line-height: 32px;
	}
	/*==input[type=checkbox]:checked状态时,改变slider左边位置==*/
	#sliderLabel input:checked + #slider {
		left: 0;
	}
	

具体样式组件,看下图:

具体的样式代码不做过多阐述,这里说两个三个地方:

第一个就是将#slideLabel容器定义宽度,并设置一个overflow:hidden属性

		#sliderLabel {
			
			height: 30px;
			overflow: hidden;/*==这个值很重要,将超出容器部分隐藏==*/
			position: relative;
			width: 100px;
			
		}
	

第二就是隐藏input[type="checkbox"]

	#onOff {
		border: 0 none !important;
		clip: rect(1px,1px,1px,1px);
		height: 1px !important;
		overflow: hidden !important;
		position: absolute !important;
		width: 1px !important;
	}
	

第三点,也就是最为重要的一点,“#slider”位置控制,默认是未选择状态,而选中状态,通过input:checked + #slider来控制:

	/*==未选中状态位置==*/
	#slider {
		left: -50px;/*定位在OFF位置*/
		position: absolute;
		top: 0;		
	}
	/*==选中状态位置==*/
	#sliderLabel input:checked + #slider {
		left: 0;
	}
	

方法二:伪类元素

方法一采用的是添加标签的方法实现,为了实现一个效果添加一些标签觉得有点浪费,接下来我通过CSS3的伪类元素的方法在制作了一个DEMO:

实现原理

同样的,将默认的input[type="checkbox"]隐藏,通过label的for属性值与input[type="checkbox"]的id属性值来控制选中与否,关键处使用伪类元素来制作ON和OFF的按钮,而盖板效果依旧采用的是一个标签制作,具体参考下面的示意分析图:

HTML Markup

		<div class="labelBox">
		  <input type="checkbox" value="wi-fi" id="wifi" name="wifi" checked="checked" />
		  <label for="wifi" class="check"></label>
		  <label for="wifi" class="info">Wi-Fi</label>
		</div>
	

上面的结构很简单,只要你把上图看懂了的话,没有什么不清楚的。在这里我只想提醒大家“label”中的for属性值一定要和input[type=checkbox]的id属性值相同,否则将没有任何效果。

CSS Code

		/*-------------------------*\
		 *	Demo2
		\*-------------------------*/		
		#checked {
			font-family: "Lucida Grande", Verdana, Arial, sans-serif, Helvetica;
			width: 300px;
			position: relative;
			margin: 20px auto;
		}
		/*==Checkbox容器==*/
		.labelBox {
			margin-bottom: 20px;
			background: -webkit-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
			background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#14539C), to(#3095C7));
			background: -moz-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
			background: -ms-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
			background: -o-linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
			background: linear-gradient(19% 75% 90deg,#3095C7, #14539C); 
			border-radius: 4px;
			border: 1px solid #555555;
			/*容器大小*/
			width: 80px;
			position: relative;/*这个很重要*/
			height: 32px;
		}
		/*==CSS3的伪类元素制作ON和OFF按钮==*/
		.labelBox::before,
		.labelBox::after {
			content:"ON";/*添加ON标识符*/
			padding-left: 9px;
			line-height: 32px;
			color: #fff;
			font-size: 14px;
			text-shadow: #093b5c 0 -1px 1px;
		}
		/*==改变OFF按钮标签符==*/
		.labelBox::after {
			content:"OFF";
			padding-left: 12px;
		}
		/*==盖板效果==*/
		.check { 
			display: block;
			width: 40px;
			height: 30px;
			border-radius: 3px;
			background: #fff -webkit-gradient(linear, 0% 0%, 0% 100%, from(#A1A1A1), to(#FFFFFF));
			background: -webkit-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
			background: -moz-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
			background: -ms-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
			background: -o-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
			background: -moz-linear-gradient(19% 75% 90deg,#FFFFFF, #A1A1A1);
			border: 1px solid #e5e5e5;
			/*默认盖板位置*/
			position: absolute;
			top: 0px;
			left: 0px;
		}
		/*==隐藏input[type=checkbox]==*/
		input[type=checkbox] {
			border: 0 none !important;
			clip: rect(1px,1px,1px,1px);
			height: 1px !important;
			overflow: hidden !important;
			position: absolute !important;
			width: 1px !important;
		}
		/*==制作LabelON动画效果==*/
		@-webkit-keyframes labelON {
			0% {
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}			
			100% { 
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}
		}
		@-moz-keyframes labelON {
			0% {
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}	
			100% { 
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}
		}
		@-o-keyframes labelON {
			0% {
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}			
			100% { 
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}
		}
		@-ms-keyframes labelON {
			0% {
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}	
			100% { 
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}
		}
		@keyframes labelON {
			0% {
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}	
			100% { 
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}
		}
		/*==制作labelOFF动画==*/
		@-webkit-keyframes labelOFF {
			0% {
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}			
			100% { 
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}
		}
		@-moz-keyframes labelOFF {
			0% {
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}			
			100% { 
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}
		}
		@-o-keyframes labelOFF {
			0% {
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}			
			100% { 
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}
		}
		@-ms-keyframes labelOFF {
			0% {
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}			
			100% { 
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}
		}
		@keyframes labelOFF {
			0% {
				top: 0px;
				left: 38px;/*确定按钮选中状态位置*/
			}			
			100% { 
				top: 0px;
				left: 0px;/*确定按钮未选中状态位置*/
			}
		}
		/*==input[type=checkbox]:checked时盖板位置==*/
		input[type=checkbox]:checked + label.check {
		
			top: 0px;
			left: 38px;	
		
			-webkit-animation: labelON 0.2s ease-in 0s 1;
			-moz-animation: labelON 0.2s ease-in 0s 1;
			-o-animation: labelON 0.2s ease-in 0s 1;
			-ms-animation: labelON 0.2s ease-in 0s 1;
			animation: labelON 0.2s ease-in 0s 1;
			box-shadow: #244766 -1px 0px 3px;
		}
		/*==input[type="checkbox"]没选中时盖板位置==*/
		input[type=checkbox] + label.check {
		
			top: 0px;
			left: 0px;
		
			-webkit-animation: labelOFF 0.2s ease-in 0s 1;
			-moz-animation: labelOFF 0.2s ease-in 0s 1;
			-o-animation: labelOFF 0.2s ease-in 0s 1;
			-ms-animation: labelOFF 0.2s ease-in 0s 1;
			animation: labelOFF 0.2s ease-in 0s 1;
			box-shadow: #244766 1px 0px 3px;		
		}
		label.info {
			position: absolute;
			color: #000;
			top:0px;
			left: 100px;
			line-height: 32px;
			width: 200px;
		}
	

上面两种方法是模仿iPhone上的checkbox的效果,但我们PC机上的WEB页面checkbox的效果呢?其实用上面的方法也是可以的,下面我们来看一个实例,使用第二种方法来改变checkbox边框的样式。

HTML Markup

		<form action="" id="gf-form">
		  <div class="checkBox">
		    <input type="checkbox" id="checkbox1" />
		    <label for="checkbox1"<Unchecked Checkbox</label>
		  </div>
		  <div class="checkBox">
		    <input type="checkbox" id="checkbox2" checked="checked" />
		    <label for="checkbox2" >Checked Checkbox</label>
		  </div>
		  <div class="checkBox">
		    <input type="checkbox" id="checkbox3" disabled="disabled"/>
		  <label for="checkbox3">Disabled Unchecked Checkbox</label>
		  </div>
		  <div class="checkBox">
		    <input type="checkbox" id="checkbox4" disabled="disabled" checked="checked"/>
		    <label for="checkbox4">Disabled Checkbox</label>
		  </div>
		</form>
	

使用这种方法,主要是借助图片来实现,那么我们就需要制作一个sprites图片,下面我在网上随便找了一张图片:

CSS Code

		
/*-------------------------*\
Demo3
\*-------------------------*/
#gf-form label {
	font: normal normal 11px/13px Arial, Sans-serif;
  color: #000;
  cursor: pointer;
}
#gf-form label,
#gf-form input[type="checkbox"] + label::before {
	vertical-align: middle;
}
#gf-form input[type="checkbox"] {
	border: 0 none !important;
	clip: rect(1px,1px,1px,1px);
	height: 1px !important;
	overflow: hidden !important;
	position: absolute !important;
	width: 1px !important;
}
#gf-form input[type="checkbox"] + label::before {
	content: "";
  display: inline-block;
  width: 13px;
  height: 13px;
  line-height: 13px;
  margin: 0 8px 0 0;
  background: url("../images/sprite-radio-checkbox.png") no-repeat 0 0;
  vertical-align: middle;
}
/* disabled checkbox*/
#gf-form input[type="checkbox"]:disabled + label{
    opacity: .5;
    cursor: default; /* or cursor: no-drop */
}
/* hover checkbox (unselected state only) */
#gf-form input[type="checkbox"]:not(:checked):hover + label::before{
    background-position: 0 -13px;
}
/* selected checkbox */
#gf-form input[type="checkbox"]:checked + label::before{
    background-position: 0 -26px;
}
	

最终果:

上面用CSS3制作了三个美化表单中的复选框的效果,其实我们也可以使用这样的方法来美化单选按钮的效果,后面将花点时间来试试,大家不仿也试试。

那么今天就说到这了,希望大家喜欢。

如需转载烦请注明出处:W3CPLUS

CSS的陷阱

$
0
0

我们写CSS的在写CSS总会碰到一些这样那样的问题,为了应付这些问题,我们需要一些特殊的技巧才能解决。今天这篇文章我收集了几个怪异的问题,放上来给大家分享,希望大家以后碰到这样的问题能得心应手的解决。

Select最佳设置

昨天在携程UED中看到一篇关于表单元素中的Select的设置的文章,写的很有意思,详细的不多说,截了里面的一张图来说明Select的在各浏览器的测试情况:

最终得到select的最佳设置的值:

		select{height:22px; line-height:18px; padding:2px 0;font-size: 12px;}
	

详细的介绍参考:携程UED的《select的最佳预设(reset)

Buttons样式

制作按钮时,我们平常都用“<button>”、“input[type=rest]”、“input[type="submit"]”和“input[type=button]”较多,如果你想让你的按钮漂亮,记得加上下面的样式:

		/*IE下除去多余的边距 */
		.button{
			overflow: visible;
		}

		/* Firefox下去除焦点虚线框 */
		.button::-moz-focus-inner{
			border: 0;
			padding: 0;
		}
		/*实现图片按钮*/
		.button {
			font: 0/0 a;
			color: transparent;
		}		
	

另外在这些按钮中使用padding值来代替行高居中的效果,在firefox和opera浏览器下只识别默认行高:

扩展阅读

  1. 表单button的行高问题
  2. 表单button的outline问题
  3. 表单button的text-indent问题
  4. input 按钮在IE下兼容问题

使用伪元素

“:before”和“:after”我想很多人都有见过,知道他是“伪类”,但对于“::before”和“::after”我想还是有蛮多人不清楚这个是什么?一个“:”和两个“:”有什么区别。从简单的称呼上来说,一个“:”的叫做“伪类”,而两个“:”的是CSS3的产物,称为伪元素。具体的区别可以点击这里查阅。

我在这里不想说他们的区别,大家都认为在任何元素上通过他们都能为某个元素添加内容,或者写任何效果,其实不是的。他们在“input”和“img”元素是使用是没有任何效果的,还有一点伪元素的动画效果在“-webkit”内容下不起作用。

整个body的渐变色

这次做一个iphone上的项目在body中运用了一个渐变色。我采用的是CSS Gradient写的:

	html,body {
		height: 100%;
		margin: 0;
	}
	body {
		background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,1)), color-stop(5%,rgba(255,255,255,0.3)), color-stop(30%,rgba(164,180,188,.5)),color-stop(40%,rgba(164,180,188,.6)),color-stop(100%,rgba(164,180,188,1)));
		background: -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0.3) 5%,rgba(164,180,188,.5) 30%,rgba(164,180,188,.6) 40%,rgba(164,180,188,1) 100%);
		background: -moz-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0.3) 5%,rgba(164,180,188,.5) 30%,rgba(164,180,188,.6) 40%,rgba(164,180,188,1) 100%);
		background: -ms-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0.3) 5%,rgba(164,180,188,.5) 30%,rgba(164,180,188,.6) 40%,rgba(164,180,188,1) 100%);
		background: -o-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0.3) 5%,rgba(164,180,188,.5) 30%,rgba(164,180,188,.6) 40%,rgba(164,180,188,1) 100%);
	}
	

结果碰到这样一个问题:

屏幕在旋转后渐变背景色会显示不全,另外当滚动屏幕到底部分时,渐变色也将显示不全。可以通过下面的方法解决这个问题:

		body {
			background-repeat: no-repeat;
			background-attachment: fixed;
		}
	

IE9下的圆角与渐变

前段时间有一友人在制作了一个Buuton,带圆角和渐变效果,同样采用的是CSS3来制作,但在IE9下将会有一个Bug,渐变色会冒出圆角,最终采用的是Ultimate CSS Gradient Generator工具,在IE9下使用SVG解决。

假过渡的渐变

说起渐变,有时想使用梯渡实现渐变效果,可惜的是现在浏览器都不支持,但Twitter’s Bootstrap有一种方法能帮我们实现。

Twitter’s Bootstrap使用的是这种技巧:

在“:hover”上使用“background-position”来实现梯度的渐变效果,唯一的技巧就是改变“background-position”的“Y轴”效果:

		a{
			background: linear-gradient(orange, red) repeat-x;
			display: inline-block;
			padding: 20px;
		}
		a:hover{
			background-color: red;
			background-position: 0 -15px;
			transition: background-position .1s linear;
		}
	

第二种比较好的方法就是改变“background-color”值,不过需要使用到“background-image”

		a{
			background-color: orangered;
			background-image: linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
			transition: background-color .1s linear;
			display: inline-block;
			padding: 20px;
		}

		a:hover{
			background-color: red;
		}
	

inline-block的缺口

有很多地方介绍过使用“display:inline-block”来替代“float”制作水平布局效果。如果你也使用过的话,你肯定有碰到过,元素之间会有一个左右2px的margin一样产生。

解决这样的问题有两种方法:

方法一有点龌龊,就是在html结构中改变他的书写方式:

原来的写法

		<ul>
      <li>one</li>
      <li>two</li>
      <li>three</li>
		</ul>
	

修改后的结构

		<ul>
      <li>one</li><li>two</li><li>three</li>
		</ul>
	

另外一种方法就是将父元素字号设置为0;然后在li元素上恢复字号大小

		ul {
			font-size: 0;
		}
		li {
			font-size: 12px;
		}
	

详细的介绍可以参考:

  1. CSS display: inline-block: why it rocks, and why it sucks
  2. CSS3制作的分页导航

100%高度的运用

有些同学总是喜欢给一个元素设置高度为100%;想让他填充父元素的整个高度。但是有一点不知道大家有没有试过,当你的父元素没有明确指定一个高度的值,你在其子元素中设置一个高度为100%;会有作用?所以说,如果你想给元素指定100%的高度,最好在父元素中指定一个明确的高度值。

		<div id="parent">
			<div id="child">2</div>
		</div>
	

相应的样式

		#parent{
			height: 400px;
			padding:10px;
			background:red;
		}

		#child{
			height: 100%;
			background:green;
		}
	

只有这样设置,子元素#child才会拉伸和父元素#parent一样的高度。

table的圆角设置

如果你想给表格设置圆角效果,那么最好在你的表格中加上下面的样式

		table {
			*border-collapse: collapse; /* IE7 and lower */
			border-spacing: 0;
			border-radius: 5px;
		}
	

上面介绍的几个CSS小技巧在平时的运用中是非常有实用价值的,不信你可以尝试一下。上面的小技巧帮我在项目中解决了一些难以想像的bug,我也希望对你在今后的项目中有所帮助。如果你有更好更多的小技巧,不仿与我们一起分享,希望在下面的评论中留下您的足迹,我会在第一时间更新您提供的小技巧。

如需转载烦请注明出处:W3CPLUS

CSS3制作菜单的Hover效果

$
0
0

最近一直在整理W3cplus Demo站点,收集和写了一些CSS3的Demo效果。今天整理了一下写的《How to spice up your menu with CSS3》效果,整理一下与大家一起学习。

目的

这是一个简单的列表菜单,当你鼠标移到菜单项时,有一张图片慢慢的从左边向右边移动,并淡淡显示出来,而且此时的菜单项背景色和字体色也同时会改变。

下面我们一起来简单的学习这种效果的制作。

HTML Markup

制作上面的效果需要的HTML结构很简单,在每个列表项中放置两个span制作菜单的内容,并同时放置了一张图片,用来制作hover时图片显示出来的效果,具体的代码如下:

		<ul class="mh-menu">
			<li>
				<a href="#">
					<span>Art Director</span>
					<span>Henry James</span>
				</a>
				<img src="images/1.jpg" alt="image01"/>
			</li>
				<!-- ... -->
		</ul>
	

CSS Code

接下来制作样式效果。制作这个效果关键有以下几步:

第一步:

设置列表项中a元素的背景色,并在悬停状态下改变他的背景色:

		.mh-menu li a{
			display: block;
			width: 220px;
			padding: 0px 10px;
			text-align: right;
			position: relative;
			z-index: 10;
			height: 97px;
			border-right: 1px solid #ddd;
			background: rgba(255,255,255, 0.8);
		}
		.mh-menu li:hover a{
			background: rgba(225,239,240, 0.4);
		}
	

第二步:

第二步是改变每个列表项的第二个span的字体颜色。在这个效果中,使用了两个CSS3效果,其一是transition,第二个就是CSS3的伪类选择器:nth-child

		.mh-menu li a span:nth-child(2){
			font-weight: 400;
			font-style: italic;
			font-size: 28px;
			font-family: 'Alegreya SC', Georgia, serif;
			
			-webkit-transition: color 0.2s linear;
			-moz-transition: color 0.2s linear;
			-o-transition: color 0.2s linear;
			-ms-transition: color 0.2s linear;
			transition: color 0.2s linear;
			
		}
		.mh-menu li:nth-child(1):hover span:nth-child(2){
			color: #ae3637;
		}
		.mh-menu li:nth-child(2):hover span:nth-child(2){
			color: #c3d243;
		}
		.mh-menu li:nth-child(3):hover span:nth-child(2){
			color: #d38439;
		}
		.mh-menu li:nth-child(4):hover span:nth-child(2){
			color: #8e7463;
		}
	

第三步:

最后一个效果就是鼠标悬停状态时显示隐藏的img,在这个效果中通过transition改变left和opacity的值。left值从0变到240px,而opacity值从0变到1.

		.mh-menu li img{
			position: absolute;
			z-index: 1;
			left: 0px;
			top: 0px;
			
			opacity: 0;
			-webkit-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
			-moz-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
			-o-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
			-ms-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
			transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
			
		}
		.mh-menu li:hover img{
			left: 240px;
			opacity: 1;
		}
	

完成上面的关键几步,效果就算是完成了。当然要实现上面demo效果,还需要别的代码支撑。详细的代码大家可以点击这里

上面的效果只是其中的一种,你可以发挥自己的想像力,在li之类上动动心思,会实现更多的效果。如demo 2demo 3效果。

到这里效果就算是完成了,不知道大家是否喜欢。如果有更好的心路和创意欢迎在下面的评论中与我们一起分享。或者制作demo效果放在w3cplus demo站上。

如需转载烦请注明出处:W3CPLUS

CSS3制作表单动态帮助信息

$
0
0

前几天在W3cplus Demo站上放了一个CSS3 Sliding Form Helps效果。

今天我们就一起来看看他是如何实现的。

实现方法

在表单制作中,往往都在一个input后面或者右边有一个提示框效果,特别是表单验证的制作上。有错误的,警告的,正确的等多种帮助信息。以前大多数看到的有提示信息一直显示,第二种,当表单验正完后显示提示信息,第三种就是input得到焦点时提示用户如何操作。而这些效果以前都是依附在jQuery的上面实现,今天我想和大家一起探讨的是使用CSS3来实现。

实现原理也是来源于jQuery,在这个案例中,当表单载入时,所有提示信息都处理隐藏状态,一但input得到焦点,相对应的提示信息就会显示出来。

HTML Markup

	<form action="#" method="post" class="form-horizontal">
  <fieldset>
    <div class="control-group">
      <label for="email" class="control-label">E-Mail:</label>
      <div class="controls controls-inline">
        <input type="email" id="email" />
        <span class="help-inline">Please Input Your Email!</span>
      </div>
    </div>
    <div class="control-group">
      <label for="password" class="control-label">Password:</label>
      <div class="controls controls-inline">
        <input type="password" id="password" />
        <span class="help-inline">Please Input Your Password!</span>
      </div>
    </div>			 
  </fieldset>
  <fieldset>
    <div class="control-group">
      <label for="email2" class="control-label">E-Mail:</label>
      <div class="controls controls-block">
        <input type="email" id="email2" />
        <span class="help-block">Please Input Your Email!</span>
      </div>
    </div>
    <div class="control-group">
      <label for="password2" class="control-label">Password:</label>
      <div class="controls controls-block">
        <input type="password" id="password2" >>
        <span class="help-block">Please Input Your Password!</span>
      </div>
    </div>			 
  </fieldset>
</form>		
	

这个结构很简单,渲染出来后就是左边label右边文本框的效果。在这里采用了Bootstrap的form结构和样式风格。详细的运用大家可以点击这里。我想在这里特别提出的是“帮助信息”的结构:

行内显示

		<div class="controls controls-inline">
      <input type="password" id="password" />
      <span class="help-inline">Please Input Your Password!</span>
    </div>
	

表单的帮助信息和input将在同一行显示,在Bootstrap form基础上进行了扩展,给div.controls容器添加一个新类名“controls-inline”。

块状显示

		<div class="controls controls-block">
      <input type="password" id="password2" >>
      <span class="help-block">Please Input Your Password!</span>
    </div>
	

同样的道理,只不过更换了一个类名“controls-block”。

CSS Code

		form {
			margin: 20px 0 18px;
		}
		fieldset {
			padding: 0;
			margin: 0;
			border: 0;
		}
		label,
		input,
		button{
			font-size: 13px;
			font-weight: normal;
			line-height: 18px;
		}
		input,
		button{
			font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
		}
		label {
			display: block;
			margin-bottom: 5px;
			color: #333333;
		}
		input{
			display: inline-block;
			width: 210px;
			height: 18px;
			padding: 4px;
			margin-bottom: 9px;
			font-size: 13px;
			line-height: 18px;
			color: #555555;
			border: 1px solid #cccccc;
			-webkit-border-radius: 3px;
			-moz-border-radius: 3px;
			border-radius: 3px;
		}
		input[type="button"],
		input[type="reset"],
		input[type="submit"] {
			width: auto;
			height: auto;
		}
		input {
			-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
			-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
			box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
			-webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
			-moz-transition: border linear 0.2s, box-shadow linear 0.2s;
			-ms-transition: border linear 0.2s, box-shadow linear 0.2s;
			-o-transition: border linear 0.2s, box-shadow linear 0.2s;
			transition: border linear 0.2s, box-shadow linear 0.2s;
		}
		input:focus,
		textarea:focus {
			border-color: rgba(82, 168, 236, 0.8);
			-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
			-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
			box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
			outline: 0;
			outline: thin dotted \9;
		}
		input{
			margin-left: 0;
		}
		input:focus:required:invalid,
		textarea:focus:required:invalid,
		select:focus:required:invalid {
			color: #b94a48;
			border-color: #ee5f5b;
		}
		input:focus:required:invalid:focus,
		textarea:focus:required:invalid:focus,
		select:focus:required:invalid:focus {
			border-color: #e9322d;
			-webkit-box-shadow: 0 0 6px #f8b9b7;
			-moz-box-shadow: 0 0 6px #f8b9b7;
			box-shadow: 0 0 6px #f8b9b7;
		}
		:-moz-placeholder {
			color: #999999;
		}
		::-webkit-input-placeholder {
			color: #999999;
		}
		.help-block,
		.help-inline {
			color: #555555;
		}
		.help-block {
			display: block;
			margin-bottom: 9px;
		}
		.help-inline {
			display: inline-block;
			*display: inline;
			*zoom: 1;
			vertical-align: middle;
			padding-left: 5px;
		}
		.form-horizontal input,
		.form-horizontal .help-inline {
			display: inline-block;
			margin-bottom: 0;
		}

		.control-group {
			margin-bottom: 9px;
		}
		.form-horizontal .control-group {
			margin-bottom: 18px;
			*zoom: 1;
		}
		.form-horizontal .control-group:before,
		.form-horizontal .control-group:after {
			display: table;
			content: "";
		}
		.form-horizontal .control-group:after {
			clear: both;
		}
		.form-horizontal .control-label {
			float: left;
			width: 140px;
			padding-top: 5px;
			text-align: right;
		}
		.form-horizontal .controls {
			margin-left: 160px;
			*display: inline-block;
			*margin-left: 0;
			*padding-left: 20px;
		}
		.form-horizontal .help-block {
			margin-top: 9px;
			margin-bottom: 0;
		}
		.form-horizontal .form-actions {
			padding-left: 160px;
		}
		/*helps info*/

		.form-horizontal .help-inline {
			position: relative;
			padding: 3px 6px;
			background: #444;
			color: #fff;
			z-index: -2;
			border-radius: 3px;
			-webkit-transition:all 0.5s;
			-moz-transition:all 0.5s;
			-o-transition:all 0.5s;
			-ms-transition:all 0.5s;
			transition:all 0.5s;
			position: relative;
			margin-left: -500px;
		}	
		.form-horizontal .help-inline::before {
			content:"";
			display: block;
			height: 0;
			width: 0;
			position: absolute;
			top: 7px;
			left: -12px;
			border: 6px solid transparent;
			border-right-color: #444;
			z-index: 2;
		}
		.controls {
			position: relative;
			overflow: hidden;
		}	
		.form-horizontal .help-block {
			background: #444;
			border-radius: 3px;
			padding: 3px 6px;
			position: absolute;
			top: 28px;
			left: 0;
			z-index: -2;
			color: #fff;
			-webkit-transition:all 0.5s;
			-moz-transition:all 0.5s;
			-o-transition:all 0.5s;
			-ms-transition:all 0.5s;
			transition:all 0.5s;
		}
		.form-horizontal .help-block::after {
			border: 6px solid transparent;
			border-bottom-color: #444;
			content:"";
			display: block;
			height:0;
			width: 0;
			left: 5px;
			top: -12px;
			z-index: 2;
			position: absolute;
		} 
		.form-horizontal input:active + .help-inline,
		.form-horizontal input:focus + .help-inline {
			margin-left: 8px;
		}
		.form-horizontal .controls-block input:active,
		.form-horizontal .controls-block input:focus {
			margin-bottom: 35px;
		}
	

上面表单样式代码都是现成的,我就是一个拿来主义者,将bootstrap的表单的样式运用过来了,不过bootstrap表单的样式可没有动态显示帮助信息的功能。那么我在下面想给大家介绍的是这段代码。

1、提示信息样式

	.controls {
			position: relative;
			overflow: hidden;
	}	
	.form-horizontal .help-inline {
			position: relative;
			padding: 3px 6px;
			background: #444;
			color: #fff;
			z-index: -2;
			border-radius: 3px;
			-webkit-transition:all 0.5s;
			-moz-transition:all 0.5s;
			-o-transition:all 0.5s;
			-ms-transition:all 0.5s;
			transition:all 0.5s;
			position: relative;
			margin-left: -500px;
		}	
		.form-horizontal .help-inline::before {
			content:"";
			display: block;
			height: 0;
			width: 0;
			position: absolute;
			top: 7px;
			left: -12px;
			border: 6px solid transparent;
			border-right-color: #444;
			z-index: 2;
		}		
		.form-horizontal .help-block {
			background: #444;
			border-radius: 3px;
			padding: 3px 6px;
			position: absolute;
			top: 28px;
			left: 0;
			z-index: -2;
			color: #fff;
			-webkit-transition:all 0.5s;
			-moz-transition:all 0.5s;
			-o-transition:all 0.5s;
			-ms-transition:all 0.5s;
			transition:all 0.5s;
		}
		.form-horizontal .help-block::after {
			border: 6px solid transparent;
			border-bottom-color: #444;
			content:"";
			display: block;
			height:0;
			width: 0;
			left: 5px;
			top: -12px;
			z-index: 2;
			position: absolute;
		} 
	

上面采用了一些CSS3属性,制作了一个tooltip的样式效果,代码很简单,不过有两种我单独提出来:

		.form-horizontal .help-inline {			
			
			margin-left: -500px;
			
		}	
	

在“help-inline”样式中,使用“margin-left”的负值来隐藏帮助信息,当然大家可以将其值设置的更大,按需设置吧。

		.form-horizontal .help-block {
			
			position: absolute;
			top: 28px;
			left: 0;
			z-index: -2;
			
		}
	

上面的这几行代码是用来设置块状帮助信息,在表单加入的时候不显示出来,位置的定制主要是靠“top”和“left”值,而隐藏是依靠“z-index”的值。

2、显示提示信息

这一步是今天的最关键的地方了,就是如何让表单的文本框得到焦点时,相对应的表单帮助信息能显示出来,下面我们先来看实现这个功能的代码:

	
.form-horizontal input:active + .help-inline,
.form-horizontal input:focus + .help-inline {
	margin-left: 8px;
}
.form-horizontal .controls-block input:active,
.form-horizontal .controls-block input:focus {
	margin-bottom: 35px;
}
	

上面的几行代码就实现了我们需要功能,大家此时肯定会问为什么了?其实也并不是想像的那么复杂。关键性的功能来自于“CSS选择器”。一个是“相邻兄弟元素选择器(E + F)” ,另一个是伪类选择器。说得简单点“当表单得到焦点(:active和:focus)时其相邻的兄弟元素“help-inline/help-block”元素将做什么?”。因此在“.help-inline”我们改变了margin-left的值,由当初的“-500px”变成了“8px”。而对于块状提示信息,一但表单input得到焦点,就会增加一个“margin-bottom”值,从而使“help-block”显示出来。

功能就是这样实现的,是不是觉得很神呀,只可惜的是在IE下实现起来困难。不过对于不鸟IE的同学来说还是很适用的。我就把这个效果运用到一个iPhone的项目上。(^-^)

那么关于这个教程就说到这了,如果你感兴趣,可以点击这里查看所有代码,也可以下载源码自己学习。

最后希望大家喜欢,如果觉得这篇教程对你学习有帮助,多多支持本站。如果你有更好的思路可以在下面的评论中给我留言,与大家一起分享你的经验。

如需转载烦请注明出处:W3CPLUS

jQuery Timeline

$
0
0

TimelineVeriteCo写的一个jQuery插件。它将一连串的事件集合到一起,按时间轴的顺序展示这些发生的事件。你可以将各种媒体、图片、视频、地图等相关信息插入到timeline。结合设计可以完美的展示你的工作效率或者更强的信息。比如说你一年,或者多年下来人生中的大事等。

VeriteCoTimelineFacebooktimeline都有类似功能之处。前面在jQuery制作Facebook Timeline一文中学习了Facebooktimeline使用。今天主要想让大家和我一起跟着VeriteCoMartin Angelov 学习如何使用timeline。

准备工作

要成功的使用Timeline,首先需要做好以下的准备工作:

  1. jQuery版本库:可以到官网下载最新版本库;
  2. timeline插件:点击下载
  3. timeline样式:点击下载,当然样式大家可以在自己的项目中,使用覆盖的方式去覆盖这个样式文件;
  4. json文件:这个文件大家需要根据自己的需求去下写了(我也不懂,所以我使用了一个在线的json文件),当然大家还可以使用Google Doc Template,说细的介绍点击这里

大家也可以从github下载所需文件,当然还可以到官网点击Download按钮下载。文件下载到本地后进行解压缩后就可以按照下面的方法进行使用了。

HTML Markup

timeline带有一个默认的主题,当然大家可以根据自己的设计需求进行主题的覆写。

首先,让我们看看首页的基本模板

		<body>
			<div id="timeline">
				 <!-- Timeline will generate additional markup here -->
			</div>
		</body>
	

如果你只想让整个页面是timeline效果,在body中放一个div#timeline容器就够了,这里需要特别声明一点“使用这个timeline必需要这个id为‘timeline’,不然将会失去效果。”如果你需要其他的效果,可以在div#timeline添加别的类名,或者在其外部添加别的容器。

接着在<head>中载入你下载的timeline.css样式文件:

	<!-- The default timeline stylesheet -->
  <link rel="stylesheet" href="assets/css/timeline.css" />
	

你也可以加载在线样式文件:

		<!-- The default timeline stylesheet -->
		<link rel="stylesheet" href="http://veritetimeline.appspot.com/latest/timeline.css" />
	

不过加载在线样式文件的风险大家知道的,我就不多说了。

样式加载完后,其后在你的<body>底部加载js文件:

	 <!-- JavaScript includes - jQuery, turn.js and our own script.js -->
   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
   <script src="assets/js/timeline-min.js"></script>
	

这两件文件也和样式文件一样,可以加载在线的文件:

	 <!-- JavaScript includes - jQuery, turn.js and our own script.js -->
   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
   <script src="http://veritetimeline.appspot.com/latest/timeline-min.js"></script>
	

最后启用这个插件:

		<script>
			$(document).ready(function() {
				var timeline = new VMM.Timeline();
				timeline.init("your_data.json");			
			});
		</script>
	

此时你将看到timline在默认主题下的一个效果了。

大家都看到了上面的效果了,当我们启用了timeline.js后,就会搜索文档中的div#timeline容器,并按下面的模板格式将json中的数据加载到div#timeline容器中:

	<div class="container main" id="timeline">
	<div class="feature slider" style="overflow-y: hidden;">
		<div class="slider-container-mask slider-container slider-item-container">

			<!-- The divs below are the events of the timeline -->

			<div class="slider-item content">
				<div class="text container">

					<h2 class="start">Johnny B Goode</h2>
					<p><em><span class="c1">Designer</span> & <span class=
					"c2">Developer</span></em></p>

				</div>

				<div class="media media-wrapper media-container">
					<!-- Images or other media go here -->
				</div>
			</div>

			<div class="slider-item content content-container">
				<div class="text container">

					<h2 class="date">March 2009</h2>
					<h3>My first experiment in time-lapse photography</h3>
					<p>Nature at its finest in this video.</p>

				</div>

				<div class="media media-wrapper media-container">
					<!-- Images or other media go here -->
				</div>
			</div>

			<!-- More items go here -->
		</div>

        <!-- Next arrow -->
		<div class="nav-next nav-container">
			<div class="icon"></div>
			<div class="date">March 2010</div>
			<div class="title">Logo Design for a pet shop</div>
		</div>

        <!-- Previous arrow -->
		<div class="nav-previous nav-container">
			<div class="icon"></div>
			<div class="date">July 2009</div>
			<div class="title">Another time-lapse experiment</div>
		</div>
	</div>

	<div class="navigation">

			<!-- The navigation items go here (the tooltips in the bottom)
                one for each of the events -->

			<div class="time">
				<!-- The timeline numbers go here -->
			</div>
		</div>

		<div class="timenav-background">
			<div class="timenav-line" style="left: 633px;"></div>

			<div class="timenav-interval-background top-highlight"></div>
		</div>

		<div class="toolbar" style="top: 27px;">
			<div class="back-home icon" title="Return to Title"></div>
			<div class="zoom-in icon" title="Expand Timeline"></div>
			<div class="zoom-out icon" data-original-title="Contract Timeline"></div>
		</div>
	</div>
</div>
	

CSS Code

上面展示的是timeline的一个默认主题样式,下面我们一起来看看Martin Angelov是如何覆写主题样式。

首先需要创建一个新的主题样式文件“style.css”并且加载到项目中,下面我们具体来看是怎样一步一步覆写主题:

1、修改timeline的背景

		#timeline{
			background:none;
		}

		/* The individual events in the slider */
		.slider .slider-container-mask .slider-container{
			background:none;
		}

		/* Setting a custom background image */
		#timeline div.navigation{
				background: url('../img/timeline_bg.jpg') repeat;
				border-top:none;
		}
	

2、修改时间轴navigation样式

		#timeline div.navigation:before{
			position:absolute;
			content:'';
			height:40px;
			width:100%;
			left:0;
			top:-40px;
			background: url('../img/timeline_bg.jpg') repeat;
		}

		#timeline div.navigation:after{
			position:absolute;
			content:'';
			height:10px;
			width:100%;
			left:0;
			top:-40px;
			background:repeat-x;

			background-image: linear-gradient(bottom, #434446 0%, #363839 100%);
			background-image: -o-linear-gradient(bottom, #434446 0%, #363839 100%);
			background-image: -moz-linear-gradient(bottom, #434446 0%, #363839 100%);
			background-image: -webkit-linear-gradient(bottom, #434446 0%, #363839 100%);
			background-image: -ms-linear-gradient(bottom, #434446 0%, #363839 100%);
		}
	

3、给tooltips样式

		#timeline div.timenav-background{
			background-color:rgba(0,0,0,0.4) !important;
		}

		#timeline .navigation .timenav-background .timenav-interval-background{
			background:none;
		}

		#timeline .top-highlight{
			background-color:transparent !important;
		}
	

4、覆写toolbar工具栏样式

		#timeline .toolbar{
			border:none !important;
			background-color: #202222 !important;
		}

		#timeline .toolbar div{
			border:none !important;
		}
	

5、底部数据轴的样式

		#timeline .navigation .timenav .time .time-interval-minor .minor{
			margin-left:-1px;
		}
		#timeline .navigation .timenav .time .time-interval div{
			color: #CCCCCC;
		}
	

6、向前向后按钮样式

		.slider .nav-previous .icon {
			background: url("timeline.png") no-repeat scroll 0 -293px transparent;
		}

		.slider .nav-previous,.slider .nav-next{
			font-family:'Segoe UI',sans-serif;
		}

		.slider .nav-next .icon {
			background: url("timeline.png") no-repeat scroll 72px -221px transparent;
			width: 70px !important;
		}

		.slider .nav-next:hover .icon{
			position:relative;
			right:-5px;
		}

		.slider .nav-previous:hover, .slider .nav-next:hover {
				color: #666;
				cursor: pointer;
		}

		#timeline .thumbnail {
			border: medium none;
		}
	

7、loading样式

		#timeline .feedback {
			background-color: #222222;
			box-shadow: 0 0 30px rgba(0, 0, 0, 0.2) inset;
			border:none;
		}

		#timeline .feedback div{
			color: #AAAAAA;
			font-size: 14px !important;
			font-weight: normal;
		}
	

8、slider的样式

		#timeline .slider-item h2,
		#timeline .slider-item h3{
			font-family:'Antic Slab','Segoe UI',sans-serif;
		}

		#timeline .slider-item h2{
			color:#fff;
		}

		#timeline .slider-item p{
			font-family:'Segoe UI',sans-serif;
		}

		#timeline .slider-item img,
		#timeline .slider-item iframe{
			border:none;
		}
	

9、页面样式

		/* Customizing the first slide - the cover */
		#timeline .slider-item:nth-child(1) h2{
			font:normal 70px/1 'Antic Slab','Segoe UI',sans-serif;
			background:rgba(0,0,0,0.3);
			white-space: nowrap;
			padding:10px 5px 5px 20px;
			position:relative;
			right:-60px;
			z-index:10;
		}
		#timeline .slider-item:nth-child(1) p i{
			font:normal normal 40px 'Dancing Script','Segoe UI',sans-serif;
			background:rgba(0,0,0,0.3);
			white-space: nowrap;
			padding:5px 20px;
			position:relative;
			right:-60px;
			z-index:10;
		}
		#timeline .slider-item:nth-child(1) p .c1{
			color:#1bdff0;
		}
		#timeline .slider-item:nth-child(1) p .c2{
			color:#c92fe6;
		}
		#timeline .slider-item:nth-child(1) .media-container {
			left: -30px;
			position: relative;
			z-index: 1;
		}
		#timeline .slider-item:nth-child(1) .credit{
			text-align: center;
		}
	

到这主题就覆写完了,大家可以看看覆写后的样效果:

那么有关于timeline的使用就说到这里了。最后在结束此篇文章时,非常感谢VeriteCo提供的Timeline插件,特别感谢Martin Angelov 的覆写模板教程。

如果你对这个感兴趣可以到Timeline的官网查看详细的doc文档,也可以点击这里查看具体使用的案例,或者直接下载对应的demo学习。

特别声明:上面的代码来自于VeritoCoMartin Angelov

如需转载烦请注明出处:W3CPLUS

Pure CSS3 Ribbons

$
0
0

前面在CSS3 Ribbons一文中介绍了一个纯CSS3制作的“Ribbons”效果,今天收集了更多的“Ribbons”效果,以供大家参考与学习,希望大家能喜欢。

在看具体每个demo之前,我们一起来看下面一个截图:

上图是一个典型的“Ribbons”各部位的示意图,但每一个“Ribbons”并不会都使用上图示意的各个部分,在下面的实例中大家可以明显的看到或者说感受到。别的我就不多说了,我想上图能示意出“Ribbons”各个部位。那么每个部位我们可以使用一个“html”标签,当然有了CSS3的伪元素“::before”和“::after”后,我们可以省去一些标签。

效果一:

HTML Markup

	<div class="ribbons" id="ribbon-1">Ribbon-1</div>
	

CSS Code

		#ribbon-1 {
				font: bold 16px/48px Cambria,Georgia,Times,serif;
				color: #000;
				text-shadow: 1px 0 0 hsla(20,50%,30%,0.6);
				width: 300px;
				padding: 0 0 0 30px;
				background: hsla(200, 20%, 80%, 0.8);
				position: relative;
			}
			#ribbon-1::after {
				content: "";
				position: absolute;
				top: 0;
				left: 100%;
				width: 0;
				height: 0;
				border: 24px solid hsla(200, 20%, 80%, 0.8);
				border-right-color: transparent;
			}
	

DEMO效果

效果二

HTML Markup

		<div class="ribbons" id="ribbon-2">Ribbon-2</div>
	

CSS Code

		#ribbon-2 {
			font: bold 16px/48px Cambria,Georgia,Times,sans-serif;
			color:hsla(25,50%,80%,1);
			text-shadow: 1px 0 0 hsla(20,50%,30%,0.6);
			width: 300px;
			position: relative;
			background: hsla(255,45%,50%,0.8);
		}
		#ribbon-2::before {
			content:"";
			position: absolute;
			top:0;
			right: 100%;
			width: 0;
			height: 0;
			border: 24px solid hsla(255,45%,50%,0.8);
			border-left-color:transparent;
		}
		#ribbon-2::after {
			content:"";
			position:absolute;
			top:0px;
			left: 100%;
			width:0;
			height:0;
			border:24px solid transparent;
			border-left-color: hsla(255,45%,50%,0.8);
		}
	

DEMO效果:

效果三

HTML Markup

		<div class="ribbons" id="ribbon-3">Ribbon-3</div>
	

CSS Code

		#ribbon-3 {
			font: bold 16px/48px Cambria,Georgia,Times,serif;
			color: hsla(100,80%,20%,0.6);
			text-shadow: 1px 0 0 hsla(20,50%,30%,0.6);
			width: 300px;
			padding: 0 0 0 30px;
			position: relative;
			background: hsla(200,80%,50%,0.8);
		}
		#ribbon-3::before {
			content:"";
			position: absolute;
			top:100%;
			left:0px;
			width:0;
			height: 0;
			border: 5px solid transparent;
			border-color: hsla(200,70%,42%,0.8) hsla(200,70%,42%,0.8) transparent transparent;
		}
		#ribbon-3::after {
			content:"";
			position: absolute;
			top:0;
			left: 100%;
			width:0;
			height: 0;
			border: 24px solid hsla(200,80%,50%,0.8);
			border-right-color: transparent;	
		}
	

DEMO效果:

效果四

HTML Markup

		<div class="ribbons" id="ribbon-4">Ribbon-4</div>
	

CSS Code

		#ribbon-4 {
			font: bold 16px Cambria,Georgia,Times,serif;
			line-height: 48px;
			width: 315px;
			padding: 0 30px;
			position: relative;
			text-align: center;
			color: hsla(180,60%,80%,0.8);
			text-shadow: 1px 0 0 hsla(20,50%,30%,0.6);
			background: hsla(20,30%,30%,0.8);
		}
		#ribbon-4::before {
			content:"";
			position: absolute;
			top: 100%;
			left:0;
			width: 0;
			height: 0;
			border: 5px solid transparent;
			border-color: hsla(20,25%,25%,0.85) hsla(20,25%,25%,0.85) transparent transparent;
		}
		#ribbon-4::after {
			content:"";
			position: absolute;
			top: 100%;
			right: 0;
			width: 0;
			height: 0;
			border: 5px solid transparent;
			border-color: hsla(20,25%,25%,0.85) transparent transparent hsla(20,25%,25%,0.85);
		}
	

DEMO效果:

效果五

HTML Markup

		<div id="ribbon-5-wrap">
			<div class="ribbons" id="ribbon-5">
				<div>Ribbon-5</div>
			</div>
		</div>
	

CSS Code

		#ribbon-5-wrap {
			position: relative;
			z-index: 1;
		}
		#ribbon-5 {
			font: bold 16px Cambria,Georgia,Times,serif;
			line-height: 48px;
			width: 300px;
			padding: 0 30px;
			position: relative;
			color: hsla(350,80%,30%,0.8);
			text-shadow: 1px 0 0 hsla(20,50%,30%,0.6);
			background: hsla(315,40%,60%,1);
			text-align: center;
		}
		#ribbon-5::before {
			content:"";
			position:absolute;
			top:100%;
			left:0;
			width:0;
			height:0;
			border: 5px solid transparent;
			border-color: hsla(315,28%,50%,0.95) hsla(315,28%,50%,0.95) transparent transparent;
		}
		#ribbon-5::after {
			content:"";
			position:absolute;
			top:100%;
			right:0;
			width:0;
			height:0;
			border: 5px solid transparent;
			border-color: hsla(315,28%,50%,0.95) transparent transparent hsla(315,28%,50%,0.95);
		}
		#ribbon-5 > div {
			width: 100%;
		}
		#ribbon-5 > div::before,
		#ribbon-5 > div::after {
			content:"";
			position: absolute;
			width: 0;
			height:0;
			border: 24px solid hsla(315,23%,40%,0.95);
			top:10px;
			z-index: -1;
		}
		#ribbon-5 > div::before {
			border-left-color: transparent;
			right: 100%;
			margin-right: -10px;
		}
		#ribbon-5 > div::after {
			border-right-color: transparent;
			left: 100%;
			margin-left: -10px;
		}
	

DEMO效果:

效果六

HTML Markup

		<div class="ribbons" id="ribbon-6">Ribbon-6</div>
	

CSS Code

		#ribbon-6 {
			font: bold 12px Cambria,Georgia,Times,sans-serif;
			color:hsla(315,28%,50%,0.95);
			text-align: center;
			width: 90px;
			height: 50px;
			line-height: 50px;
			padding:15px 0;
			position: relative;
			background: hsla(5,58%,20%,0.95);
			margin-bottom: 120px;
		}
		#ribbon-6::after{
			content:"";
			position: absolute;
			top: 100%;
			width: 0;
			height: 0;
			border: 45px solid  hsla(5,58%,20%,0.95);
			left: 0;
			border-bottom-color: transparent;
		}
	

DEMO效果:

效果七

HTML Markup

		<div class="ribbons" id="ribbon-7">Ribbon-7</div>
	

CSS Code

		#ribbon-7 {
			font:bold 12px Cambria,Georgia,Times,Serif;
			color:#fff;
			width:100px;
			text-align:center;
			padding:15px 0px 15px;
			height:100px;
			line-height: 40px;
			background:#3B5998;
			position:relative;
			margin:20px auto 100px;
		}
		#ribbon-7:before, 
		#ribbon-7:after {
			content:"";
			position:absolute;
			bottom:-20px;
			left:-10px;
			width:0px;
			height:20px;
			border-width:20px 60px;
			border-style:solid;
			border-color:transparent #3B5998;
		}
		#ribbon-7:after {
			bottom:10px;
		}
	

DEMO效果:

效果八

HTML Markup

		<div id="ribbon-8-wrap">
			<div class="ribbons" id="ribbon-8">
				<div>
					<div>
						<div>Ribbon-8</div>
					</div>
				</div>
			</div>
		</div>
	

CSS Code

		#ribbon-8-wrap {
			position: relative;
			z-index: 1;
		}
		#ribbon-8 {
			font:bold 16px Cambria,Georgia,Times,Serif;
			color:#fff;
			width:50%;
			height:48px;
			text-align:center;
			padding:0px 30px;
			background:#AF3605;
			position:relative;
			line-height:48px;
			margin:50px auto;
		}
		#ribbon-8:before {
			content:"";
			position:absolute;
			top:100%;
			left:0px;
			width:0px;
			height:0px;
			border-width:10px;
			border-style:solid;
			border-color:#76290A #76290A transparent transparent;
		}
		#ribbon-8:after {
			content:"";
			position:absolute;
			top:100%;
			right:0px;
			width:0px;
			height:0px;
			border-width:10px;
			border-style:solid;
			border-color:#76290A transparent transparent #76290A;
		}
		#ribbon-8 div {
			width:100%;
			height:100%;
		}
		#ribbon-8 div:before, 
		#ribbon-8 div:after {
			content:"";
			position:absolute;
			width:40px;
			height:100%;
			background:#983912;
			top:20px;
			z-index:-1;
		}
		#ribbon-8 div:before {
			border-left-color:transparent;
			right:100%;
			margin-right:-20px;
		}
		#ribbon-8 div:after {
			border-right-color:transparent;
			left:100%;
			margin-left:-20px;
		}
		#ribbon-8 div div:before, 
		#ribbon-8 div div:after {
			content:"";
			position:absolute;
			width:20px;
			height:0px;
			background:transparent;
			border:25px solid #AF3605;
			top:10px;
			z-index:3;
		}
		#ribbon-8 div div:before {
			border-left-color:transparent;
			margin-right:10px;
		}
		#ribbon-8 div div:after {
			border-right-color:transparent;
			margin-left:10px;
		}
		#ribbon-8 div div div:before, 
		#ribbon-8 div div div:after {
			content:"";
			position:absolute;
			width:0px;
			height:0px;
			background:transparent;
			border:5px solid transparent;
			top:100%;
			margin-top:10px;
			z-index:1;
		}
		#ribbon-8 div div div:before {
			border-top-color:#76290A;
			border-left-color:#76290A;
			margin-left:20px;
		}
		#ribbon-8 div div div:after {
			border-top-color:#76290A;
			border-right-color:#76290A;
			margin-right:20px;
		}
	

DEMO效果:

效果九

HTML Markup

		<div class="ribbons left ribbon-holder" id="ribbon-9">
			<a href="#" class="ribbon red"><span class="text">Forke me on GitHub</span></a>
		</div>
	

CSS Code

		.ribbon-holder {
			position: relative;
		}
		.ribbon-holder {
			position: absolute;
			top: 0;
			overflow: hidden;
			height: 10em;
		}
		.left.ribbon-holder {
			left: 0;
		}
		.ribbon-holder  .ribbon,
		.ribbon-holder .ribbon:hover {
			text-decoration: none;
		}
		.ribbon-holder  .ribbon{
			font-family: Collegiate, sans-serif;
			letter-spacing: -.1px;
			opacity: 0.95;
			padding: 0.25em 0;
			position: relative;
			top: 3.2em;
			box-shadow: 0 0 13px #888;
			color: #FFF;
			display: block;
			line-height: 1.35em;
		}
		.ribbon-holder .ribbon .text {
			padding: 0.1em 3em;
		}
		.left .ribbon {
			-moz-transform: rotate(-45deg);
			-webkit-transform: rotate(-45deg);
			-ms-transform: rotate(-45deg);
			-o-transform: rotate(-45deg);
			transform: rotate(-45deg);
			left: -2.82em;
		}
		.red.ribbon {
			background-color: #9a0000;
			background-image: linear-gradient(bottom, #9a0000, #a90000);
			background-image: -o-linear-gradient(bottom, #9a0000, #a90000);
			background-image: -moz-linear-gradient(bottom,  #9a0000, #a90000);
			background-image: -webkit-linear-gradient(bottom,  #9a0000, #a90000);
			background-image: -ms-linear-gradient(bottom,  #9a0000, #a90000);
			background-image: -webkit-gradient(
				linear,
				left bottom,
				left top,
				color-stop(#9a0000),
				color-stop(#a90000)
			);
		}
		.red.ribbon .text {
			border: 1px solid #bf6060;
		}
	

DEMO效果:

效果十

HTML Markup

		<div class="ribbons right ribbon-holder" id="ribbon-10">
			<a href="#" class="ribbon green"><span class="text">Forke me on GitHub</span></a>
		</div>
	

CSS Code

		.ribbon-holder {
			position: relative;
		}
		.ribbon-holder {
			position: absolute;
			top: 0;
			overflow: hidden;
			height: 10em;
		}
		.right.ribbon-holder {
			right: 0;
		}
		.ribbon-holder  .ribbon,
		.ribbon-holder .ribbon:hover {
			text-decoration: none;
		}
		.ribbon-holder  .ribbon{
			font-family: Collegiate, sans-serif;
			letter-spacing: -.1px;
			opacity: 0.95;
			padding: 0.25em 0;
			position: relative;
			top: 3.2em;
			box-shadow: 0 0 13px #888;
			color: #FFF;
			display: block;
			line-height: 1.35em;
		}
		.ribbon-holder .ribbon .text {
			padding: 0.1em 3em;
		}
		.right .ribbon {
			-moz-transform: rotate(45deg);
			-webkit-transform: rotate(45deg);
			-o-transform: rotate(45deg);
			-ms-transform: rotate(45deg);
			transform: rotate(45deg);
			right: -2.82em;
		}
		.green.ribbon {
			background-color: #006e00;
			background-image: linear-gradient(bottom, #006e00, #007200);
			background-image: -o-linear-gradient(bottom, #006e00, #007200);
			background-image: -moz-linear-gradient(bottom,  #006e00, #007200);
			background-image: -webkit-linear-gradient(bottom,  #006e00, #007200);
			background-image: -ms-linear-gradient(bottom,  #006e00, #007200);
			background-image: -webkit-gradient(
				linear,
				left bottom,
				left top,
				color-stop(#006e00),
				color-stop(#007200)
			);
		}
		.green.ribbon .text {
			border: 1px solid #6bac6b;
		}
	

DEMO效果:

效果十一

HTML Markup

		<div class="ribbons" id="ribbon-11">Ribbon-11</div>
	

CSS Code

		#ribbon-11 {
			padding: 0 25px;
			height: 80px;
			color: #301607;
			background-color: #c94700;
			background-image: -webkit-gradient(linear, left top, left bottom, from(#c94700), to(#b84100)); 
			background-image: -webkit-linear-gradient(top, #c94700, #b84100); 
			background-image:    -moz-linear-gradient(top, #c94700, #b84100); 
			background-image:     -ms-linear-gradient(top, #c94700, #b84100); 
			background-image:      -o-linear-gradient(top, #c94700, #b84100); 
			background-image:         linear-gradient(top, #c94700, #b84100);
			border-bottom: 1px solid rgba(255, 255, 255, 0.3);
			position: relative;
			float: left;
			clear: left;
			font-family: 'Montez', cursive;
			font-size: 32px;			
			line-height: 80px;
			text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.3);
			box-shadow: -7px 7px 0px rgba(0, 0, 0, 0.3);
			border-radius: 0 0 20px 0 / 0 0 5px 0;
			margin-top: 60px;
		}			
		#ribbon-11::after {
			content: "";	
			display: block;
			width: 40px;
			height: 0px;
			position: absolute;
			right: 0;
			bottom: 4px;
			z-index: 20;
			border-bottom: 80px solid #de6625;
			border-right: 80px solid transparent;
			-webkit-transform: rotate(90deg);
			-webkit-transform-origin: right bottom;
			-moz-transform: rotate(90deg);
			-moz-transform-origin: right bottom;
			-o-transform: rotate(90deg);
			-o-transform-origin: right bottom;
			-ms-transform: rotate(90deg);
			-ms-transform-origin: right bottom;
			transform: rotate(90deg);
			transform-origin: right bottom;
		}				
		#ribbon-11::before {
			content: "";	
			display: block;
			width: 20px;
			height: 0px;
			position: absolute;
			right: 0;
			bottom: 4px;
			z-index: 10;
			border-bottom: 80px solid rgba(0, 0, 0, 0.3);
			border-right: 80px solid transparent;
			-webkit-transform: rotate(80deg);
			-webkit-transform-origin: right bottom;
			-moz-transform: rotate(80deg);
			-moz-transform-origin: right bottom;
			-o-transform: rotate(80deg);
			-o-transform-origin: right bottom;
			-ms-transform: rotate(80deg);
			-ms-transform-origin: right bottom;
			transform: rotate(80deg);
			transform-origin: right bottom;
		}
	

DEMO效果:

效果十二

HTML Markup

		<div id="ribbon-12" class="ribbons">Ribbon-12</div>
	

CSS Code

		#ribbon-12  {
			background-color: #999999;
			box-shadow: 0 2px 4px #888888;
			color: #555555;
			font-size: 1.5em;
			font-weight: bold;
			padding: 6px 20px 6px 71px;
			position: relative;
			text-shadow: 0 1px 2px #BBBBBB;
			width: 50%;
			clear: both;
		}
		#ribbon-12::before, 
		#ribbon-12::after {
			content: " ";
			height: 0;
			position: absolute;
			width: 0;
		}
		#ribbon-12::before {
			border-color: #999999 #999999 #999999 transparent;
			border-style: solid;
			border-width: 20px 10px;
			left: -30px;
			top: 12px;
			width: 30px;
		}	
		#ribbon-12::after {
			border-color: #666666 #666666 transparent transparent;
			border-style: solid;
			border-width: 5px 10px;
			left: 0;
			top: 100%;
		}
	

DEMO效果:

效果十三

HTML Markup

		<div class="ribbons" id="ribbon-13">
			<h1 class="ribbon-content"><a>A Pure CSS Ribbon</a></h1>
		</div>
	

CSS Code

		#ribbon-13 {
		 width: 300px;
		 position: relative;
		 text-align: center;
		 font-size: 20px!important;
		 background: #d64b4b;
		 background: -webkit-gradient(linear, left top, left bottom, from(#d64b4b), to(#ab2c2c));
		 background: -webkit-linear-gradient(top, #d64b4b, #ab2c2c);
		 background: -moz-linear-gradient(top, #d64b4b, #ab2c2c);
		 background: -ms-linear-gradient(top, #d64b4b, #ab2c2c);
		 background: -o-linear-gradient(top, #d64b4b, #ab2c2c);
		 background-image: -ms-linear-gradient(top, #d64b4b 0%, #ab2c2c 100%);
		 -webkit-box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
		 -moz-box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
		 box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
		 font-family: 'Helvetica Neue',Helvetica, sans-serif;
		 margin: 50px auto;
		 }
	#ribbon-13 h1 {
		 color: #801111;
		 text-shadow: #d65c5c 0 1px 0;
		 margin:0px;
		 padding: 15px 10px;
		 font-size: 1em;
		 }
	#ribbon-13::before, 
	#ribbon-13::after {
		 content: '';
		 position: absolute;
		 display: block;
		 bottom: -1em;
		 border: 1.5em solid #c23a3a;
		 z-index: -1;
		 }
	#ribbon-13::before {
		 left: -2em;
		 border-right-width: 1.5em;
		 border-left-color: transparent;
		 -webkit-box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
		 -moz-box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
		 box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
		 }
	#ribbon-13::after {
		 right: -2em;
		 border-left-width: 1.5em;
		 border-right-color: transparent;
		 -webkit-box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
		 -moz-box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
		 box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
		 }
	#ribbon-13 .ribbon-content:before, 
	#ribbon-13 .ribbon-content:after {
		 border-color: #871616 transparent transparent transparent;
		 position: absolute;
		 display: block;
		 border-style: solid;
		 bottom: -1em;
		 content: '';
		 }
	#ribbon-13 .ribbon-content:before {
		 left: 0;
		 border-width: 1em 0 0 1em;
		 }
	#ribbon-13 .ribbon-content:after {
		 right: 0;
		 border-width: 1em 1em 0 0;
		 }
	#ribbon-13 a::before{
		content:"";
		display:block;
		margin-top:2px;
		border-top: 1px dashed rgba(0, 0, 0, 0.2);
		box-shadow: 0px 0px 2px rgba(255, 255, 255, 0.5);
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
	}
	#ribbon-13 a::after{
		 margin-bottom:2px;
		 border-top: 1px dashed rgba(0, 0, 0, 0.2);
		 box-shadow: 0px 0px 2px rgba(255, 255, 255, 0.3);
		 content: "";
		 display:block;
		 width: 100%;
		 bottom: 0;
		 left: 0;
		 position: absolute;
	 }
	

DEMO效果:

效果十四

HTML Markup

		<div class="ribbons" id="ribbon-14">
			<div class="ribbon-wrapper">
				<div class="ribbon">NEWS</div>
			</div>
		</div>
	

CSS Code

		#ribbon-14 {
			margin: 50px auto;
			width: 280px;
			height: 100px;
			background: white;
			border-radius: 10px;
			box-shadow:         0px 0px 8px rgba(0,0,0,0.3);
			position: relative;
			z-index: 90;
		}
		#ribbon-14 .ribbon-wrapper{
			width: 85px;
			height: 88px;
			overflow: hidden;
			position: absolute;
			top: -3px;
			right: -3px;
		}
		#ribbon-14 .ribbon{
			font: bold 15px Sans-Serif;
			color: #333;
			text-align: center;
			text-shadow: rgba(255,255,255,0.5) 0px 1px 0px;
			-webkit-transform: rotate(45deg);
			-moz-transform:    rotate(45deg);
			-ms-transform:     rotate(45deg);
			-o-transform:      rotate(45deg);
			position: relative;
			padding: 7px 0;
			left: -5px;
			top: 15px;
			width: 120px;
			background-color: #BFDC7A;
			background-image: -webkit-gradient(linear, left top, left bottom, from(#BFDC7A), to(#8EBF45));
			background-image: -webkit-linear-gradient(top, #BFDC7A, #8EBF45);
			background-image:    -moz-linear-gradient(top, #BFDC7A, #8EBF45);
			background-image:     -ms-linear-gradient(top, #BFDC7A, #8EBF45);
			background-image:      -o-linear-gradient(top, #BFDC7A, #8EBF45);
			color: #6a6340;
			box-shadow:         0px 0px 3px rgba(0,0,0,0.3);
		}
		#ribbon-14 .ribbon::before, 
		#ribbon-14 .ribbon::after {
			content: "";
			border-top:   3px solid #6e8900;   
			border-left:  3px solid transparent;
			border-right: 3px solid transparent;
			position:absolute;
			bottom: -3px;
		}
		#ribbon-14 .ribbon::before {
			left: 0;
		}
		#ribbon-14 .ribbon::after {
			right: 0;
		}
	

DEMO效果:

效果十五

HTML Markup

		<div class="ribbons" id="ribbon-15">
			<div class="ribbon-wrap">			
				<div class="content">
					<div class="ribbon"><span>NEWS</span></div>
					<div class="box">box</div>
				</div>
			</div>
		</div>
	

CSS Code

		#ribbon-15 {
			margin: 50px aut0;
			position: relative;
			width: 400px;
		} 
		#ribbon-15 .ribbon-wrap {
			position: absolute;
			tip: 0;
			left: 0;
			width: 100%;
			padding: 5px;
			overflow: hidden;
		}
		#ribbon-15 .content {
			box-shadow: 0 0 1px rgba(0, 0, 0, 0.15);
			color: #444444;
			font: 12px/14px Arial,Helvetica,Sans-serif;
			margin: 0 auto 30px;
			position: relative;
			border: 1px solid #ccc;
			border-radius: 5px;
			background: #fff;
			min-height: 100px;
		}
		#ribbon-15 .ribbon {
				display: inline;
		}
		#ribbon-15 .ribbon span {
				-moz-transform: rotate(-45deg);
				-webkit-transform: rotate(-45deg);
				-o-transform: rotate(-45deg);
				-ms-transform: rotate(-45deg);
				transform: rotate(-45deg);
				background: none repeat scroll 0 0 #D93131;
				box-shadow: 0 0 10px rgba(0, 0, 0, 0.2), 0 5px 30px rgba(255, 255, 255, 0.2) inset;
				color: #FFFFFF;
				display: inline-block;
				font-weight: 900;
				padding: 3px 10px;
				position: absolute;
				left: -29px;
				text-align: center;
				text-transform: uppercase;
				top: 16px;
				width: 90px;
		}
		#ribbon-15 .ribbon::before {
				border-color: transparent transparent #662121;
				border-style: solid;
				border-width: 17px;
				content: "";
				height: 0;
				position: absolute;
				left: 54px;
				top: -23px;
				width: 0;
				z-index: -1;
		}
		#ribbon-15 .ribbon::after {
				border-color: #662121 transparent transparent;
				border-style: solid;
				border-width: 17px;
				content: "";
				height: 0;
				position: absolute;
				left: -10px;
				top: 67px;
				width: 0;
				z-index: -1;
		}
		#ribbon-15 .box {
			margin-left: 50px;
			padding: 20px;
		}
	

DEMO效果:

效果十六

HTML Markup

		<div class="ribbons" id="ribbon-16"><a href=""><span>Ribbon-16</span></a></div>
	

CSS Code

		#ribbon-16::after, 
		#ribbon-16::before {
			margin-top:0.5em;
			content: "";
			float:left;
			border:1.5em solid hsla(20,50%,23%,0.3);
		}
		#ribbon-16::after {
			border-right-color:transparent;
		}
		#ribbon-16::before {
			border-left-color:transparent;
		}
		#ribbon-16 a:link, 
		#ribbon-16 a:visited { 
				color:#000;
				text-decoration:none;
				float:left;
				height:3.45em;
				overflow:hidden;
		}
		#ribbon-16 span {
				background:hsla(20,50%,23%,0.3);
				display:inline-block;
				line-height:2.9em;
				padding:0 1em;
				margin-top:0.5em;
				position:relative;
				-webkit-transition: background-color 0.2s, margin-top 0.2s;  /* Saf3.2+, Chrome */
				-moz-transition: background-color 0.2s, margin-top 0.2s;  /* FF4+ */
				-ms-transition: background-color 0.2s, margin-top 0.2s;  /* IE10 */
				-o-transition: background-color 0.2s, margin-top 0.2s;  /* Opera 10.5+ */
				transition: background-color 0.2s, margin-top 0.2s;
		}
		#ribbon-16 a:hover span {
				background:#FFD204;
				margin-top:0;
		}
		#ribbon-16 span::before {
				content: "";
				position:absolute;
				top:3em;
				left:0;
				border-right:0.5em solid #9B8651;
				border-bottom:0.5em solid hsla(20,50%,23%,0.3);
		}
		#ribbon-16 span::after {
				content: "";
				position:absolute;
				top:3em;
				right:0;
				border-left:0.5em solid #9B8651;
				border-bottom:0.5em solid hsla(20,50%,23%,0.3);
		}
	

DEMO效果:

效果十七

HTML Markup

		<div class="ribbons" id="ribbon-17">
			<h1>Ribbon-17</h1>
		</div>
	

CSS Code

		#ribbon-17 {
			background-color:#999;
			background-image:-webkit-linear-gradient(top, rgba(255,255,255,0.1), rgba(0,0,0,.1));
			background-image:-moz-linear-gradient(top, rgba(255,255,255,0.1), rgba(0,0,0,.1));
			background-image:linear-gradient(top, rgba(255,255,255,0.1), rgba(0,0,0,.1));
			height:40px;
			clear:both;
			color:#fff;
			font:bold 12px/40px sans-serif;
			text-align:center;
			text-shadow:0 1px #666;
			position:relative;
			box-shadow:	0 1px 3px rgba(0,0,0,.3),0 0 0 1px #777,0 1px 0 #bbb inset;
		}
		#ribbon-17::before, 
		#ribbon-17::after {
			content:'';
			border:6px solid transparent;
			position:absolute;
			display:block;
			width:0;
			height:0;
			top:100%;
		}
		#ribbon-17::before{
			left:0;
			border-top-color:#666;
			border-left-width:7px;
			border-right-width:0;
		}
		#ribbon-17::after {
			right:0;
			border-top-color:#666;
			border-right-width:7px;
			border-left-width:0;
		}
		#ribbon-17 h1::after,
		#ribbon-17 h1::before{
			content:"";
			border:19px solid #999;
			position:absolute;
			display:block;
			width:0; height:0;
			top:7px;
			z-index:-1;
		}
		#ribbon-17 h1::after{
			box-shadow:
					0 1px 0 #777,
					0 -1px 0 #bbb,
					0 -2px 0 #777,
					1px 0 0 #777;
			border-left-color:transparent;
			left:-32px;
		}
		#ribbon-17 h1::before {
			box-shadow:
					0 1px 0 #777,
					0 -1px 0 #bbb,
					0 -2px 0 #777,
					-1px 0 0 #777;
			border-right-color:transparent;
			right:-32px;
		}
	

DEMO效果:

效果十八

HTML Markup

		<div id="ribbon-18" class="ribbons">	
			<div class="inset"></div>		
			<div class="container">
				<div class="base"></div>
				<div class="left_corner"></div>
				<div class="right_corner"></div>
			</div>
		</div>
	

CSS Demo

		#ribbon-18 {
			width: 180px;
			height: 280px;
			margin: 50px auto 0;
			position: relative;
			overflow: hidden;
		}
		#ribbon-18 .inset {
			width: 200px;
			height: 55px;
			position: absolute;
			top: -50px;
			left: -10px;
			z-index: 5;
			border-radius: 50%;
			background: rgba(0,0,0,0.3);
			box-shadow: 0px 5px 10px 0px rgba(0,0,0,0.3);
		}
		#ribbon-18 .container {
			position: relative;
			width: 100px;
			height: 250px;
			overflow: hidden;
			margin: 0 auto;
			border-left: 1px solid #631a15;
			border-right: 1px solid #631a15;
		}
		#ribbon-18 .base {
			height: 200px;
			width: 100px;			
			background: rgb(199,59,60);
			background: -moz-linear-gradient(top,  rgba(199,59,60,1) 0%, rgba(184,32,31,1) 100%);
			background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(199,59,60,1)), color-stop(100%,rgba(184,32,31,1)));
			background: -webkit-linear-gradient(top,  rgba(199,59,60,1) 0%,rgba(184,32,31,1) 100%);
			background: -o-linear-gradient(top,  rgba(199,59,60,1) 0%,rgba(184,32,31,1) 100%);
			background: -ms-linear-gradient(top,  rgba(199,59,60,1) 0%,rgba(184,32,31,1) 100%);
			background: linear-gradient(top,  rgba(199,59,60,1) 0%,rgba(184,32,31,1) 100%);
			filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c73b3c', endColorstr='#b8201f',GradientType=0 );
			position: relative;
			z-index: 2;
		}
		#ribbon-18 .base:after {
			content: '';
			position: absolute;
			top: 0;
			width: 86px;
			left: 6px;
			height: 242px;
			border-left: 1px dashed #631a15;
			border-right: 1px dashed #631a15;
		}
		#ribbon-18 .base:before {
			content: '';
			position: absolute;
			top: 0;
			width: 86px;
			left: 7px;
			height: 242px;
			border-left: 1px dashed #da5050;
			border-right: 1px dashed #da5050;
		}
		#ribbon-18 .left_corner {
			width: 100px;
			height: 100px;
			background: #b8201f;
			position: absolute;
			bottom: 20px;
			left: -50px;
			z-index: 1;			
			-webkit-transform: rotate(45deg);
			-moz-transform: rotate(45deg);
			-ms-transform: rotate(45deg);
			-o-transform: rotate(45deg);
			transform: rotate(45deg);
		}
		#ribbon-18 .right_corner {
			width: 100px;
			height: 100px;
			background: #b8201f;
			position: absolute;
			bottom: 20px;
			right: -50px;
			z-index: 1;			
			-webkit-transform: rotate(45deg);
			-moz-transform: rotate(45deg);
			-ms-transform: rotate(45deg);
			-o-transform: rotate(45deg);
			transform: rotate(45deg);
		}
	

效果:

上面总共收集了十八种CSS3制作的Ribbons,我想这些效果较为齐全了,希望对大家日后的工作有所帮助,或者对您的学习有所帮助,希望大家喜欢。如果您想了解更多,可以点击这里查看所有DEMO效果,也可以下载源码到本地慢慢学习。如果您有更好的实例或者想法可以在下面的评论中给我留言,与我们一起分享。

如需转载烦请注明出处:W3CPLUS


CSS3 Media Queries模板

$
0
0

最早在《CSS3 Media Queries》一文中初探了CSS3的媒体类型和媒体特性的相关应用。简单的知道了使用这个能在各种不同的设备显示不一样的样式风格。随着Responsive的响应式设计的兴起,前面跟大家一起学习了:

  1. Responsive设计和CSS3 Media Queries的结合
  2. 了解Responsive网页设计的三个特性
  3. Responsive设计的关键三步

从这几篇文章中可以知道,在Responsiv的设计中,CSS3的Media是起着非常关键性的作用,也可以说没有CSS3 Media这个属性,Responsiv设计是玩不起来,也是玩不转的。大家都知道Responsiv是为各种不同的设备进行样式设计的,但有一个问题大家或许还处在模糊状态,这个CSS3 Media要如何设置各自的临界点?

那么今天我们就针对上面的问题,一起来探讨一下CSS3 Media Queries在各种不同设备(桌面,手机,笔记本,ios等)下的模板制作。那么Media Queries是如何工作的?那么有关于他的工作原理大家要是感兴趣的话可以参考《CSS3 Media Queries》一文,里面已经做过详细的介绍,这里就不在进行过多的阐述。

CSS3 Media Queries模板

CSS3 Media Queries一般都是使用“max-width”和“min-width”两个属性来检查各种设备的分辨大小与样式表所设条件是否满足,如果满足就调用相应的样式。打个比方来说,如果你的Web页面在960px的显屏下显示,那么首先会通过CSS3 Media Queries进行查询,看看有没有设置这个条件样式,如果找到相应的,就会采用对应下的样式,其他的设备是一样的道理。下面具体看看“max-width”和“min-width”模板:

使用max-width

		@media screen and (max-width: 600px) {
			//你的样式放在这里....
		}
	

使用min-width

		@media screen and (min-width: 900px) {
			//你的样式放在这里...
		}
	

max-width和min-width的混合使用

		@media screen and (min-width: 600px) and (max-width: 900px) {
			//你的样式放在这里...
		}
	

同时CSS3 Media Queries还能查询设备的宽度“device-width”来判断样式的调用,这个主要用在iPhone,iPads设备上,比如像下面的应用:

iPhone和Smartphones上的运用

		/* iPhone and Smartphones (portrait and landscape) */
		@media screen and (min-device-width : 320px) and (max-device-width: 480px) {
			//你的样式放在这里...
		}
	

max-device-width指的是设备整个渲染区宽度(设备的实际宽度)

iPads上的运用

		/* iPads (landscape) */
		@media screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
			//你的样式放在这里...
		}
		/* iPads (portrait) */
		@media screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
			//你的样式放在这里...
		}
	

针对移动设备的运用,如果你想让样式工作得比较正常,需要在“<head>”添加“viewport”的meta标签:

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

有关于这方面的介绍大家可以看看这个blog上进行的的移动端开发的相关总结。

调用独立的样式表

你可能希望在不同的设备下调用不同的样式文件,方便管理或者维护,那么你可以按下面的这种方式进行调用:

		<link rel="stylesheet" media="screen and (min-device-width : 320px) and (max-device-width: 480px)" href="iphone.css" />
		<link rel="stylesheet" media="screen and (min-device-width : 768px) and (max-device-width : 1024px)" href="ipad.css" />
	

CSS3 Media Queries在标准设备上的运用

下面我们一起来看看CSS3 Meida Queries在标准设备上的运用,大家可以把这些样式加到你的样式文件中,或者单独创建一个名为“responsive.css”文件,并在相应的条件中写上你的样式,让他适合你的设计需求:

1、1024px显屏

		@media screen and (max-width : 1024px) {
			/* CSS Styles */
		}
	

2、800px显屏

		@media screen and (max-width : 800px) {
			/* CSS Styles */
		}
	

3、640px显屏

		@media screen and (max-width : 640px) {
			/* CSS Styles */
		}
	

4、iPad横板显屏

		@media screen and (max-device-width: 1024px) and (orientation: landscape) {
			/* CSS Styles */
		}
	

5、iPad竖板显屏

		@media screen and (max-device-width: 768px) and (orientation: portrait) {
			/* CSS Styles */
		}
	

iPhone 和 Smartphones

		@media screen and (min-device-width: 320px) and (min-device-width: 480px) {
			/* CSS Styles */
		}
	

现在有关于这方面的运用也是相当的成熟,twitter的Bootstrap第二版本中就加上了这方面的运用。大家可以对比一下:

	// Landscape phones and down
	@media (max-width: 480px) { ... }
	 
	// Landscape phone to portrait tablet
	@media (max-width: 768px) { ... }
	 
	// Portrait tablet to landscape and desktop
	@media (min-width: 768px) and (max-width: 980px) { ... }
	 
	// Large desktop
	@media (min-width: 1200px) { .. }
	

bootstrap中的responsive.css采用的是网格布局,大家可以到官网查看或下载其源码进行学习。另外960gs为大家提供了一个Adapt.js也很方便的帮大家实现上述效果。感兴趣的同学可以去了解了解。

下面给大家提供几个这方面的案例,以供大家参考:

  1. CSS3 Media Queries案例——Hicksdesign
  2. CSS3 Media Queries案例——Tee Gallery
  3. CSS3 Media Queries案例——A List Apart

更新CSS3 Media Queries模板查询

1、Smartphones (portrait and landscape)

@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
	/* Styles */
}

2、Smartphones (landscape)

@media only screen and (min-width : 321px) {
	/* Styles */
}

3、Smartphones (portrait)

@media only screen and (max-width : 320px) {
	/* Styles */
}

4、iPads (portrait and landscape)

@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
	/* Styles */
}

5、iPads (landscape)

@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
	/* Styles */
}

6、iPads (portrait)

@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
	/* Styles */
}

7、iPhone 4

@media only screen and (-webkit-min-device-pixel-ratio : 1.5),only screen and (min-device-pixel-ratio : 1.5) {
	/* Styles */
}

8、640px显屏

@media screen and (max-width : 640px) {
	/* CSS Styles */
}

9、800px显屏

@media screen and (max-width : 800px) {
	/* CSS Styles */
}

10、1024显屏

@media screen and (max-width : 1024px) {
	/* CSS Styles */
}

11、Desktops and laptops

@media only screen and (min-width : 1224px) {
	/* Styles */
}

12、Large screens

@media only screen and (min-width : 1824px) {
	/* Styles */
}

那么有关于CSS3 Media Queries模板的相关介绍就说到这里了,最后希望大家喜欢。如果你觉得这篇文章对你有所帮助或者比较有实用价值,您可以把他推荐给您的朋友,如果你有更好的分享可以在下面的评论中直接与我们一起分享您的经验。

如需转载烦请注明出处:W3CPLUS

@font-face制作Web Icon

$
0
0

@font-faceCSS3中有关于字体设置的属性,通过@font-face可以将本地字体设置为Web页面字体,并能兼容所有浏览器,使用这个属性就不必担心用户本地不具备这样的字体。因为我们把字体都上传到服务器上,不过这样一来很多人担心影响性能问题。鱼和熊掌不能兼得嘛,我们就不在为这个问题说太多的话了,不过我今天要与大家分享的主题和这个@font-face还是有很在关系的,使用他配合一定的字体来制作Web页面中的Icon图标。初一看有点不实际,以前的Icon都是依靠图片来完成,怎么可能用字体就能实现呢?如果你以前有用过HTML的实体符,我想就不会那么惊奇了。

如果你以前关注过本站,我想这个你并不会陌生,因为我在css3制作3D分页导航一文中就有用到@font-face来制作icon的效果:

今天我想和大家进一步的探讨这方面的应用,同时为大家准备了多种字体制作Icon的效果,下面我们一起来看看吧。

制作思路

思路其实很清晰,我们就是需要得到font icon的字体,然后通过@font-face将这个字体运用到一定的字符上,从而让他渲染出来是ICON的效果。难就难在无法得到这样的字体,今天我给大家搜集了三种免费的字体,以供大家学习。接下来我们一起来学习这三种字体如何转换成Web上的Icon图标。

第一种:Guifx字体

要使用Guifx字体制作Icon,你首先要得到相应的字体,然后通过fontsquirrel转换各浏览器所需的字体,详细的操作过程大家可以参考@font-face

字体得到了就好办了,现在只需要使用一定的编码来代表相应的字符,打个比方来说:

		<div class="icon">A</div>
	

那么上面的“A”字符代表的就是一个Icon,只不过我们需要把刚才得到字体运用上去:

		@font-face {
    font-family: 'GuifxIcon';
    src: url('Guifx/guifx_v2_transports-webfont.eot');
    src: url('Guifx/guifx_v2_transports-webfont.eot?#iefix') format('embedded-opentype'),
    url('Guifx/guifx_v2_transports-webfont.woff') format('woff'),
    url('Guifx/guifx_v2_transports-webfont.ttf') format('truetype'),
    url('Guifx/guifx_v2_transports-webfont.svg#Guifxv2TransportsRegular') format('svg');
    font-weight: normal;
    font-style: normal;
    }
    .icon {
    font-family: 'GuifxIcon';
    }
	

这样运用过后,"A"在web中就渲染成下图的icon效果:

上面拿了一个简单的Icon来做实例,其他的运用也是这样的,下面我将对应的字符和Icon对照表放上来让大家使用时好参考,省得测试的时间:

有关于详细的代码大家可以查看这里,当然你可以点击下载相关字体和代码。

第二种:websymbols字体

这种字体其实运用和前面介绍的方法是一样的,唯一区别是使用的字体不一样,从而字母渲染出来的Icon也就不一样了。下面我们同样来看“A”渲染出来的效果

		<div class="icon">A</div>
	

样式的使用:

		@font-face{ 
			font-family: 'WebSymbolsRegular';
			src: url('websymbols/fonts/websymbols-regular-webfont.eot');
			src: url('websymbols/fonts/websymbols-regular-webfont.eot?#iefix') format('embedded-opentype'),
					 url('websymbols/fonts/websymbols-regular-webfont.woff') format('woff'),
					 url('websymbols/fonts/websymbols-regular-webfont.ttf') format('truetype'),
					 url('websymbols/fonts/websymbols-regular-webfont.svg#WebSymbolsRegular') format('svg');
		}
		.icon {
    font-family: 'WebSymbolsRegular';
    }
	

对应出来的Icon就是下图的样子了:

我想大家肯定也在头痛字体的来源吧,不急,点这里下载吧。同样给大家附上相应的字符照图,以供大家参考:

有关于详细的代码大家可以查看这里,当然你可以点击下载相关字体和代码。

第三种:Font Awesome

Font Awesome是一个强大的字体制作Icon的案例,作者在Bootstrap Icon的基础上将Icon图片换成了字体来制作。初看真的让我汗颜呀,太强大了。下面我们一起来看看如何使用?

HTML Markup

		 <div class="icon-glass"></div>
	

相对来说这个字体制作ICON复杂一点,他是在Bootstrap Icon基础上扩展的,只不过区别是Bootstrap Icon采用的是IMG,而他采用的是@font-face:

		@font-face {
  font-family: 'FontAwesome';
  src: url('font/fontawesome-webfont.eot');
  src: url('font/fontawesome-webfont.eot?#iefix') format('embedded-opentype'), url('../font/fontawesome-webfont.woff') format('woff'), url('../font/fontawesome-webfont.ttf') format('truetype'), url('../font/fontawesome-webfont.svgz#FontAwesomeRegular') format('svg'), url('../font/fontawesome-webfont.svg#FontAwesomeRegular') format('svg');
  font-weight: normal;
  font-style: normal;
}
/* sprites.less reset */
[class^="icon-"], 
[class*=" icon-"] {
  display: inline;
  width: auto;
  height: auto;
  line-height: inherit;
  vertical-align: baseline;
  background-image: none;
  background-position: 0% 0%;
  background-repeat: repeat;
}
[class^="icon-"]:before, 
[class*=" icon-"]:before {
  font-family: FontAwesome;
  font-weight: normal;
  font-style: normal;
  display: inline-block;
  text-decoration: inherit;
}
/*  Font Awesome uses the Unicode Private Use Area (PUA) to ensure screen
    readers do not read off random characters that represent icons */
.icon-glass:before              { content: "\f000"; }
.icon-music:before              { content: "\f001"; }
.icon-search:before             { content: "\f002"; }
.icon-envelope:before           { content: "\f003"; }
.icon-heart:before              { content: "\f004"; }
.icon-star:before               { content: "\f005"; }
.icon-star-empty:before         { content: "\f006"; }
.icon-user:before               { content: "\f007"; }
.icon-film:before               { content: "\f008"; }
.icon-th-large:before           { content: "\f009"; }
.icon-th:before                 { content: "\f00a"; }
.icon-th-list:before            { content: "\f00b"; }
.icon-ok:before                 { content: "\f00c"; }
.icon-remove:before             { content: "\f00d"; }
.icon-zoom-in:before            { content: "\f00e"; }

.icon-zoom-out:before           { content: "\f010"; }
.icon-off:before                { content: "\f011"; }
.icon-signal:before             { content: "\f012"; }
.icon-cog:before                { content: "\f013"; }
.icon-trash:before              { content: "\f014"; }
.icon-home:before               { content: "\f015"; }
.icon-file:before               { content: "\f016"; }
.icon-time:before               { content: "\f017"; }
.icon-road:before               { content: "\f018"; }
.icon-download-alt:before       { content: "\f019"; }
.icon-download:before           { content: "\f01a"; }
.icon-upload:before             { content: "\f01b"; }
.icon-inbox:before              { content: "\f01c"; }
.icon-play-circle:before        { content: "\f01d"; }
.icon-repeat:before             { content: "\f01e"; }

/* \f020 is not a valid unicode character. all shifted one down */
.icon-refresh:before            { content: "\f021"; }
.icon-list-alt:before           { content: "\f022"; }
.icon-lock:before               { content: "\f023"; }
.icon-flag:before               { content: "\f024"; }
.icon-headphones:before         { content: "\f025"; }
.icon-volume-off:before         { content: "\f026"; }
.icon-volume-down:before        { content: "\f027"; }
.icon-volume-up:before          { content: "\f028"; }
.icon-qrcode:before             { content: "\f029"; }
.icon-barcode:before            { content: "\f02a"; }
.icon-tag:before                { content: "\f02b"; }
.icon-tags:before               { content: "\f02c"; }
.icon-book:before               { content: "\f02d"; }
.icon-bookmark:before           { content: "\f02e"; }
.icon-print:before              { content: "\f02f"; }

.icon-camera:before             { content: "\f030"; }
.icon-font:before               { content: "\f031"; }
.icon-bold:before               { content: "\f032"; }
.icon-italic:before             { content: "\f033"; }
.icon-text-height:before        { content: "\f034"; }
.icon-text-width:before         { content: "\f035"; }
.icon-align-left:before         { content: "\f036"; }
.icon-align-center:before       { content: "\f037"; }
.icon-align-right:before        { content: "\f038"; }
.icon-align-justify:before      { content: "\f039"; }
.icon-list:before               { content: "\f03a"; }
.icon-indent-left:before        { content: "\f03b"; }
.icon-indent-right:before       { content: "\f03c"; }
.icon-facetime-video:before     { content: "\f03d"; }
.icon-picture:before            { content: "\f03e"; }

.icon-pencil:before             { content: "\f040"; }
.icon-map-marker:before         { content: "\f041"; }
.icon-adjust:before             { content: "\f042"; }
.icon-tint:before               { content: "\f043"; }
.icon-edit:before               { content: "\f044"; }
.icon-share:before              { content: "\f045"; }
.icon-check:before              { content: "\f046"; }
.icon-move:before               { content: "\f047"; }
.icon-step-backward:before      { content: "\f048"; }
.icon-fast-backward:before      { content: "\f049"; }
.icon-backward:before           { content: "\f04a"; }
.icon-play:before               { content: "\f04b"; }
.icon-pause:before              { content: "\f04c"; }
.icon-stop:before               { content: "\f04d"; }
.icon-forward:before            { content: "\f04e"; }

.icon-fast-forward:before       { content: "\f050"; }
.icon-step-forward:before       { content: "\f051"; }
.icon-eject:before              { content: "\f052"; }
.icon-chevron-left:before       { content: "\f053"; }
.icon-chevron-right:before      { content: "\f054"; }
.icon-plus-sign:before          { content: "\f055"; }
.icon-minus-sign:before         { content: "\f056"; }
.icon-remove-sign:before        { content: "\f057"; }
.icon-ok-sign:before            { content: "\f058"; }
.icon-question-sign:before      { content: "\f059"; }
.icon-info-sign:before          { content: "\f05a"; }
.icon-screenshot:before         { content: "\f05b"; }
.icon-remove-circle:before      { content: "\f05c"; }
.icon-ok-circle:before          { content: "\f05d"; }
.icon-ban-circle:before         { content: "\f05e"; }

.icon-arrow-left:before         { content: "\f060"; }
.icon-arrow-right:before        { content: "\f061"; }
.icon-arrow-up:before           { content: "\f062"; }
.icon-arrow-down:before         { content: "\f063"; }
.icon-share-alt:before          { content: "\f064"; }
.icon-resize-full:before        { content: "\f065"; }
.icon-resize-small:before       { content: "\f066"; }
.icon-plus:before               { content: "\f067"; }
.icon-minus:before              { content: "\f068"; }
.icon-asterisk:before           { content: "\f069"; }
.icon-exclamation-sign:before   { content: "\f06a"; }
.icon-gift:before               { content: "\f06b"; }
.icon-leaf:before               { content: "\f06c"; }
.icon-fire:before               { content: "\f06d"; }
.icon-eye-open:before           { content: "\f06e"; }

.icon-eye-close:before          { content: "\f070"; }
.icon-warning-sign:before       { content: "\f071"; }
.icon-plane:before              { content: "\f072"; }
.icon-calendar:before           { content: "\f073"; }
.icon-random:before             { content: "\f074"; }
.icon-comment:before            { content: "\f075"; }
.icon-magnet:before             { content: "\f076"; }
.icon-chevron-up:before         { content: "\f077"; }
.icon-chevron-down:before       { content: "\f078"; }
.icon-retweet:before            { content: "\f079"; }
.icon-shopping-cart:before      { content: "\f07a"; }
.icon-folder-close:before       { content: "\f07b"; }
.icon-folder-open:before        { content: "\f07c"; }
.icon-resize-vertical:before    { content: "\f07d"; }
.icon-resize-horizontal:before  { content: "\f07e"; }

.icon-bar-chart:before          { content: "\f080"; }
.icon-twitter-sign:before       { content: "\f081"; }
.icon-facebook-sign:before      { content: "\f082"; }
.icon-camera-retro:before       { content: "\f083"; }
.icon-key:before                { content: "\f084"; }
.icon-cogs:before               { content: "\f085"; }
.icon-comments:before           { content: "\f086"; }
.icon-thumbs-up:before          { content: "\f087"; }
.icon-thumbs-down:before        { content: "\f088"; }
.icon-star-half:before          { content: "\f089"; }
.icon-heart-empty:before        { content: "\f08a"; }
.icon-signout:before            { content: "\f08b"; }
.icon-linkedin-sign:before      { content: "\f08c"; }
.icon-pushpin:before            { content: "\f08d"; }
.icon-external-link:before      { content: "\f08e"; }

.icon-signin:before             { content: "\f090"; }
.icon-trophy:before             { content: "\f091"; }
.icon-github-sign:before        { content: "\f092"; }
.icon-upload-alt:before         { content: "\f093"; }
.icon-lemon:before              { content: "\f094"; }
	

有关详细的使用大家可以点击官网。下图是部分类名对应的icon图标

这个比较有名气的使用方法,也是一个开源的宝贝,大家可以通过多种路径下载到相应的源码,然后按其api运用到你的项目中。如果你对这个感兴趣可以点击这里下载所需文件和源码。或者到Github上查和下载所有源码。

上面给大家介绍了三种字体,配合@font-face制作web icon方法,希望对大家以后的运用上有所帮助。

如需转载烦请注明出处:W3CPLUS

修复iPhone上submit按钮bug

$
0
0

自从完成上次iPhone的几个页面效果后,一直在没有制作iPhone的页面效果了,今天在公司写了一个登录页面效果,让我碰到一个怪异的问题——“表单中的input[type="submit"]和input[type="reset"]按钮在iPhone的safari浏览器下圆角有一个bug”。下面我来简单的描述一下这个bug的样子:

初载入页面后,表单中的input[type="submit"]和input[type="reset"]按钮渲染成下图的样子:

奇怪的是你点击以后就会正常:

对比一下,你也会觉得怪,怪都算了,还不知道如何下手:

或许很多同学会认为我的样式代码没写好,那么想让大家知道是怎么一回事,先来看看我写的代码:

input[type="submit"]和input[type="reset"]样式代码:

		.form-actions input{
			width: 30%;
			cursor: pointer;	
			background: rgb(61, 157, 179);
			padding: 8px 5px;
			font-family: 'BebasNeueRegular','Arial Narrow',Arial,sans-serif;
			color: #fff;
			font-size: 24px;	
			margin: 5px;
			border: 1px solid rgb(28, 108, 122);	
			margin-bottom: 10px;	
			text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
			border-radius: 3px;	
			box-shadow:0px 1px 6px 4px rgba(0, 0, 0, 0.07) inset,
	        0px 0px 0px 3px rgb(254, 254, 254),
	        0px 5px 3px 3px rgb(210, 210, 210);
		 -webkit-transition: all 0.2s linear;
	        transition: all 0.2s linear;
		}
		.form-actions input:hover{
			background: rgb(74, 179, 198);
		}
		.form-actions input:active,
		.form-actions input:focus{
			background: rgb(40, 137, 154);
			position: relative;
			top: 1px;
			border: 1px solid rgb(12, 76, 87);	
		  box-shadow: 0px 1px 6px 4px rgba(0, 0, 0, 0.2) inset;
		}
	

这样的代码在浏览器中浏览是完全没有问题的:

注:请使用safari测试上面代码

可是上面的代码就在iPhone的Safari浏览器下出开头所陈述的问题。一下真不好如何动手解决,因为从来没有接触过,所以就一直没有碰到过。但问题出了,就要想办法解决,于是在GG上搜索“input submit for iPhone”,还真找到了问题所在。Styling Submit Buttons for Mobile Safari中介绍的内容和我碰到的问题可真是一模一样,按其方法在样式中加入:

	.form-actions input{
		...	
	   -webkit-appearance: none;     
	}
	

更新到iPhone一看,真爽,问题解决了。

原来问题出在这里,iPhone上的safari解析input[type="submit"]和input[type="reset"]按钮会以苹果浏览器的默认UI渲染,这样就出现我刚才那种现像,我们在样式中明确的设置了button的圆角值,但到iPhone的safari上就不生效了。要想让他生效,就需要在样式中明确的指名:

	.form-actions input{
		...	
	   -webkit-appearance: none;     
	}
	

告诉浏览器我们不希望按钮按苹果的默认UI来渲染。

那么"-webkit-appearance"对button还有什么影响呢?大家可以参考下面的截图:

上图所显示的效果,都将button设置了:

		.button {
			border-radius: 0;
		}
	

效果图明显的告诉我们,在不同的“-webkit-appearance”选值情况下,button所渲染的效果是不一样的,详细的测试代码大家可使用safari浏览器点击这里。有关于“-webkit-appearance”的详细介绍,大家还可以参阅:

  1. -webkit-appearance properties
  2. Trent Walton on -webkit-appearance
  3. Safari CSS Reference

这回算是知道了,最后我建议大家,我们可以直接在“reset.css”样式文件中加处这么一句:

		input[type="submit"],
		input[type="reset"],
		input[type="button"],
		button {
			-webkit-appearance: none;
		}
	

这样一来就不会为这样的问题头痛了。

如果你还没有碰到,或者你也在开发移动端web,都希望你记住这个小技巧,因为当你在制作中碰到这样的问题时,不会为此抓破头皮,能解决你问题。最后希望大家喜欢这篇文章,如果你觉得对你有所帮助,可以推荐给你的朋友,或者有更好的分享可以在下面的评论中直接给我们留言。

如需转载烦请注明出处:W3CPLUS

手机上网站导航的制作

$
0
0

为了让Web页面在手机上显示流畅,现在国外很多网站都使用Responsive设计和CSS3 Media Queries的结合来实现。这样的实例到处可见,那么今天我想和大家一起学习的是有关于这种方法实现手机布局中的导航制作。

如果你的导航选项比较多,放到手机上来浏览就会挤到一起,造成美观性的不足。下面为了解决这样的问题,我们就一起跟随Nick La写的教程《Mobile Navigation Design & Tutorial》学习如何使用jQuery来解决刚才所说的问题。

问题的描述

下面的截图说明了导航布局在手机上的问题。如果你的导航只有三到四个选项,如Web Designer Wall网站,导航刚好一行能显示,但当你的导航选项包含更多时,其实的选项就会被挤压下去,比如说Bitfoundry网站。下面可以看看他们对比的截图:

解决方法

Nick La在教程中罗列了几种相关的解决方法:

1、下拉选择

这种方法是将所有的导航选项放到一个下拉选择控制(select)中,但这种方法并不是很好,因为select的样式要制作到让各浏览器下完全一致是非常的麻烦。除非你使用jQuery的插件,比如说Chosen插件能帮你实现select的样式美化,否则的话你只好采用select的默认样式风格。这也将导致用户的体验不一样,在桌面系统下是链接标签,而在手机上却是下拉选择框。如果你喜欢这种解决方式,你可以仔细阅读CSS-Tricks写的Convert a Menu to a Dropdown for Small Screens一文。也可以参考下面的网站

2、显示成块状

第二种方法是将所有导航通过"display:block",并将float去掉,将每个导航项设置成一个块项,这是一种快速的解决方法,不过同时也带来一个不足之处,给头部带来很大的空间,本来手机屏幕空间就小,这样一来,整个屏幕或许只能看到你的导航选项了。这样导致用户体验就差,需要滚动到底部才能看到页面的主内容。比如说下面的几个案例。

3、菜单图标

最后一种解决方法是使用菜单图标名菜单按钮。这种效果是借助jquery来实现的。在页面截入时,显示一个菜单的图标或按钮,而导航选项是隐藏的,当你点击这个图标时导航选项将显示出来,再次点击时这们导航选项将隐藏。这种方法将是最适合的一种方法,完全可以通过css来实现,如果你还需要兼容ie的话,那这种功能你就在考虑配合jQ来完成,下面列出几个案例,供大家参考:

在众多按例中,我比较喜欢bootstrap的,大家感兴趣可以去看看bootstrap的api

jQuery制作手机导航

上面给大家展示了三种不同的方法实现手机导航效果,下面我们来看看如何使用jQuery实现上面介绍的第三种方法。

方法很简单,使用jQuery的prepend方法在导航中插入一个菜单按钮,然后给这个按钮绑定一个click事件,点击实现显示/隐藏效果,具体方法如下:

HTML Markup

		<nav id="nav-wrap">
			<ul id="nav">
				<li><a href="#">Button</a></li>
				<li><a href="#">Button</a></li>
			</ul>
		</nav>
	

上面结构是一个制作导航菜单的模板,极其的常见,在些不做过多描述。

jQuery Code

使用jQuery的prepend方法,将“<div id="menu-icon">”插入到“<nav id="nav-wrap">”前面,并在“div#menu-icon”上绑定一个click事件,实现导航的显示/隐藏功能

	jQuery(document).ready(function($){
	/* prepend menu icon */
	$('#nav-wrap').prepend('<div id="menu-icon">Menu</div>');
	
	/* toggle nav */
	$("#menu-icon").on("click", function(){
		$("#nav").slideToggle();
		$(this).toggleClass("active");
	});

});
	

此时导航的HTML Markup并变成下面这样:

		<nav id="nav-wrap">
	<div id="menu-icon">Menu</div>
	<ul id="nav">
		<li><a href="#">Button</a></li>
		<li><a href="#">Button</a></li>
	</ul>
</nav>
	

CSS Code

结构有了,功能也有了,但还需要CSS来美化,那么有关于CSS详细的代码在此就不做过多得的罗列,此处只给大家介绍几个关键部分。

首先在样式中将“div#menu-icon”隐藏起来(display:none),然后通过CSS3 Media Queries来重置div#menu-icon样式。换句话说当显屏宽度小于600px时,将div#menu-icon重设置为显示(display:block)。

		@media screen and (max-width:600px){
			#menu-icon {
				color: #000;
				width: 42px;
				height: 30px;
				background: url(images/menu-icon.png) no-repeat left center;
				padding: 8px 10px 42px;
				cursor: pointer;
				border: 1px solid #666;
				display: block;/*显示div#menu-icon*/
			}
			#nav {
				clear: both;
				position: absolute;
				top: 38px;
				width: 160px;
				z-index: 10000;
				padding: 5px;
				background: #f8f8f8;
				border: 1px solid #999;
				display: none;/*默认隐藏,通过jq实现显示隐藏切换*/
			}
		}
	

通过CSS3 Media Queries在手机浏览器上,将#nav设置为隐藏,这样主要实现实初截入时隐藏导航,然后通过上面写的jq来实现,点击“div#menu-icon”图标时,显示导航菜单项,在点击时就隐藏导航菜单项。如图所示:

DEMO效果

上面DEMONick La给大家写的一个效果,感兴趣的话可以看看,不过记得使用iPhone查看,不然就看不到下图的效果:

那么有关于手机上导航制作方法就介绍完了,上面方法各有所长,就像Nick La介绍的一样,最后取决需要大家自己根据需求去定夺,此文仅供参考,希望大家喜欢,如果您觉得对你有所帮助,请将此文发送给你的朋友,如果你还有更好的建议也可以在下面的评论中与我们一起分享您的经验。最后再次感谢Nick La给我们带来这么好的教程

如需转载烦请注明出处:W3CPLUS

CSS3 Media Queries在iPhone4和iPad上的运用

$
0
0

CSS3 Media Queries的介绍在本站上的介绍已有好几篇文章了,但自己碰到的问题与解决的文章还是相对的较少。前几天在《修复iPhone上submit按钮bug》上介绍了修复form中sumit按钮的bug。同一个项目,为了实现iPhone和iPad横板与竖板的风格,让我还是头疼了一翻。

一开始按照CSS3 Media Queries模板中的介绍来运用,虽然帮我解决了iPad的横板与竖板的风格渲染问题,但在iPhone4上还是存在问题的。后来结过网上的查找,总算是问题解决了,下面就来看看问题是如何解决的。

在具体开始之前,先来看看他的源码:

	<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
	<title>login form</title>
	<style type="text/css" media="screen">
		button,
		input{
		  margin: 0;
		  font-size: 100%;
		  vertical-align: middle;
		  *overflow: visible;
		  line-height: normal;
		}
		button::-moz-focus-inner,
		input::-moz-focus-inner {
		  padding: 0;
		  border: 0;
		}
		button,
		input[type="button"],
		input[type="reset"],
		input[type="submit"] {
		  cursor: pointer;
		  -webkit-appearance: button;
		}
	
		body {
			margin: 0;
			padding: 58px 2% 2%;
		  background: -webkit-gradient(
		  	linear, 
		  	left top, 
		  	left bottom, 
		  	color-stop(0%,rgba(61,157,179,1)), 
		  	color-stop(15%,rgba(61,157,179,0.3)), 
		  	color-stop(40%,rgba(61,157,179,.5)),
		  	color-stop(70%,rgba(239,239,239,.4)),
		  	color-stop(100%,rgba(239,239,239,0.3)));
			background: -webkit-linear-gradient(
				top, 
				rgba(61,157,179,1) 0%,
				rgba(61,157,179,0.8) 15%,
				rgba(61,157,179,.5) 40%,
				rgba(239,239,239,.4) 70%,
				rgba(239,239,239,0.3) 100%);
		  	background-repeat: no-repeat;
				background-attachment: fixed;
		}
		form {
			margin: 0;
			padding: 0;
		}
		form fieldset {
			border: none;
			border-radius: 10px;
			box-shadow: inset 0 0 2px rgba(0,0,0,0.3),0 0 5px rgba(0,0,0,0.13);
			background-color: rgba(255,255,255,0.8);
		  background-image: -webkit-gradient(linear, 0 0, 0 100%, from(rgba(255,255,255,0.8)), to(rgba(216,216,216,0.8)));
		  background-image: -webkit-linear-gradient(top,rgba(255,255,255,0.8), rgba(216,216,216,0.8));
		  background-repeat: repeat-x;
		  padding:20px 5%;
		  margin: 0;
		  position: relative;
		  border: 1px solid rgba(216,216,216,0.8);
		}
		.control-group {
			margin-bottom: 15px;			
		}
		
		.control-label {
			color: #405c60;
			display:block;
			line-height: 18px;
			font-weight: normal;
			font-size: 16px;
			display:inline-block;
			min-width: 80px;
			max-width: 80px;
			text-align: right;
			margin-top: 12px;
			vertical-align: top;
		}
		.controls {
			display: inline-block;
			vertical-align: top;
			width: 65%;
		}
		input {
    	outline: medium none;
		}
	input:not([type="checkbox"]){
		width: 90%;
		margin-top: 4px;
		padding: 10px;	
		border: 1px solid rgb(178, 178, 178);
		-webkit-appearance: textfield;
		-webkit-box-sizing: content-box;
	       box-sizing : content-box;
       border-radius: 3px;
	        box-shadow: 0px 1px 4px 0px rgba(168, 168, 168, 0.6) inset;
		-webkit-transition: all 0.2s linear;
	        transition: all 0.2s linear;
		}
		input:not([type="checkbox"]):active,
		input:not([type="checkbox"]):focus{
			border: 1px solid rgba(91, 90, 90, 0.7);
			background: rgba(238, 236, 240, 0.2);	
 			box-shadow: 0px 1px 4px 0px rgba(168, 168, 168, 0.9) inset;
		}
		.form-actions {
			text-align: center;			
		} 
		.form-actions input{
			width: 30%;
			cursor: pointer;	
			background: rgb(61, 157, 179);
			padding: 8px 5px;
			font-family: 'BebasNeueRegular','Arial Narrow',Arial,sans-serif;
			color: #fff;
			font-size: 24px;	
			margin: 5px;
			border: 1px solid rgb(28, 108, 122);	
			margin-bottom: 10px;	
			text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
			border-radius: 3px;	
			box-shadow:0px 1px 6px 4px rgba(0, 0, 0, 0.07) inset,
	        0px 0px 0px 3px rgb(254, 254, 254),
	        0px 5px 3px 3px rgb(210, 210, 210);
		 -webkit-transition: all 0.2s linear;
	        transition: all 0.2s linear;
	   -webkit-appearance: none;     
		}
		.form-actions input:hover{
			background: rgb(74, 179, 198);
		}
		.form-actions input:active,
		.form-actions input:focus{
			background: rgb(40, 137, 154);
			position: relative;
			top: 1px;
			border: 1px solid rgb(12, 76, 87);	
		  box-shadow: 0px 1px 6px 4px rgba(0, 0, 0, 0.2) inset;
		}
	</style>	
    </head>
    <body>
        <form name="form1" method="post" action="2.html" onsubmit="return check()" class="form-horizontal">
					<fieldset>
						<div class="control-group">
							<label for="text1" class="control-label">用户名:</label>
							<div class="controls">
								<input id="username_reg" type="text" name="text1" onblur="check()" required="required" />
								<div class="help-inline" id="div1"></div>
							</div>
						</div>
						<div class="control-group">
							<label for="text2" class="control-label">密码:</label>
							<div class="controls">
								<input id="password_reg" type="password" name="text2" onblur="check()" required="required">
								<div class="help-inline" id="div2"></div>
							</div>
						</div>
						<div class="control-group">
							<label for="text3" class="control-label">确认密码:</label>
							<div class="controls">
								<input id="confirm_reg" type="password" name="text3" onblur="check()" required="required" />
								<div class="help-inline" id="div3"></div>
							</div>
						</div>

						<div class="form-actions">
							<input type="button" value="提交" name="tect6" class="btn btn-primary" onclick="reg()" />
							<input type="reset" value="重置" name="text7" class="btn" />
						</div>
					</fieldset>           
        </form>
    </body>
</html>
	

现在在iPhone4竖板是OK的,如下图所示

但现在需求是,在iPhone4的横板以及iPad的横板与竖板下,也需要让表单居中显示:

上图显示的是iPad竖板下的需求,横板下也需要类似的效果。

需求明确,做法也是有思路的,首先我按照:CSS3 Media Queries模板中的模板在样式中增加了代码:

	/*iPad竖板*/
	@media screen and (max-device-width: 768px) and (orientation: portrait) {
    form {
      margin: 0 25%;
    }
  }
	/*iPad横板*/
	@media screen and (max-device-width: 1024px) and (orientation: landscape) {
    form {
      margin: 0 25%;
    }
  }
	/*iPhone4*/
	@media only screen and (max-device-width: 480px),
    only screen and (-webkit-min-device-pixel-ratio: 2) {
			form {
        margin: 0 ;
			}
      .controls {
        width: 68%;
      }
	}
	

加上上面代码后在iPad下是正常了,而且不会有什么问题存在。但在iPhone4上依然存在一个怪异的现象:当你iPhone4加载页面是用横板加载,再旋转到竖板,不会存在任何问题,而且显示也是蛮正常的。但是初始加载页面是竖板,然后在旋转到横板,就有问题了,表单给放大了

初步给我感觉就是放大了,但具体是不是因为这个原因,我也不太清楚,查找了一些资料,也尝试了无解决办法。最后也从横板竖板的思路出发查找资料,经过一试,给解决了,下面来看看这段代码:

	/* iPhone 4 竖板 */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5) and (orientation:portrait),
only screen and (min-device-pixel-ratio : 1.5)  and (orientation:portrait){
    form {
      margin:0;
    }
		.controls {
			width: 68%;
		}
}

/* iPhone 4 横板 */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5) and (orientation:landscape),
only screen and (min-device-pixel-ratio : 1.5)  and (orientation:landscape){
    form {
        margin:0 10%;
    }
		.controls {
			width: 68%;
		}
}
	

这样一来就OK了。在iPhone4和iPad的横竖板下都能正常让表单居中显示。

那么以后大家在iPhone4和iPad设备上,就可以按照横竖板来定样式了:

1、iPhone4竖板

	@media
	only screen and (-webkit-min-device-pixel-ratio : 1.5) and (orientation:portrait),
	only screen and (min-device-pixel-ratio : 1.5)  and (orientation:portrait){
		/*你的样式写在这里*/	
	}
	

2、iPhone横板

		@media
		only screen and (-webkit-min-device-pixel-ratio : 1.5) and (orientation:landscape),
		only screen and (min-device-pixel-ratio : 1.5)  and (orientation:landscape){
			/*你的样式写在这里*/
		}
	

3、iPad竖板

	@media screen and (max-device-width: 768px) and (orientation: portrait) {
		/*你的样式写在这里*/
  }
	

4、iPad横板

	@media screen and (max-device-width: 1024px) and (orientation: landscape) {
		/*你样式写在这里*/
  }
	

上面四种CSS3 Media Queries就是用来对付iPhone4和iPad的,至于其他的运用,大家参考下面我重新整理的CSS3 Media Queries模板:

CSS3 Media Queries 模板:

1、Smartphones (竖板和横板)

		@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
			/* 你的样式写在这里 */
		}
		//===或者====//
		< link rel="stylesheet" href="smartphones.css" media="only screen and (min-device-width : 320px) and (max-device-width : 480px)" />
	

2、Smartphones (横板)

		@media only screen and (min-width : 321px) {
			/* 你的样式写在这里 */
		}
		
		//===或者====//
		< link rel="stylesheet" href="smartphones-landscape.css" media="only screen and (min-width : 321px)" />
	

3、Smartphones (竖板)

		@media only screen and (max-width : 320px) {
			/* 你的样式写在这里 */
		}
		//===或者====//
		< link rel="stylesheet" href="smartphones-portrait.css" media="only screen and (max-width : 320px)" />
	

4、iPad(竖板和横板)

		@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
			/* 你的样式写在这里 */
		}
		//===或者====//
		< link rel="stylesheet" href="ipad.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px)" />
	

5、iPad横板

		@media only screen and (min-device-width : 768px) and (max-device-width : 1024px)	and (orientation : landscape) {
			/* 你的样式写在这里 */
		}	
		//===或者====//
		< link rel="stylesheet" href="ipad-landscape.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px)	and (orientation : landscape)" />
	

6、iPad的竖板

		@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
			/* 你的样式写在这里 */
		}
		
		//===或者====//
		< link rel="stylesheet" href="ipad-portrait.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait)" />
	

7、Desktops and laptops

		@media only screen and (min-width : 1224px) {
			/* 你的样式写在这里 */
		}
		
		//===或者====//
		< link rel="stylesheet" href="desktops-and-laptops.css" media="only screen and (min-width : 1224px)" />
	

8、Large screens

		@media only screen and (min-width : 1824px) {
			/* 你的样式写在这里 */
		}
		//===或者====//
		< link rel="stylesheet" href="large-screens.css" media="only screen and (min-width : 1824px)" />
	

9、iPone4

		@media only screen and (-webkit-min-device-pixel-ratio : 1.5),only screen and (min-device-pixel-ratio : 1.5) {
			/* 你的样式写在这里 */
		}
		//===或者====//
		< link rel="stylesheet" href="iphone4.css" media="only screen and (-webkit-min-device-pixel-ratio : 1.5),only screen and (min-device-pixel-ratio : 1.5)" />
	

10、iPhone4竖板

	@media only screen and (-webkit-min-device-pixel-ratio : 1.5) and (orientation:portrait),	only screen and (min-device-pixel-ratio : 1.5)  and (orientation:portrait){
		/*你的样式写在这里*/	
	}
	//===或者====//
		< link rel="stylesheet" href="iphone4-portrait.css" media="only screen and (-webkit-min-device-pixel-ratio : 1.5) and (orientation:portrait),	only screen and (min-device-pixel-ratio : 1.5)  and (orientation:portrait)" />
	

11、iPhone4横板

		@media only screen and (-webkit-min-device-pixel-ratio : 1.5) and (orientation:landscape),only screen and (min-device-pixel-ratio : 1.5)  and (orientation:landscape){
			/*你的样式写在这里*/
		}
		//===或者====//
		< link rel="stylesheet" href="iphone4-landscape.css" media="only screen and (-webkit-min-device-pixel-ratio : 1.5) and (orientation:landscape),only screen and (min-device-pixel-ratio : 1.5)  and (orientation:landscape)" />
	

上面罗列了常用的CSS3 Media Queries模板,特别是在移动设备上的几种,希望对大家在今后的移动开发端上的运用有所帮助。当然CSS3 Media Queries的运用条件往往不只这些,大家完全可以根据自己的需求去定义不同的条件,但个人建议,使用CSS3 Media Queries采用主流就Ok了。随着潮流走嘛。那么今天就扯到这了。如果大家有更好的经验,可以通过下面的评论与我们一起分享。

2012年04月16日更新:iPad 3 Media Query

@media only screen and (min-device-width: 1536px) and (max-device-width: 2048px) and (-webkit-min-device-pixel-ratio: 2)
{
  // your CSS
}

如需转载烦请注明出处:W3CPLUS

Viewing all 1557 articles
Browse latest View live