頁(yè)面需要一定的 CSS 基本功,雖然現(xiàn)在有很多成熟的框架如 bootstrap 等,我們輕松的就就可以做出一些頁(yè)面效果。但是掌握每一個(gè)常見效果的寫法還是很重要的,下面整理出一些常見的 CSS 前端效果,讓你更輕松的寫頁(yè)面。
1、禁止選擇文本
body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
2、在可打印的網(wǎng)頁(yè)中顯示URLs
@media print {
a:after {
content: " [" attr(href) "] ";
}
}
3、深灰色的點(diǎn)擊漸變按鈕
.graybtn {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient( linear, left top, left bottombottom, color-stop(0.05, #ffffff), color-stop(1, #d1d1d1) );
background:-moz-linear-gradient( center top, #ffffff 5%, #d1d1d1 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#d1d1d1');
background-color:#ffffff;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
color:#777777;
font-family:arial;
font-size:15px;
font-weight:bold;
padding:6px 24px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
}
.graybtn:hover {
background:-webkit-gradient( linear, left top, left bottombottom, color-stop(0.05, #d1d1d1), color-stop(1, #ffffff) );
background:-moz-linear-gradient( center top, #d1d1d1 5%, #ffffff 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#d1d1d1', endColorstr='#ffffff');
background-color:#d1d1d1;
}
.graybtn:active {
position:relative;
top:1px;
}
4、網(wǎng)頁(yè)頂部盒陰影
body:before {
content: "";
position: fixed;
top: -10px;
left: 0;
width: 100%;
height: 10px;
-webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
-moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
box-shadow: 0px 0px 10px rgba(0,0,0,.8);
z-index: 100;
}
5、在可點(diǎn)擊的項(xiàng)目上強(qiáng)制手型
a[href], input[type='submit'], input[type='image'], label[for], select, button, .pointer {
cursor: pointer;
}
6、CSS3 鮮艷的輸入(邊框漸變)
input[type=text], textarea {
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
outline: none;
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid #ddd;
}
input[type=text]:focus, textarea:focus {
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid rgba(81, 203, 238, 1);
}
7、三角形列表項(xiàng)目符號(hào)
ul {
margin: 0.75em 0;
padding: 0 1em;
list-style: none;
}
li:before {
content: "";
border-color: transparent #111;
border-style: solid;
border-width: 0.35em 0 0.35em 0.45em;
display: block;
height: 0;
width: 0;
left: -1em;
top: 0.9em;
position: relative;
}
8、內(nèi)部CSS3 盒陰影
#mydiv {
-moz-box-shadow: inset 2px 0 4px #000;
-webkit-box-shadow: inset 2px 0 4px #000;
box-shadow: inset 2px 0 4px #000;
}
9、外部CSS3 盒陰影
#mydiv {
-webkit-box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.52);
-moz-box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.52);
box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.52);
}
10、@font-face模板
@font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff') format('woff'), /* Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
body {
font-family: 'MyWebFont', Arial, sans-serif;
}
11、CSS3漸變模板
#colorbox {
background: #629721;
background-image: -webkit-gradient(linear, left top, left bottombottom, from(#83b842), to(#629721));
background-image: -webkit-linear-gradient(top, #83b842, #629721);
background-image: -moz-linear-gradient(top, #83b842, #629721);
background-image: -ms-linear-gradient(top, #83b842, #629721);
background-image: -o-linear-gradient(top, #83b842, #629721);
background-image: linear-gradient(top, #83b842, #629721);
}
12、CSS3:全屏背景
html {
background: url('images/bg.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
13、錨鏈接偽類
a:link { color: blue; }
a:visited { color: purple; }
a:hover { color: red; }
a:active { color: yellow; }
14、圖片邊框偏光
img.polaroid {
background:#000; /*Change this to a background image or remove*/
border:solid #fff;
border-width:6px 6px 20px 6px;
box-shadow:1px 1px 5px #333; /* Standard blur at 5px. Increase for more depth */
-webkit-box-shadow:1px 1px 5px #333;
-moz-box-shadow:1px 1px 5px #333;
height:200px; /*Set to height of your image or desired div*/
width:200px; /*Set to width of your image or desired div*/
}
15、通用媒體查詢
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
@media only screen and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
@media only screen and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
@media only screen and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
@media only screen and (-webkit-min-device-pixel-ratio:1.5), only screen and (min-device-pixel-ratio:1.5) {
/* Styles */
}
16、跨瀏覽器透明
.transparent {
filter: alpha(opacity=50); /* internet explorer */
-khtml-opacity: 0.5; /* khtml, old safari */
-moz-opacity: 0.5; /* mozilla, netscape */
opacity: 0.5; /* fx, safari, opera */
}
17、用CSS動(dòng)畫實(shí)現(xiàn)省略號(hào)動(dòng)畫
.loading:after {
overflow: hidden;
display: inline-block;
vertical-align: bottombottom;
animation: ellipsis 2s infinite;
content: "26"; /* ascii code for the ellipsis character */
}
@keyframes ellipsis {
from {
width: 2px;
}
to {
width: 15px;
}
}
18、制造模糊文本
.blurry-text {
color: transparent;
text-shadow: 0 0 5px rgba(0,0,0,0.5);
}
19、包裹長(zhǎng)文本 文本過長(zhǎng)自動(dòng)換行不會(huì)穿破盒子
pre {
whitewhite-space: pre-line;
word-wrap: break-word;
}
20、背景漸變色
button {
background-image: linear-gradient(#5187c4, #1c2f45);
background-size: auto 200%;
background-position: 0 100%;
transition: background-position 0.5s;
}
button:hover {
background-position: 0 0;
}
21、內(nèi)容可編輯(contenteditable="true")
<ul contenteditable="true">
<li>悼念遇難香港同胞 </li>
<li>深圳特區(qū)30周年</li>
<li>伊春空難</li>
</ul>
22、輸入框改變placeholder字體顏色
::-webkit-input-placeholder {
color: red;
}
:-moz-placeholder {
color: red;
}
::-moz-placeholder{
color: red;
}
:-ms-input-placeholder {
color: red;
}
作者:雅兮網(wǎng)
來(lái)源:boke112導(dǎo)航
言:每當(dāng)過節(jié)的時(shí)候,女朋友就抱怨我總是忘記給她買花,說程序不懂浪漫,這不我準(zhǔn)備了幾款愛心動(dòng)畫特效,打算當(dāng)面向她表達(dá)一下。
寓意:告白無(wú)須多么華麗的語(yǔ)言,一顆顆小的愛心匯聚成一顆真心,讓你的另一半感受到濃濃的愛意。
代碼難度系數(shù)★★★
新建index.html,復(fù)制以下代碼保存在瀏覽器中打開即可。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>canvas 心</title>
<style>
html, body {
height: 100%;
padding: 0;
margin: 0;
background: #000;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
}</style>
</head>
<body>
<canvas id="pinkboard"></canvas>
<script>
/*
* Settings
*/
var settings={
particles: {
length: 500, // maximum amount of particles
duration: 2, // particle duration in sec
velocity: 100, // particle velocity in pixels/sec
effect: -0.75, // play with this for a nice effect
size: 30, // particle size in pixels
},
};
/*
* RequestAnimationFrame polyfill by Erik M?ller
*/
(function(){var b=0;var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimationFrame=window[c[a]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a]+"CancelAnimationFrame"]||window[c[a]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,e){var d=new Date().getTime();var f=Math.max(0,16-(d-b));var g=window.setTimeout(function(){h(d+f)},f);b=d+f;return g}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(d){clearTimeout(d)}}}());
/*
* Point class
*/
var Point=(function() {
function Point(x, y) {
this.x=(typeof x !=='undefined') ? x : 0;
this.y=(typeof y !=='undefined') ? y : 0;
}
Point.prototype.clone=function() {
return new Point(this.x, this.y);
};
Point.prototype.length=function(length) {
if (typeof length=='undefined')
return Math.sqrt(this.x * this.x + this.y * this.y);
this.normalize();
this.x *=length;
this.y *=length;
return this;
};
Point.prototype.normalize=function() {
var length=this.length();
this.x /=length;
this.y /=length;
return this;
};
return Point;
})();
/*
* Particle class
*/
var Particle=(function() {
function Particle() {
this.position=new Point();
this.velocity=new Point();
this.acceleration=new Point();
this.age=0;
}
Particle.prototype.initialize=function(x, y, dx, dy) {
this.position.x=x;
this.position.y=y;
this.velocity.x=dx;
this.velocity.y=dy;
this.acceleration.x=dx * settings.particles.effect;
this.acceleration.y=dy * settings.particles.effect;
this.age=0;
};
Particle.prototype.update=function(deltaTime) {
this.position.x +=this.velocity.x * deltaTime;
this.position.y +=this.velocity.y * deltaTime;
this.velocity.x +=this.acceleration.x * deltaTime;
this.velocity.y +=this.acceleration.y * deltaTime;
this.age +=deltaTime;
};
Particle.prototype.draw=function(context, image) {
function ease(t) {
return (--t) * t * t + 1;
}
var size=image.width * ease(this.age / settings.particles.duration);
context.globalAlpha=1 - this.age / settings.particles.duration;
context.drawImage(image, this.position.x - size / 2, this.position.y - size / 2, size, size);
};
return Particle;
})();
/*
* ParticlePool class
*/
var ParticlePool=(function() {
var particles,
firstActive=0,
firstFree=0,
duration=settings.particles.duration;
function ParticlePool(length) {
// create and populate particle pool
particles=new Array(length);
for (var i=0; i < particles.length; i++)
particles[i]=new Particle();
}
ParticlePool.prototype.add=function(x, y, dx, dy) {
particles[firstFree].initialize(x, y, dx, dy);
// handle circular queue
firstFree++;
if (firstFree==particles.length) firstFree=0;
if (firstActive==firstFree ) firstActive++;
if (firstActive==particles.length) firstActive=0;
};
ParticlePool.prototype.update=function(deltaTime) {
var i;
// update active particles
if (firstActive < firstFree) {
for (i=firstActive; i < firstFree; i++)
particles[i].update(deltaTime);
}
if (firstFree < firstActive) {
for (i=firstActive; i < particles.length; i++)
particles[i].update(deltaTime);
for (i=0; i < firstFree; i++)
particles[i].update(deltaTime);
}
// remove inactive particles
while (particles[firstActive].age >=duration && firstActive !=firstFree) {
firstActive++;
if (firstActive==particles.length) firstActive=0;
}
};
ParticlePool.prototype.draw=function(context, image) {
// draw active particles
if (firstActive < firstFree) {
for (i=firstActive; i < firstFree; i++)
particles[i].draw(context, image);
}
if (firstFree < firstActive) {
for (i=firstActive; i < particles.length; i++)
particles[i].draw(context, image);
for (i=0; i < firstFree; i++)
particles[i].draw(context, image);
}
};
return ParticlePool;
})();
/*
* Putting it all together
*/
(function(canvas) {
var context=canvas.getContext('2d'),
particles=new ParticlePool(settings.particles.length),
particleRate=settings.particles.length / settings.particles.duration, // particles/sec
time;
// get point on heart with -PI <=t <=PI
function pointOnHeart(t) {
return new Point(
160 * Math.pow(Math.sin(t), 3),
130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25
);
}
// creating the particle image using a dummy canvas
var image=(function() {
var canvas=document.createElement('canvas'),
context=canvas.getContext('2d');
canvas.width=settings.particles.size;
canvas.height=settings.particles.size;
// helper function to create the path
function to(t) {
var point=pointOnHeart(t);
point.x=settings.particles.size / 2 + point.x * settings.particles.size / 350;
point.y=settings.particles.size / 2 - point.y * settings.particles.size / 350;
return point;
}
// create the path
context.beginPath();
var t=-Math.PI;
var point=to(t);
context.moveTo(point.x, point.y);
while (t < Math.PI) {
t +=0.01; // baby steps!
point=to(t);
context.lineTo(point.x, point.y);
}
context.closePath();
// create the fill
context.fillStyle='#ea80b0';
context.fill();
// create the image
var image=new Image();
image.src=canvas.toDataURL();
return image;
})();
// render that thing!
function render() {
// next animation frame
requestAnimationFrame(render);
// update time
var newTime=new Date().getTime() / 1000,
deltaTime=newTime - (time || newTime);
time=newTime;
// clear canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// create new particles
var amount=particleRate * deltaTime;
for (var i=0; i < amount; i++) {
var pos=pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
var dir=pos.clone().length(settings.particles.velocity);
particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);
}
// update and draw particles
particles.update(deltaTime);
particles.draw(context, image);
}
// handle (re-)sizing of the canvas
function onResize() {
canvas.width=canvas.clientWidth;
canvas.height=canvas.clientHeight;
}
window.onresize=onResize;
// delay rendering bootstrap
setTimeout(function() {
onResize();
render();
}, 10);
})(document.getElementById('pinkboard'));</script>
</body>
</html>
寓意:將想說的話打開一顆顆的愛心氣球上,隨著氣球不斷的升空,讓整個(gè)氛圍可更加地纏綿,看到此處可以有感動(dòng)的淚水。
代碼難度系數(shù)★★★
新建index.html,復(fù)制以下代碼保存在瀏覽器中打開即可。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>情人節(jié)快樂:)</title>
<style>
canvas {
position: absolute;
top: 0;
left: 0;
}</style>
</head>
<body>
<canvas id=c></canvas>
<script>
var w=c.width=window.innerWidth,
h=c.height=window.innerHeight,
ctx=c.getContext( '2d' ),
opts={
phrases: [ "Don't die\nit's not hard", "You're the Best", "Every day,\nYou're beautiful", "Every occasion,\nYou're clever", "A world without You?\nNah", "Keep kicking ass", "You're better than them,\nwhoever they are", "You're just amazing", "You are,\ntherefore I am", "Nothing better than You \ncould have happened to the world" ],
balloons: 10,
baseVelY: -1,
addedVelY: -1,
baseVelX: -.25,
addedVelX: .5,
baseSize: 20,
addedSize: 10,
baseSizeAdder: 2,
addedSizeAdder: 2,
baseIncrementer: .01,
addedIncrementer: .03,
baseHue: -10,
addedHue: 30,
font: '15px Verdana'
},
cycle=0,
balloons=[];
ctx.font=opts.font;
function Balloon(){
this.reset();
}
Balloon.prototype.reset=function(){
this.size=opts.baseSize + opts.addedSize * Math.random();
this.sizeAdder=opts.baseSizeAdder + opts.addedSizeAdder * Math.random();
this.incrementer=opts.baseIncrementer + opts.addedIncrementer * Math.random();
this.tick=0;
this.x=Math.random() * w;
this.y=h + this.size;
this.vx=opts.baseVelX + opts.addedVelX * Math.random();
this.vy=opts.baseVelY + opts.addedVelY * Math.random();
this.color='hsla(hue,70%,60%,.8)'.replace( 'hue', opts.baseHue + opts.addedHue * Math.random() );
this.phrase=opts.phrases[ ++cycle % opts.phrases.length ].split( '\n' );
this.lengths=[];
for( var i=0; i < this.phrase.length; ++i )
this.lengths.push( -ctx.measureText( this.phrase[ i ] ).width / 2 );
}
Balloon.prototype.step=function(){
this.tick +=this.incrementer;
this.x +=this.vx;
this.y +=this.vy;
var size=this.size + this.sizeAdder * Math.sin( this.tick );
ctx.lineWidth=size / 40;
ctx.strokeStyle='#eee';
ctx.beginPath();
ctx.moveTo( this.x, this.y - 2 );
ctx.lineTo( this.x, this.y + size );
ctx.stroke();
ctx.fillStyle=this.color;
ctx.translate( this.x, this.y );
ctx.rotate( Math.PI / 4 );
//ctx.fillRect( -size / 2, -size / 2, size / 2, size / 2 );
ctx.beginPath();
ctx.moveTo( 0, 0 );
ctx.arc( -size / 2, -size / 2 + size / 4, size / 4, Math.PI / 2, Math.PI * 3 / 2 );
ctx.arc( -size / 2 + size / 4, -size / 2, size / 4, Math.PI, Math.PI * 2 );
ctx.lineTo( 0, 0 );
ctx.fill();
ctx.rotate( -Math.PI / 4 );
ctx.translate( -this.x, -this.y );
ctx.translate( this.x, this.y + size + 15 );
ctx.scale( size / this.size, size / this.size );
ctx.fillStyle='#eee';
for( var i=0; i < this.phrase.length; ++i )
ctx.fillText( this.phrase[ i ], this.lengths[ i ], i * 15 );
ctx.scale( this.size / size, this.size / size );
ctx.translate( -this.x, -( this.y + size + 15 ) );
if( this.y < -size * 3 )
this.reset();
}
function anim(){
window.requestAnimationFrame( anim );
ctx.fillStyle='#222';
ctx.fillRect( 0, 0, w, h );
if( balloons.length < opts.balloons && Math.random() < .01 )
balloons.push( new Balloon );
for( var i=0; i < balloons.length; ++i )
balloons[ i ].step();
}
anim();</script>
</body>
</html>
寓意:天空中下起了愛心雨,襯托的房間變得溫暖,也讓整個(gè)場(chǎng)景都變得溫馨無(wú)比,想必此時(shí)可以有一個(gè)大大的擁抱。
代碼難度系數(shù)★★★
代碼有image、js和html,所以不好貼出來(lái),有需要的朋友直接問我要吧。
總結(jié):程序員的工作本身就很枯燥,特定找了幾個(gè)好看的特效拿出來(lái)和大家分享,希望大家能夠快樂每一天,上述代碼親測(cè)可用,歡迎點(diǎn)贊收藏。
《完》
大家如果喜歡的話麻煩點(diǎn)贊、關(guān)注、轉(zhuǎn)發(fā),謝謝大家。
果圖
各位看官好!知了的看門道、不知道的評(píng)論個(gè)熱鬧
今天給大家?guī)?lái)的是:企業(yè)級(jí)jQuery響應(yīng)式全屏背景圖片導(dǎo)航菜單特效源碼
正如效果圖所示!炫酷到?jīng)]朋友啊!
廢話不多說,上源碼!
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
*請(qǐng)認(rèn)真填寫需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。