介绍
一名合格的前端“攻城狮”首先要在布局静态页面方面过关,而静态布局,美化离不开样式表css,less,sass。
公共样式
一般如ul,li标签的圆点标志,a标签的下划线,颜色,文档的文本都是需要改变的,如果每次写项目都要手动敲一遍很费时费力。但如果把经常用的样式整理成一个css文件,每次写项目引用进来就能少去很多环节。
例如.fl 代表示 float: left 左浮动,.ellipse 代表文字溢出效果 overflow: hidden;text-overflow: ellipsis;white-space: nowrap;只需给页面加上这两个类名即可达到想要的效果,多运用,孰能生巧。
我自己常用的公共样式如下:
html, body, div, ul, li, h1, h2, h3, h4, h5, h6, p, dl, dt, dd, ol, form, input, textarea, th, td, select {margin: 0;padding: 0;}
/* *{box-sizing: border-box;} */
html, body {min-height: 100%;}
body {background: #fff;font: 12px/1.5 Arial,Helvetica,sans-serif;color: #333;-webkit-text-size-adjust: none;margin: 0}
button,input,select,textarea {font: 100% tahoma,arial,\5b8b\4f53}
h1,h2,h3,h4,h5,h6 {font-size: 100%;font-weight: bold;}
em,i {font-style: normal}
ul,ol {list-style: none;}
fieldset,img {border: 0;}
input {vertical-align: middle;}
table {border-collapse: collapse;border-spacing: 0;}
a {color: #36c;text-decoration: none;outline: 0;}
a:hover {color: #ff6000;text-decoration: none;}
h1, h2, h3, h4, h5, h6{font-weight:normal;}
ul,ol {list-style: none;}
img {border: none;vertical-align: middle;}
a {text-decoration: none;color: #232323;}
table {border-collapse: collapse;table-layout: fixed;}
input, textarea, select{outline: none;}
textarea {overflow: auto;resize: none;}
.clearfix:after {content: ".";width: 0;height: 0;visibility: hidden;display: block;clear: both;overflow:hidden;}
.clearfix {*zoom:1;}
.fl {float: left}
.ml20{margin-left: 20px;}
.fr {float: right}
.tl {text-align: left;}
.tc {text-align: center}
.tr {text-align: right;}
.ellipse {overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
.inline{display: inline-block;*display: inline;*zoom: 1;}
扩展美化样式
/*遮罩层*/
.maskLayer {
z-index: 9999;
display: none;
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
}
/* 透明特效 */
.opacity {
-webkit-animation: opacity 0.3s linear;
animation: opacity 0.3s linear;
}
@-webkit-keyframes opacity {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes opacity {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
/* 苹果手机滚屏更流畅 */
.web-touch {
-webkit-overflow-scrolling: touch;
}
/* 适配990-1920屏幕宽度容器 */
.wrap {
min-width: 990px;
max-width: 1920px;
}
/* 输入框和按钮美化样式 */
input {
border: 1px solid #ccc;
border-radius: 2px;
color: #000;
font-family: "Opan Sans", sans-serif;
font-size: 1em;
height: 50px;
padding: 0 16px;
transition: background 0.3s ease-in-out;
width: 100%;
}
input:focus {
outline: none;
border-color: #9ecaed;
box-shadow: 0 0 10px #9ecaed;
}
.button {
height: 50px;
width: 292px;
background: #009dff;
border: none;
border-radius: 2px;
color: #fff;
cursor: pointer;
font-family: "Open Sans", sans-serif;
font-size: 1.2em;
letter-spacing: 0.1em;
text-align: center;
transition: background 0.3s ease-in-out;
}
.button:hover {
background: #00c8ff;
}
/* 滚动条样式美化 */
.box {
width: 600px;
height: 400px;
margin: 100px auto;
border: 1px solid #000;
border-right: 0;
}
.main {
overflow-x: hidden;
overflow-y: auto;
color: #000;
font-size: 16px;
height: 100%;
}
.main p {
height: 300px;
}
/*-------滚动条整体样式----*/
.main::-webkit-scrollbar {
width: 8px;
height: 8px;
}
/*滚动条里面小方块样式*/
.main::-webkit-scrollbar-thumb {
border-radius: 100px;
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
background: red;
}
/*滚动条里面轨道样式*/
.main::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
border-radius: 0;
background: rgba(0, 0, 0, 0.1);
}