Table of Contents
1. Solve the problem of 5px spacing in images
2. How to make the height of the element the same as the window
3. Modify the input box placeholder style
4. Use :not selector
5. Use caret-color to modify the cursor color
6. Use flex layout to intelligently pin elements to the bottom
" >7. Remove the arrow at the end of type="number"
8. Use outline:none Delete the input status line
9. Solve the problem of iOS scroll bar getting stuck
10. Draw a triangle
11. Customize the selected text style
12. Text that is not allowed to be selected
13 Use filter:grayscale(1) Put the page in gray mode
Home Web Front-end CSS Tutorial 13 practical CSS tips to help you improve front-end development efficiency!

13 practical CSS tips to help you improve front-end development efficiency!

Jan 22, 2023 am 05:30 AM
css front end

This article compiles and shares 13 CSS techniques that may be useful on the front end, including modifying input placeholder styles, multi-line text overflow, hiding scroll bars, modifying cursor colors, etc. I hope it will be helpful to everyone!

13 practical CSS tips to help you improve front-end development efficiency!

Modify input placeholder style, multi-line text overflow, hide scroll bars, modify cursor color, horizontal and vertical centering. What a familiar scene! Front-end developers deal with them almost every day. This article collects 13 CSS skills, let’s review them together.

1. Solve the problem of 5px spacing in images

Do you often encounter the problem of extra 5px spacing at the bottom of images? Don't worry, there are 4 ways to solve it. [Recommended learning: css video tutorial]

  • Solution 1: Solve the font-size:0px
  • of its parent element Solution 2: Add the style of img to display:block
  • Solution 3: Add the style of img to vertical-align:bottom
  • Solution Solution 4: Increase the style of the parent element by line-height:5px

2. How to make the height of the element the same as the window

In the current front-end, the CSS unit is vh, set the element height style to height:100vh

3. Modify the input box placeholder style

This is the placeholder attribute of the form input box. How to modify the default style is as follows:

input::-webkit-input-placeholder {
  color: #babbc1;
  font-size: 12px;
}
Copy after login

4. Use :not selector

Every element except the last one needs some styling, which is very easy to achieve using the not selector.

For example, to implement a list, the last element does not need to be underlined, as follows:

li:not(:last-child) {
  border-bottom: 1px solid #ebedf0;
}
Copy after login

5. Use caret-color to modify the cursor color

Sometimes it is necessary to modify the color of the cursor. It's caret color time.

.caret-color {
  width: 300px;
  padding: 10px;
  margin-top: 20px;
  border-radius: 10px;
  border: solid 1px #ffd476;
  box-sizing: border-box;
  background-color: transparent;
  outline: none;
  color: #ffd476;
  font-size: 14px;
  /* 关键样式 */
  caret-color: #ffd476;
}

.caret-color::-webkit-input-placeholder {
  color: #4f4c5f;
  font-size: 14px;
}
Copy after login

6. Use flex layout to intelligently pin elements to the bottom

When the content is not enough, the button should be at the bottom of the page. When there is enough content, the button should follow the content. When encountering similar problems, you can use flex to achieve smart layout!

<div class="container">
  <div class="main">这里为内容</div>
  <div class="footer">按钮</div>
</div>
Copy after login

CSS code is as follows:

.container {
  height: 100vh;
  /* 关键样式 */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.main {
  /* 关键样式 */
  flex: 1;
  background-image: linear-gradient(
    45deg,
    #ff9a9e 0%,
    #fad0c4 99%,
    #fad0c4 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.footer {
  padding: 15px 0;
  text-align: center;
  color: #ff9a9e;
  font-size: 14px;
}
Copy after login

7. Remove the arrow at the end of type="number"

By default , a small arrow will appear at the end of the input type type="number", but sometimes it needs to be removed. You can use the following style:

input {
  width: 300px;
  padding: 10px;
  margin-top: 20px;
  border-radius: 10px;
  border: solid 1px #ffd476;
  box-sizing: border-box;
  background-color: transparent;
  outline: none;
  color: #ffd476;
  font-size: 14px;
  caret-color: #ffd476;
  display: block;
}

input::-webkit-input-placeholder {
  color: #4f4c5f;
  font-size: 14px;
}
/* 关键样式 */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}
Copy after login

8. Use outline:none Delete the input status line

When the input box is selected, there will be a blue status line by default, which can be changed using outline:none Remove.

9. Solve the problem of iOS scroll bar getting stuck

On Apple phones, elements often get stuck when scrolling. At this time, only one line of CSS will Support elastic scrolling.

body,html{
  -webkit-overflow-scrolling: touch;
}
Copy after login

10. Draw a triangle

.triangle {
  display: inline-block;
  margin-right: 10px;
  /* 基础样式 */
  border: solid 10px transparent;
}
/* 向下三角形 */
.triangle.bottom {
  border-top-color: #0097a7;
}
/* 向上三角形 */
.triangle.top {
  border-bottom-color: #b2ebf2;
}
/* 向左三角形 */
.triangle.left {
  border-right-color: #00bcd4;
}
/* 向右三角形 */
.triangle.right {
  border-left-color: #009688;
}
Copy after login

11. Customize the selected text style

Can be customized through styles The color and style of text selection, the key styles are as follows:

::selection {
  color: #ffffff;
  background-color: #ff4c9f;
}
Copy after login

12. Text that is not allowed to be selected

Use styleuser-select: none;

13 Use filter:grayscale(1) Put the page in gray mode

One line of code will put the page in gray mode.

body{
  filter: grayscale(1);
}
Copy after login

(Learning video sharing: web front-end)

The above is the detailed content of 13 practical CSS tips to help you improve front-end development efficiency!. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

See all articles