网页中css代码的功能,18个优秀的CSS前端效果代码

编程入门 行业动态 更新时间:2024-10-08 22:56:10

网页中css<a href=https://www.elefans.com/category/jswz/34/1771412.html style=代码的功能,18个优秀的CSS前端效果代码"/>

网页中css代码的功能,18个优秀的CSS前端效果代码

1、锚链接伪类

a:link { color: blue; }

a:visited { color: purple; }

a:hover { color: red; }

a:active { color: yellow; }

2、禁止选择文本

body {

-webkit-touch-callout: none;

-webkit-user-select: none;

-khtml-user-select: none;

-moz-user-select: none;

-ms-user-select: none;

user-select: none;

}

3、在可打印的网页中显示URLs

@media print {

a:after {

content: " [" attr(href) "] ";

}

}

4、网页顶部盒阴影

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、在可点击的项目上强制手型

a[href], input[type='submit'], input[type='image'], label[for], select, button, .pointer {

cursor: pointer;

}

6、三角形列表项目符号

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;

}

7、内部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;

}

8、外部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);

}

9、@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;

}

10、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;

}

11、图片边框偏光

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*/

}

12、通用媒体查询

/* 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 */

}

13、跨浏览器透明

.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 */

}

14、用CSS动画实现省略号动画

.loading:after {

overflow: hidden;

display: inline-block;

vertical-align: bottombottom;

animation: ellipsis 2s infinite;

content: "\2026"; /* ascii code for the ellipsis character */

}

@keyframes ellipsis {

from {

width: 2px;

}

to {

width: 15px;

}

}

15、制造模糊文本

.blurry-text {

color: transparent;

text-shadow: 0 0 5px rgba(0,0,0,0.5);

}

16、包裹长文本 文本过长自动换行不会穿破盒子

pre {

whitewhite-space: pre-line;

word-wrap: break-word;

}

17、背景渐变色

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;

}

18、内容可编辑(contenteditable=”true”)

  • 悼念遇难香港同胞 
  • 深圳特区30周年
  • 伊春空难

125jz网原创文章。发布者:江山如画,转载请注明出处:.html

更多推荐

网页中css代码的功能,18个优秀的CSS前端效果代码

本文发布于:2024-03-23 23:27:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1744101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   效果   优秀   功能   网页

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!