├── CSS相关 ├── 前端常用的CSS代码块.md └── 常见的CSS文字居中显示.md ├── JS相关 ├── 前端常用rule校验.js └── 前端常用正则表达式.js └── README.md /CSS相关/前端常用的CSS代码块.md: -------------------------------------------------------------------------------- 1 |  2 | 3 | [demo预览地址](https://web.lieme.cn/cssDemo/cssdemo.html) 4 | 5 | ## 1、垂直居中对齐 6 | 7 | ``` 8 | .vc { 9 | position: absolute; 10 | top: 50%; 11 | left: 50%; 12 | transform: translate(-50%, -50%); 13 | } 14 | .vc { 15 | position:absolute; 16 | top: 50%; 17 | left: 50%; 18 | width: 100px; 19 | height: 100px; 20 | margin:-50px 0 -50px; 21 | } 22 | ``` 23 | 24 | ## 2、全屏显示 25 | ``` 26 | html, 27 | body { 28 | position: fixed; 29 | width: 100%; 30 | height: 100%; 31 | } 32 | div { 33 | height: 100%; 34 | } 35 | ``` 36 | ## 3、不同a标签链接使用不同样式 37 | 38 | ``` 39 | // link 40 | 41 | a[href^="http://"]{ 42 | background: url(link.gif) no-repeat center right; 43 | } 44 | // emails 45 | a[href^="mailto:"]{ 46 | background: url(email.png) no-repeat center right; 47 | } 48 | 49 | // pdfs 50 | 51 | a[href$=".pdf"]{ 52 | background: url(pdf.png) no-repeat center right; 53 | } 54 | ``` 55 | ## 4、图像灰度 56 | 57 | ``` 58 | img { 59 | filter: gray; 60 | -webkit-filter: grayscale(1); 61 | } 62 | ``` 63 | ## 5、背景渐变动画 64 | 65 | ``` 66 | bg { 67 | background-image: linear-gradient(#5187c4, #1c2f45); 68 | background-size: auto 200%; 69 | background-position: 0 100%; 70 | transition: background-position 0.5s; 71 | } 72 | bg:hover { 73 | background-position: 0 0; 74 | } 75 | ``` 76 | ## 6、长文本自动换行 77 | 78 | ``` 79 | pre { 80 | white-space: pre-line; 81 | word-wrap: break-word; 82 | } 83 | ``` 84 | ## 7、模糊文本 85 | ``` 86 | .text { 87 | filter: blur(1px); 88 | } 89 | ``` 90 | ## 8、用CSS动画实现省略号动画 91 | ``` 92 | .point:after { 93 | overflow: hidden; 94 | display: inline-block; 95 | vertical-align: bottom; 96 | animation: ellipsis 2s infinite; 97 | content: "\2026"; 98 | } 99 | @keyframes ellipsis { 100 | from { 101 | width: 2px; 102 | } 103 | to { 104 | width: 15px; 105 | } 106 | } 107 | ``` 108 | ## 9、样式重置 109 | ``` 110 | 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 { 111 | margin: 0; 112 | padding: 0; 113 | border: 0; 114 | font-size: 100%; 115 | font: inherit; 116 | vertical-align: baseline; 117 | outline: none; 118 | -webkit-box-sizing: border-box; 119 | -moz-box-sizing: border-box; 120 | box-sizing: border-box; 121 | } 122 | html { height: 101%; } 123 | body { font-size: 62.5%; line-height: 1; font-family: Arial, Tahoma, sans-serif; } 124 | article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } 125 | ol, ul { list-style: none; } 126 | blockquote, q { quotes: none; } 127 | blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; } 128 | strong { font-weight: bold; } 129 | table { border-collapse: collapse; border-spacing: 0; } 130 | img { border: 0; max-width: 100%; } 131 | p { font-size: 1.2em; line-height: 1.0em; color: #333; } 132 | ``` 133 | 134 | ## 10、清除浮动 135 | ``` 136 | .clearfix:before, .container:after { content: ""; display: table; } 137 | .clearfix:after { clear: both; } 138 | .clearfix { zoom: 1; } 139 | ``` 140 | ## 11、css元素透明 141 | ``` 142 | .transparent { 143 | filter: alpha(opacity=50); 144 | -khtml-opacity: 0.5; 145 | -moz-opacity: 0.5; 146 | opacity: 0.5; 147 | } 148 | ``` 149 | ## 12、CSS引用样式 150 | ``` 151 | blockquote { 152 | background: #f9f9f9; 153 | border-left: 10px solid #ccc; 154 | margin: 1.5em 10px; 155 | padding: .5em 10px; 156 | quotes: "\201C""\201D""\2018""\2019"; 157 | } 158 | blockquote:before { 159 | color: #ccc; 160 | content: open-quote; 161 | font-size: 4em; 162 | line-height: .1em; 163 | margin-right: .25em; 164 | vertical-align: -.4em; 165 | } 166 | blockquote p { 167 | display: inline; 168 | } 169 | ``` 170 | ## 13、个性圆角 171 | ``` 172 | .borderRadius { 173 | border-radius: 4px 3px 6px 10px; 174 | } 175 | .borderRadius { 176 | border-top-left-radius: 4px; 177 | border-top-right-radius: 3px; 178 | border-bottom-right-radius: 6px; 179 | border-bottom-left-radius: 10px; 180 | } 181 | ``` 182 | 183 | ## 14、通用媒体查询 184 | ``` 185 | 186 | @media only screen and (min-device-width : 320px) and (max-device-width : 480px) { 187 | /* Styles */ 188 | } 189 | @media only screen and (min-width : 321px) { 190 | /* Styles */ 191 | } 192 | @media only screen and (max-width : 320px) { 193 | /* Styles */ 194 | } 195 | /* iPad */ 196 | @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) { 197 | /* Styles */ 198 | } 199 | @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) { 200 | /* Styles */ 201 | } 202 | 203 | @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) { 204 | /* Styles */ 205 | } 206 | /* 桌面 */ 207 | @media only screen and (min-width : 1224px) { 208 | /* Styles */ 209 | } 210 | 211 | @media only screen and (min-width : 1824px) { 212 | /* Styles */ 213 | } 214 | 215 | @media only screen and (-webkit-min-device-pixel-ratio:1.5), only screen and (min-device-pixel-ratio:1.5) { 216 | /* Styles */ 217 | } 218 | ``` 219 | ## 15、自定义文本选择 220 | ``` 221 | ::selection { background: #e2eae2; } 222 | ``` 223 | 224 | ## 16、图片边框偏光 225 | ``` 226 | img.polaroid { 227 | background:#000; 228 | border:solid #fff; 229 | border-width:6px 6px 20px 6px; 230 | box-shadow:1px 1px 5px #333; 231 | -webkit-box-shadow:1px 1px 5px #333; 232 | -moz-box-shadow:1px 1px 5px #333; 233 | height:200px; 234 | width:200px; 235 | } 236 | ``` 237 | ## 17、锚链接伪类 238 | ``` 239 | a:link { color: blue; } 240 | a:visited { color: purple; } 241 | a:hover { color: red; } 242 | a:active { color: yellow; } 243 | ``` 244 | 245 | ## 18、全屏背景图 246 | ``` 247 | html { 248 | background: url('bg.jpg') no-repeat center center fixed; 249 | background-size: cover; 250 | } 251 | ``` 252 | ## 19、内容垂直居中 253 | ``` 254 | .center { 255 | min-height: 6.5em; 256 | display: table-cell; 257 | vertical-align: middle; 258 | } 259 | ``` 260 | ## 20、强制出现垂直滚动条 261 | 262 | ``` 263 | html { height: 101% } 264 | ``` 265 | 266 | ## 21、CSS3渐变模板 267 | ``` 268 | .bg { 269 | background: #629721; 270 | background-image: -webkit-gradient(linear, left top, left bottom, from(#83b842), to(#629721)); 271 | background-image: linear-gradient(top, #83b842, #629721); 272 | } 273 | ``` 274 | ## 22、@font-face引用 275 | 276 | ``` 277 | @font-face { 278 | font-family: 'MyWebFont'; 279 | src: url('webfont.eot'); 280 | src: url('webfont.eot?#iefix') 281 | url('webfont.woff') format('woff'), 282 | url('webfont.ttf') format('truetype'), 283 | url('webfont.svg#svgFontName') format('svg'); 284 | } 285 | body { 286 | font-family: 'MyWebFont', Arial, sans-serif; 287 | } 288 | ``` 289 | 290 | ## 23、连接CSS3元素 291 | ``` 292 | p { 293 | position:relative; 294 | z-index:1; 295 | padding: 10px; 296 | margin: 10px; 297 | font-size: 21px; 298 | line-height: 1.3em; 299 | color: #fff; 300 | background: #ff0030; 301 | box-shadow: 0 0 0 4px #ff0030, 2px 1px 6px 4px rgba(10,10,0,.5); 302 | -webkit-border-radius: 3px; 303 | -moz-border-radius: 3px; 304 | border-radius: 3px; 305 | } 306 | p:before { 307 | content: ""; 308 | position: absolute; 309 | z-index: -1; 310 | top: 3px; 311 | bottom: 3px; 312 | left :3px; 313 | right: 3px; 314 | border: 2px dashed #fff; 315 | } 316 | p a { 317 | color: #fff; 318 | text-decoration:none; 319 | } 320 | p a:hover, p a:focus, p a:active { 321 | text-decoration:underline; 322 | } 323 | ``` 324 | ## 24、CSS斑马线 325 | ``` 326 | tbody tr:nth-child(odd) { 327 | background-color: #ccc; 328 | } 329 | ``` 330 | ## 25、 css&符号 331 | ``` 332 | .amp { 333 | font-family: Baskerville, 'Goudy Old Style', Palatino, 'Book Antiqua', serif; 334 | font-style: italic; 335 | font-weight: normal; 336 | } 337 | ``` 338 | ## 26、内盒阴影 339 | ``` 340 | .div { 341 | box-shadow: inset 2px 0 4px #000; 342 | } 343 | ``` 344 | ## 27、外盒阴影 345 | ``` 346 | .div { 347 | box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.52); 348 | } 349 | ``` 350 | ## 28、三角形列表项目符号 351 | ``` 352 | ul { 353 | margin: 0.75em 0; 354 | padding: 0 1em; 355 | list-style: none; 356 | } 357 | li:before { 358 | content: ""; 359 | border-color: transparent #111; 360 | border-style: solid; 361 | border-width: 0.35em 0 0.35em 0.45em; 362 | display: block; 363 | height: 0; 364 | width: 0; 365 | left: -1em; 366 | top: 0.9em; 367 | position: relative; 368 | } 369 | ``` 370 | ## 29、固定宽度的居中布局 371 | ``` 372 | .div { 373 | width: 800px; 374 | margin: 0 auto; 375 | } 376 | ``` 377 | ## 30、CSS3列文本 378 | ``` 379 | .columnsText { 380 | text-align: justify; 381 | -webkit-column-count: 3; 382 | -webkit-column-gap: 12px; 383 | -webkit-column-rule: 1px solid #c4c8cc; 384 | } 385 | ``` 386 | ## 31、CSS固定页脚 387 | ``` 388 | footer { 389 | position: fixed; 390 | left: 0px; 391 | bottom: 0px; 392 | height: 30px; 393 | width: 100%; 394 | background: #444; 395 | } 396 | ``` 397 | ## 32、设置浏览器最小高度 398 | ``` 399 | .div{ 400 | min-height: 550px; 401 | height: auto !important; 402 | height: 550px; 403 | } 404 | ``` 405 | ## 33、CSS3输入效果 406 | ``` 407 | input[type=text] { 408 | transition: all 0.30s ease-in-out; 409 | outline: none; 410 | padding: 3px 0px 3px 3px; 411 | margin: 5px 1px 3px 0px; 412 | border: 1px solid #ddd; 413 | } 414 | input[type=text]:focus { 415 | box-shadow: 0 0 5px rgba(81, 203, 238, 1); 416 | padding: 3px 0px 3px 3px; 417 | margin: 5px 1px 3px 0px; 418 | border: 1px solid rgba(81, 203, 238, 1); 419 | } 420 | ``` 421 | ## 34、强制换行 422 | ``` 423 | pre { 424 | white-space: pre-wrap; 425 | word-wrap: break-word; 426 | } 427 | ``` 428 | 429 | ## 35、在可点击的项目上强制手型 430 | ``` 431 | .pointer { 432 | cursor: pointer; 433 | } 434 | ``` 435 | ## 36、网页顶部盒阴影 436 | ``` 437 | body:before { 438 | content: ""; 439 | position: fixed; 440 | top: -10px; 441 | left: 0; 442 | width: 100%; 443 | height: 10px; 444 | box-shadow: 0px 0px 10px rgba(0,0,0,.8); 445 | z-index: 100; 446 | } 447 | ``` 448 | ## 37、CSS3对话气泡 449 | ``` 450 | .line { 451 | background-color: #ededed; 452 | border: 2px solid #666; 453 | font-size: 35px; 454 | line-height: 1.3em; 455 | margin: 10px auto; 456 | padding: 10px; 457 | position: relative; 458 | text-align: center; 459 | width: 300px; 460 | border-radius: 20px; 461 | box-shadow: 0 0 5px #888; 462 | } 463 | .chat-bubble-arrow-border { 464 | border-color: #666 transparent transparent transparent; 465 | border-style: solid; 466 | border-width: 20px; 467 | height: 0; 468 | width: 0; 469 | position: absolute; 470 | bottom: -42px; 471 | left: 30px; 472 | } 473 | .chat-bubble-arrow { 474 | border-color: #ededed transparent transparent transparent; 475 | border-style: solid; 476 | border-width: 20px; 477 | height: 0; 478 | width: 0; 479 | position: absolute; 480 | bottom: -39px; 481 | left: 30px; 482 | } 483 | ``` 484 | 485 | 486 | ## 38、持久的列表排序 487 | ``` 488 | ol.chapters { 489 | list-style: none; 490 | margin-left: 0; 491 | } 492 | ol.chapters > li:before { 493 | content: counter(chapter) ". "; 494 | counter-increment: chapter; 495 | font-weight: bold; 496 | float: left; 497 | width: 40px; 498 | } 499 | ol.chapters li { 500 | clear: left; 501 | } 502 | ol.start { 503 | counter-reset: chapter; 504 | } 505 | ol.continue { 506 | counter-reset: chapter 11; 507 | } 508 | ``` 509 | ## 39、CSS悬浮提示文本 510 | ``` 511 | a { 512 | border-bottom:1px solid #bbb; 513 | color:#666; 514 | display:inline-block; 515 | position:relative; 516 | text-decoration:none; 517 | } 518 | a:hover, 519 | a:focus { 520 | color:#36c; 521 | } 522 | a:active { 523 | top:1px; 524 | } 525 | 526 | a[data-tooltip]:after { 527 | border-top: 8px solid #222; 528 | border-top: 8px solid hsla(0,0%,0%,.85); 529 | border-left: 8px solid transparent; 530 | border-right: 8px solid transparent; 531 | content: ""; 532 | display: none; 533 | height: 0; 534 | width: 0; 535 | left: 25%; 536 | position: absolute; 537 | } 538 | a[data-tooltip]:before { 539 | background: #222; 540 | background: hsla(0,0%,0%,.85); 541 | color: #f6f6f6; 542 | content: attr(data-tooltip); 543 | display: none; 544 | font-family: sans-serif; 545 | font-size: 14px; 546 | height: 32px; 547 | left: 0; 548 | line-height: 32px; 549 | padding: 0 15px; 550 | position: absolute; 551 | text-shadow: 0 1px 1px hsla(0,0%,0%,1); 552 | white-space: nowrap; 553 | -webkit-border-radius: 5px; 554 | -moz-border-radius: 5px; 555 | -o-border-radius: 5px; 556 | border-radius: 5px; 557 | } 558 | a[data-tooltip]:hover:after { 559 | display: block; 560 | top: -9px; 561 | } 562 | a[data-tooltip]:hover:before { 563 | display: block; 564 | top: -41px; 565 | } 566 | a[data-tooltip]:active:after { 567 | top: -10px; 568 | } 569 | a[data-tooltip]:active:before { 570 | top: -42px; 571 | } 572 | ``` 573 | ## 40、深灰色的圆形按钮 574 | ``` 575 | .graybtn { 576 | box-shadow:inset 0px 1px 0px 0px #ffffff; 577 | background:gradient( linear, left top, left bottom, color-stop(0.05, #ffffff), color-stop(1, #d1d1d1) ); 578 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#d1d1d1'); 579 | background-color:#ffffff; 580 | border-radius:6px; 581 | border:1px solid #dcdcdc; 582 | display:inline-block; 583 | color:#777777; 584 | font-family:arial; 585 | font-size:15px; 586 | font-weight:bold; 587 | padding:6px 24px; 588 | text-decoration:none; 589 | text-shadow:1px 1px 0px #ffffff; 590 | } 591 | .graybtn:hover { 592 | background:gradient( linear, left top, left bottom, color-stop(0.05, #d1d1d1), color-stop(1, #ffffff) ); 593 | filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#d1d1d1', endColorstr='#ffffff'); 594 | background-color:#d1d1d1; 595 | } 596 | .graybtn:active { 597 | position:relative; 598 | top:1px; 599 | } 600 | ``` 601 | ## 41、显示a链接得URLs 602 | ``` 603 | @media print { 604 | a:after { 605 | content: " [" attr(href) "] "; 606 | } 607 | } 608 | ``` 609 | ## 42、禁用移动Webkit的选择高亮 610 | ``` 611 | body { 612 | -webkit-touch-callout: none; 613 | -webkit-user-select: none; 614 | -khtml-user-select: none; 615 | -moz-user-select: none; 616 | -ms-user-select: none; 617 | user-select: none; 618 | } 619 | ``` 620 | ## 43、CSS3 圆点图案 621 | ``` 622 | body { 623 | background: radial-gradient(circle, white 10%, transparent 10%), 624 | radial-gradient(circle, white 10%, black 10%) 50px 50px; 625 | background-size: 100px 100px; 626 | } 627 | ``` 628 | ## 44、CSS3 方格图案 629 | ``` 630 | body { 631 | background-color: white; 632 | background-image: linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%, black), 633 | linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%, black); 634 | background-size: 100px 100px; 635 | background-position: 0 0, 50px 50px; 636 | } 637 | ``` 638 | 639 | ## 45、CSS font属性缩写 640 | ``` 641 | p { 642 | font: italic small-caps bold 1.2em/1.0em Arial, Tahoma, Helvetica; 643 | } 644 | ``` 645 | ## 46、论文页面的卷曲效果 646 | ``` 647 | ul.box { 648 | position: relative; 649 | z-index: 1; 650 | overflow: hidden; 651 | list-style: none; 652 | margin: 0; 653 | padding: 0; 654 | } 655 | ul.box li { 656 | position: relative; 657 | float: left; 658 | width: 250px; 659 | height: 150px; 660 | padding: 0; 661 | border: 1px solid #efefef; 662 | margin: 0 30px 30px 0; 663 | background: #fff; 664 | -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset; 665 | -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset; 666 | box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset; 667 | } 668 | ul.box li:before, 669 | ul.box li:after { 670 | content: ''; 671 | z-index: -1; 672 | position: absolute; 673 | left: 10px; 674 | bottom: 10px; 675 | width: 70%; 676 | max-width: 300px; /* avoid rotation causing ugly appearance at large container widths */ 677 | max-height: 100px; 678 | height: 55%; 679 | -webkit-box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3); 680 | -moz-box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3); 681 | box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3); 682 | -webkit-transform: skew(-15deg) rotate(-6deg); 683 | -moz-transform: skew(-15deg) rotate(-6deg); 684 | -ms-transform: skew(-15deg) rotate(-6deg); 685 | -o-transform: skew(-15deg) rotate(-6deg); 686 | transform: skew(-15deg) rotate(-6deg); 687 | } 688 | ul.box li:after { 689 | left: auto; 690 | right: 10px; 691 | -webkit-transform: skew(15deg) rotate(6deg); 692 | -moz-transform: skew(15deg) rotate(6deg); 693 | -ms-transform: skew(15deg) rotate(6deg); 694 | -o-transform: skew(15deg) rotate(6deg); 695 | transform: skew(15deg) rotate(6deg); 696 | } 697 | ``` 698 | ## 47、鲜艳的锚链接 699 | ``` 700 | a { 701 | color: #00e; 702 | } 703 | a:visited { 704 | color: #551a8b; 705 | } 706 | a:hover { 707 | color: #06e; 708 | } 709 | a:focus { 710 | outline: thin dotted; 711 | } 712 | a:hover, a:active { 713 | outline: 0; 714 | } 715 | a, a:visited, a:active { 716 | text-decoration: none; 717 | color: #fff; 718 | transition: all .3s ease-in-out; 719 | } 720 | a:hover, .glow { 721 | color: #ff0; 722 | text-shadow: 0 0 10px #ff0; 723 | } 724 | ``` 725 | ## 48、带CSS3特色的横幅显示 726 | ``` 727 | .featureBanner { 728 | position: relative; 729 | margin: 20px 730 | } 731 | .featureBanner:before { 732 | content: "Featured"; 733 | position: absolute; 734 | top: 5px; 735 | left: -8px; 736 | padding-right: 10px; 737 | color: #232323; 738 | font-weight: bold; 739 | height: 0px; 740 | border: 15px solid #ffa200; 741 | border-right-color: transparent; 742 | line-height: 0px; 743 | box-shadow: -0px 5px 5px -5px #000; 744 | z-index: 1; 745 | } 746 | .featureBanner:after { 747 | content: ""; 748 | position: absolute; 749 | top: 35px; 750 | left: -8px; 751 | border: 4px solid #89540c; 752 | border-left-color: transparent; 753 | border-bottom-color: transparent; 754 | } 755 | ``` 756 | 757 | ## 49、限制单行文本超出显示省略号 758 | ``` 759 | div{ 760 | width: 65px; 761 | height: 30px; 762 | line-height: 30px; 763 | overflow: hidden; 764 | text-overflow: ellipsis; 765 | white-space: nowrap; 766 | font-size: 14px; 767 | } 768 | 769 | ``` 770 | 771 | ## 50、限制多行文本超出省略号 772 | 773 | ``` 774 | div{ 775 | overflow : hidden; 776 | text-overflow: ellipsis; 777 | display: -webkit-box; 778 | -webkit-line-clamp: 2; 779 | -webkit-box-orient: vertical; 780 | } 781 | ``` 782 | ## 51、css三角形绘制 783 | ``` 784 | .sj { 785 | width: 0; 786 | height: 0; 787 | border-width: 100px; 788 | border-style: solid; 789 | } 790 | 791 | .sj-left { 792 | border-color: transparent pink transparent transparent; 793 | } 794 | 795 | .sj-right { 796 | border-color: transparent transparent transparent pink; 797 | } 798 | 799 | .sj-top { 800 | border-color: transparent transparent pink transparent; 801 | } 802 | 803 | .sj-bottom { 804 | border-color: pink transparent transparent transparent; 805 | } 806 | ``` 807 | ## 52、自适应文本框自动换行,限宽不限高 808 | ``` 809 | div{ 810 | display: inline-block; 811 | min-height: 15px; 812 | max-width: 78%; 813 | padding: 12px 10px; 814 | text-align: left; 815 | font-family: Microsoft YaHei; 816 | word-wrap: break-word; 817 | } 818 | ``` 819 | 820 | ## 53、 ~选择器:查找某一个元素后面的所有兄弟元素 821 | 822 | ``` 823 | 例如 .test~.name{background:red} 824 | ``` 825 | 826 | ## 54、 +选择器:查找某一个元素后面紧邻的兄弟元素 827 | 828 | ``` 829 | 例如 .test+.name{background:red} 830 | ``` 831 | 832 | ## 55、 用 font-size :0 来清除边距 833 | 834 | ## 56、 利用padding实现等比例缩放的盒子 835 | 836 | ``` 837 | 最外层容器{ 838 | display:flex; 839 | display:flex-box; 840 | flex-wrap:warp; 841 | } 842 | 最外层容器 > 子元素{ 843 | flex-basis:25%; 844 | } 845 | 最外层容器 > 子元素 > 父元素{ 846 | width:100%; 847 | padding-top:75%; 848 | position:relative; 849 | } 850 | 最外层容器 > 子元素 > 父元素 > 子元素{ 851 | width:100%; 852 | height:100%; 853 | position:absolute; 854 | top:0; 855 | left:0; 856 | } 857 | ``` 858 | 859 | 860 | ## 57、利用pointer-events禁用事件光标变成default阻止hover和hover以及JavaScript 点击事件的触发 861 | 862 | ``` 863 | pointer-events:none; 864 | ``` 865 | 866 | ## 58、利用 max-width 防止图片撑破容器 867 | 868 | ``` 869 | img{ 870 | max-width:100%; 871 | display:inline-block; 872 | } 873 | ``` 874 | 875 | ## 59、伪类和伪元素的用法 876 | 877 | 878 | ``` 879 | 880 | // 伪类是用 : 来表示,伪元素是用 :: 来表示 881 | 882 | 常见的伪类有: 883 | :hover 884 | :active 885 | :focus 886 | :visited 887 | :link 888 | :lang 889 | :first-child 890 | :last-child 891 | :not 892 | :nth-child 893 | 894 | // 伪元素就是不存在DOM文档树中的虚拟元素,它们和HTML元素一样,但是你又无法使用javascript去获取 895 | 896 | 常见伪元素 897 | ::before 898 | ::after 899 | ::first-letter 900 | ::first-line 901 | 902 | 903 | 用 :valid 和 :invalid 来做表单验证 904 | 905 | html5 提供了类似required Email tel 等表单属性 906 | :required // 指定具有required属性的表单元素 907 | :valid // 指定一个通过匹配正确的所要求的表单元素 908 | :invalid // 指定一个不匹配指定要求的表单元素 909 | 910 | 911 | input:vaild{ 如果输入文字则变成绿色 912 | border:1px solid green; 913 | box-shadow:inset 10px 0 0 green; 914 | } 915 | input:invaild{ 如果没有输入则是红色 916 | border:1px solid red; 917 | box-shadow:inset 10px 0 0 red; 918 | } 919 | 920 | 921 | 用:target来实现折叠面板 922 | 923 | 924 | 用:not来排除其他选择器 925 | :not([readonly]):not([.disabled]):not([text]) 等 926 | 927 | 用:nth-child 来实现各行变色 928 | :nth-child(2n+1){background:red;} 929 | :nth-child(2n){backgorund:blue;} 930 | 931 | 932 | 用::selection 来美化选中文本 933 | p::selection{ 934 | background:red; 935 | color:green; 936 | } 937 | 938 | 用::placeholder 美化输入框占位符样式 939 | ::placeholder{ 940 | color:Red; 941 | } 942 | 943 | 用::first-letter 来实现段落首字下沉 944 | p::first-letter{ 945 | font-size:30px; 946 | color:Red; 947 | padding:20px; 948 | } 949 | 950 | 用::first-line 来标记段落的第一行 951 | p::first-line{ 952 | color:red; 953 | } 954 | ``` 955 | ## 60、footer永远在页面底部 956 | 957 | 958 | ``` 959 | 975 | footer { 976 | clear: both; 977 | position: absolute; 978 | bottom: 0px; 979 | width: 100%; 980 | background: #000; 981 | color: #fff; 982 | min-width: 1200px; 983 | height: 200px; 984 | } 985 | ``` 986 | ## 61、两个子元素 一个有内容自动撑开,另一个为空如何跟随高度。 987 | 988 | 989 | ``` 990 | .f{ 991 | display: flex; 992 | align-items: stretch; 993 | } 994 | ``` 995 | ## 62、消除transition闪屏 996 | 997 | ``` 998 | .css { 999 | transform: translate3d(0,0,0); 1000 | } 1001 | ``` 1002 | -------------------------------------------------------------------------------- /CSS相关/常见的CSS文字居中显示.md: -------------------------------------------------------------------------------- 1 |  2 | 3 | [demo预览地址](https://web.lieme.cn/cssDemo/cssCenter.html) 4 | 5 | ## 1、利用line-height和vertical-align 6 | **html** 7 | 8 | ``` 9 |