search
HomeWeb Front-endCSS TutorialSome css problems often encountered in front-end development (summary)

This chapter brings you some CSS problems (summary) that are often encountered in front-end development. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. Questions about input

1. The input is editable and pull-down

<div>
   <input type="text" list="itemlist" name="itemid" value="{$data.itemid}" >
  <datalist id="itemlist">
     <option>item1</option>
     <option>item2</option>
   </datalist>
</div>

2. The input is drop-down

<select>
    <option value="-1" >---请选择分辨率---</option>
    <option value="0" >320 X 240</option>
</select>

3. The input edge is not displayed when clicked

inputClick border style is invalid

outline: none;  /**/

4. Prompt text: placeholder="Mobile phone number"

inputModify prompt text color

::-webkit-input-placeholder { /* input提示文字颜色 */
    color: #fff;
    font-size:20px;
}

5. input The background is yellow

This kind of click box will not appear yellow

input:-webkit-autofill { box-shadow: 0 0 0px 1000px white inset !important;}

The other way is to turn off autofill: autocomplete="off"

二, Whether to occupy the space: show/hide

1. display

display:none;  /*不占位*/
display: block;  /*显示*/

2. visibility

visibility: hidden;   /*占位*/
visibility: visible;  /*显示*/

3. Positioning

1. Absolute positioning: position: absolute

The parent does not automatically increase in height. Solution: overflow:auto;

2. Relative positioning: position: relative;

3. Fixed positioning: position:fixed;

4. Textarea

1. div simulates textarea text area to easily achieve high adaptability

.testdisplay {
   width: 100%;
   min-height: 200px;
   max-height: 400px;
   margin-left: auto;
   margin-right: auto;
   outline: 0;
   font-size: 12px;
   line-height: 24px;
   word-wrap: break-word;
   overflow-x: hidden;
   overflow-y: auto;
   /*box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6);*/
}

5. Finger cursor

 cursor: pointer; /*手指光标*/

6. Text ellipses

1. Single-line text ellipsis

.digital-limit {
   overflow: hidden;
   text-overflow: ellipsis;
   /*显示...*/
   white-space: nowrap;
   /*文本不换行,这样超出一行的部分被截取,显示...*/
}

2. Multi-line text ellipsis

.digital-normal {
   display: -webkit-box;
   -webkit-box-orient: vertical; 
   -webkit-line-clamp: 3; 
   overflow: hidden;
}

7. Scroll bar modification style

::-webkit-scrollbar {/*滚动条整体样式*/
   width:  8px !important;     /*高宽分别对应横竖滚动条的尺寸*/
   height: 8px !important;
}
::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
   border-radius: 8px !important;
   -webkit-box-shadow: inset 0 0 8px rgba(0,0,0,.1) !important;
   background: rgba(0,0,0,.1) !important;
}
::-webkit-scrollbar-track {/*滚动条里面轨道*/
   -webkit-box-shadow: inset 0 0 8px rgba(0,0,0,0) !important;
   border-radius: 10px !important;
   background: rgba(0,0,0,0) !important;
}

8. Transparency

1. Background and font are transparent

opacity:0.5; /* 0-1 的透明度 */

2. Background is transparent and font is opaque

background: rgba(216, 216, 216, .1.5);

9. Screenshot of img image

.historys img{
    width: 100%;
    height: 100%;
    position: absolute;
    right: -5px;
    clip: rect(0 103px 100px 0px);
}

Via js when the image just starts loading You can get its width and height, and then use js to decide whether to limit the height or width of the image. How to get the size when the image starts loading can be found here.

Js:

$(function(){

    $(&#39;.historys img&#39;).each(function(){

        var $this=$(this);

        imgReady($this.attr(&#39;src&#39;),function(){

            if(this.width>this.height){

                $this.attr(&#39;height&#39;,&#39;100&#39;);

                $this.removeAttr(&#39;width&#39;);

            }

        });

    });

});

10. Background image

1. Expand the image proportionally to fill the element, that is, the cover value: background-size:cover;

2. The size is reduced proportionally to fit the size of the element, i.e. contain value: background-size:contain;

3. The size is filled with the size of the image itself, i.e. auto value: background-size :auto;

4. Picture blur

Use filter() function to blur the background, usage method:

-webkit-filter: blur(5px); /* Chrome, Safari, Opera */
 filter: blur(5px);

Some css problems often encountered in front-end development (summary)

##5. Others

No tiling: background-repeat: no-repeat;

Horizontal tiling: background-repeat: repeat-x;
Vertical tiling: background-repeat: repeat-y;
Fixed: background-attachment: fixed;
Scroll: background-attachment: scroll;
Horizontal centering: background-position: center;
Center horizontally and center vertically: background-position: center center;


The above is the detailed content of Some css problems often encountered in front-end development (summary). For more information, please follow other related articles on the PHP Chinese website!

Statement
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
A Little Reminder That Pseudo Elements are Children, Kinda.A Little Reminder That Pseudo Elements are Children, Kinda.Apr 19, 2025 am 11:39 AM

Here's a container with some child elements:

Menus with 'Dynamic Hit Areas'Menus with 'Dynamic Hit Areas'Apr 19, 2025 am 11:37 AM

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

Improving Video Accessibility with WebVTTImproving Video Accessibility with WebVTTApr 19, 2025 am 11:27 AM

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

Weekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteWeekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteApr 19, 2025 am 11:25 AM

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

Making width and flexible items play nice togetherMaking width and flexible items play nice togetherApr 19, 2025 am 11:23 AM

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

Position Sticky and Table HeadersPosition Sticky and Table HeadersApr 19, 2025 am 11:21 AM

You can't position: sticky; a

Weekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryWeekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryApr 19, 2025 am 11:18 AM

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

IndieWeb and WebmentionsIndieWeb and WebmentionsApr 19, 2025 am 11:16 AM

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool