Those small CSS codes you need to know

1. Text Gradient

.text{
  background-image: linear-gradient(to right, #c6ffdd, #fbd786, #f7797d);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
}

2, column count, column attributes make beautiful column layouts for text elements

p{
  column-count: 3;
  column-gap: 5rem;          
  column-rule: 1px solid salmon;
}

3. Comma-separated unordered list

ul li:not(:last-child)::after{
    content: ','
}

4. Realize different backgrounds for odd and even rows in the table

.table > tr:nth-child(even) > td {} //(偶数行)
.table > tr:nth-child(odd) > td {} //(奇数行)

//或者

.table > tr:nth-child(2n) > td {} //(偶数行)
.table > tr:nth-child(2n+1) > td {} //(奇数行)

5. Implement a custom small triangle

//下三角
.arrow-down{
    width: 0px;
    height: 0px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #ccc;
    line-height: 0px;
}

//上三角
.arrow-up{
    width: 0px;
    height: 0px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #ccc;
    line-height: 0px;
}

6. Realize the alignment of both ends of the text

p{
    display: inline-block;
    text-align: justify;
    text-justify:distribute-all-lines; // 兼容ie
    text-align-last: justify;
}

7. Automatic text wrapping

p{
    width: 100px;
    word-wrap: break-word;
}

8. If the text is too long, use an ellipsis instead

//单行文本
p{
    width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


//多行文本
p{
    display: -webkit-box; /*重点,不能用block等其他,将对象作为弹性伸缩盒子模型显示*/
    -webkit-box-orient: vertical; /*从上到下垂直排列子元素(设置伸缩盒子的子元素排列方式)*/
    -webkit-line-clamp: 3; /*行数,超出三行隐藏且多余的用省略号表示...*/
    line-clamp: 3;
    word-break: break-all;
    overflow: hidden;
    max-width: 100%;
}

10. Clear floating

.clearfix:after { content:"\20"; display:block;height:0;clear:both;visibility:hidden;}
.clearfix{display:block;}
.clear{margin:0; padding:0; width:0; height:0; line-height:0; font-size:0; clear:both;}

11. Set the color of the input box placeholder (placeholder)

input::-webkit-input-placeholder {    /* Chrome/Opera/Safari */
    color: red;
}
input::-moz-placeholder { /* Firefox 19+ */
    color: red;
}
input:-ms-input-placeholder { /* IE 10+ */
    color: red;
}
input:-moz-placeholder { /* Firefox 18- */
    color: red;
}

12. Transparent background

.liter{
    filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',startColorstr='#4CDDDDDD', endColorstr='#4CDDDDDD');
}
:root .liter {
    filter:none;     /*处理IE9浏览器中的滤镜效果*/
    background-color:rgba(221,221,221,0.3);
}

Continually updated

Guess you like

Origin blog.csdn.net/codingLeader/article/details/124730559