26 Commonly Forgotten CSS Tips

26 Commonly Forgotten CSS Tips

This is a collection of commonly used but easily forgotten CSS implementation methods. If there are any omissions or additions, please correct me!

Solve the problem that the overflow:hidden attribute of inline-block elements causes the adjacent inline elements to shift downward

.wrap {
  display: inline-block;
  overflow: hidden
 vertical-align: bottom
}

Ellipses are displayed for the excess part

// Single line text.wrap {
 overflow:hidden;/*The overflow part is hidden*/
 text-overflow:ellipsis;/*The part that exceeds the limit will be displayed with ellipsis*/
 white-space:nowrap;/*The text in the specified paragraph does not wrap*/
}
//Multi-line text.wrap {
    width: 100%;
    overflow: hidden;
    display: -webkit-box; //Display the object as an elastic box model *Required properties*
    -webkit-box-orient: vertical; //Set the arrangement of the sub-elements of the telescopic box object *Must be combined with the property *
    -webkit-line-clamp: 3; //Used to limit the number of lines of text displayed in a block element word-break: break-all; //Allow the browser to implement line breaks at any position *break-all allows line breaks within words*
}

CSS implements no line break, automatic line break, and forced line break

//No line break.wrap {
  white-space:nowrap;
}
//Automatically wrap lines.wrap {
  word-wrap: break-word;
  word-break: normal;
}
//Force line break.wrap {
  word-break:break-all;
}

CSS to achieve text alignment

.wrap {
    text-align: justify;
    text-justify: distribute-all-lines; //ie6-8
    text-align-last: justify; //Alignment of the last line of a block or line -moz-text-align-last: justify;
    -webkit-text-align-last: justify;
}

Implement vertical text layout

// Single column display.wrap {
    width: 25px;
    line-height: 18px;
    height: auto;
    font-size: 12px;
    padding: 8px 5px;
    word-wrap: break-word;/*You need to add this sentence when writing in English to automatically wrap the line*/  
}
// When displaying multiple columns.wrap {
    height: 210px;
    line-height: 30px;
    text-align: justify;
    writing-mode: vertical-lr; //From left to right writing-mode: tb-lr; //IE from left to right//writing-mode: vertical-rl; -- From right to left//writing-mode: tb-rl; -- From right to left}

Disable element mouse events

.wrap {
    // If pressing tab selects the element, such as button, then pressing enter still executes the corresponding event, such as click.
 pointer-events: none;
    cursor: default;
}

Disable user selection

.wrap {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

cursor properties

.wrap {
  cursor: pointer; //little finger;
  cursor: help; //arrow plus question mark;
  cursor:wait; //spin in circles;
  cursor:move; //Move the cursor;
  cursor:crosshair; //cross cursor}

Use hardware acceleration

.wrap {
    transform: translateZ(0);
}

Image width adaptive

img {max-width: 100%}

Text-transform and Font Variant

p {text-transform: uppercase} // Make all letters uppercasep {text-transform: lowercase} // Make all letters lowercasep {text-transform: capitalize} // Capitalize the first letterp {font-variant: small-caps} // Make the font small-caps

Make a container transparent

.wrap { 
  filter:alpha(opacity=50); 
  -moz-opacity:0.5; 
  -khtml-opacity: 0.5; 
  opacity: 0.5; 
}

Eliminate transition splash screen

.wrap {
    -webkit-transform-style: preserve-3d;
    -webkit-backface-visibility: hidden;
    -webkit-perspective: 1000;
}

Custom scroll bars

overflow-y: scroll;
The entire scrollbar::-webkit-scrollbar {
    width: 5px;
}

Scrollbar track::-webkit-scrollbar-track {
    background-color: #ffa336;
    border-radius: 5px;
}

Scrollbar thumb::-webkit-scrollbar-thumb {
    background-color: #ffc076;
    border-radius: 5px;
}

Let HTML recognize '\n' in string and wrap it

body {
   white-space: pre-line;
}

Implementing a triangle

.wrap { 
  border-color: transparent transparent green transparent; 
  border-style: solid; 
  border-width: 0px 300px 300px 300px; 
  height: 0px; 
  width: 0px; 
}

Remove the border of the clicked link

a {outline: none}
a {outline: 0}

Use CSS to display the URL behind the link

a:after{content:" (" attr(href) ") ";}

Select content is displayed in the center and the drop-down content is right-aligned

select{
    text-align: center;
    text-align-last: center;
}
select option {
    direction: rtl;
}

Modify the cursor color in the input box without changing the font color

input{
    color: #fff;
    caret-color: red;
}

Modify the default font style of the placeholder in the input box

//webkit-based browser input::-webkit-input-placeholder {
    color: #c2c6ce;
}
//Firefox version 4-18 
input:-moz-placeholder {
    color: #c2c6ce;
}
//Firefox version 19+
input::-moz-placeholder {
    color: #c2c6ce;
}
//IE browser input:-ms-input-placeholder {
    color: #c2c6ce;
}

