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

Pure CSS to achieve click to expand and read the full text function

Note When developing an article display list inte...

Linux Cron scheduled execution of PHP code with parameters

1. Still use PHP script to execute. Command line ...

Example analysis of mysql variable usage [system variables, user variables]

This article uses examples to illustrate the usag...

Vue implements a small countdown function

Countdown function needs to be implemented in man...

The difference between mysql outer join and inner join query

The syntax for an outer join is as follows: SELEC...

Elements of user experience or elements of web design

System and user environment design <br />Th...

SQL fuzzy query report: ORA-00909: invalid number of parameters solution

When using Oracle database for fuzzy query, The c...

MySQL query statement simple operation example

This article uses examples to illustrate the simp...

This article will help you understand the life cycle in Vue

Table of contents 1. beforeCreate & created 2...

How to add vim implementation code examples in power shell

1. Go to Vim's official website to download t...

Execute initialization sql when docker mysql starts

1. Pull the Mysql image docker pull mysql:5.7 2. ...

A brief discussion on MySQL select optimization solution

Table of contents Examples from real life Slow qu...