The width of the child element is fixed and the width of the parent element is expanded

// The child element under the parent element is an inline element.wrap {
  white-space: nowrap;
}
// If the child element under the parent element is a block-level element.wrap {
  white-space: nowrap; // child elements are not wrapped display: inline-block;
}

Center the image and text in div at the same time

.wrap {
  height: 100,
  line-height: 100
}
img {
  vertival-align: middle
}
// vertical-align The css property vertical-align is used to specify the vertical alignment of inline elements (inline) or table cell (table-cell) elements. It only works for inline elements and table cell elements. It cannot be used to vertically align block-level elements. // vertical-align: baseline/top/middle/bottom/sub/text-top;

Realize adaptive rectangle with equal width and height ratio

        .scale {
            width: 100%;
            padding-bottom: 56.25%;
            height: 0;
            position: relative; 
        }

        .item {
            position: absolute; 
            width: 100%;
            height: 100%;
            background-color: 499e56;
        }    
   <div class="scale">
        <div class="item">
            This is the container for all child elements</div>
    </div>

The rotate attribute of transfrom is invalid under the span tag

span {
  display: inline-block
}

Border font same color

 .wrap {
  width: 200px;
  height: 200px;
  color: #000;
  font-size: 30px;
  border: 50px solid currentColor;
  // border: 50px solid; // Implementation 2}

at last

The original text is here: gitHub If there are any omissions, please correct me! !

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Idea deploys remote Docker and configures the file

>>:  A brief discussion on how to choose and combine div and table

Recommend

Solution to the problem of adaptive height and width of css display table

Definition and Usage The display property specifi...

Two simple ways to remove text watermarks from web pages

<br /> When we browse certain websites and s...

A detailed introduction to for/of, for/in in JavaScript

Table of contents In JavaScript , there are sever...

How to clear the timer elegantly in Vue

Table of contents Preface optimization Derivative...

Analysis of Nginx Rewrite usage scenarios and configuration methods

Nginx Rewrite usage scenarios 1. URL address jump...

Some slightly more complex usage example codes in mysql

Preface I believe that the syntax of MySQL is not...

MySQL turns off password strength verification

About password strength verification: [root@mysql...

Detailed steps to install MySQL 5.6 X64 version under Linux

environment: 1. CentOS6.5 X64 2.mysql-5.6.34-linu...

How to solve the abnormal error ERROR: 2002 in mysql

Recently, an error occurred while starting MySQL....

Use pure CSS to achieve scroll shadow effect

To get straight to the point, there is a very com...

Example of converting JS one-dimensional array into three-dimensional array

Today I saw a friend asking a question in the Q&a...

Detailed explanation of MySQL injection without knowing the column name

Preface I feel like my mind is empty lately, as I...

An article to understand Linux disks and disk partitions

Preface All hardware devices in the Linux system ...

Detailed explanation of how to implement secondary cache with MySQL and Redis

Redis Introduction Redis is completely open sourc...