自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

13 種可能對前端有用的 CSS 技術(shù)

開發(fā) 前端
修改輸入占位符樣式、多行文本溢出、隱藏滾動(dòng)條、修改光標(biāo)顏色、水平和垂直居中。多么熟悉的場景啊!前端開發(fā)人員幾乎每天都會(huì)與它們打交道。本文收集了13個(gè)CSS技巧,我們一起來回顧一下。

修改輸入占位符樣式、多行文本溢出、隱藏滾動(dòng)條、修改光標(biāo)顏色、水平和垂直居中。多么熟悉的場景??!前端開發(fā)人員幾乎每天都會(huì)與它們打交道。本文收集了13個(gè)CSS技巧,我們一起來回顧一下。

1.解決圖片5px間距問題

5px ,你是否經(jīng)常遇到圖片底部多余空間的問題?別擔(dān)心,有4種方法可以解決。

方案一:更改其父元素的font-size:0px

方案二:增加img display:block的樣式

方案三:增加img的樣式vertical-align:bottom

方案四:增加父元素的樣式line-height:5px

2.如何讓元素高度與窗口相同

目前的前端中,CSS有一個(gè)單位vh,將元素高度樣式設(shè)置為height:100vh

3.修改輸入框占位符樣式

這是表單輸入框的占位符屬性。修改默認(rèn)樣式的方法如下:

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

4. 使用 :not 選擇器

除了最后一個(gè)元素之外的所有元素都需要一些樣式,而使用選擇器實(shí)現(xiàn)這一點(diǎn)并不容易。

例如,要實(shí)現(xiàn)列表,最后一個(gè)元素不需要加下劃線,如下所示:

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

5.使用caret-color修改光標(biāo)顏色

有時(shí)需要修改光標(biāo)的顏色?,F(xiàn)在是插入符號顏色時(shí)間。

.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;
   /* Key style */
   caret-color: #ffd476;
}


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

6.使用flex布局智能地將元素固定到底部

當(dāng)內(nèi)容不夠時(shí),按鈕應(yīng)該位于頁面底部。當(dāng)內(nèi)容足夠多時(shí),按鈕應(yīng)該跟隨內(nèi)容。當(dāng)你遇到類似的問題時(shí),可以使用flex智能布局!

<div class="container">
   <div class="main">Content here</div>
   <div class="footer">Button</div>
</div>

CSS代碼如下:

.container {
   height: 100vh;
   /* Key style */
   display: flex;
   flex-direction: column;
   justify-content: space-between;
}


.main {
   /* Key style */
   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;
}

7.去掉type="number"末尾的箭頭

默認(rèn)情況下,type="number" 輸入類型末尾會(huì)出現(xiàn)一個(gè)小箭頭,但有時(shí)需要將其刪除。你可以使用以下樣式:

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;
}
/* Key style */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
   -webkit-appearance: none;
}

8.使用outline:none刪除輸入狀態(tài)行

當(dāng)輸入框被選中時(shí),默認(rèn)會(huì)有一條藍(lán)色的狀態(tài)行,可以使用outline:none去掉。

9.解決iOS滾動(dòng)條卡住的問題

在蘋果手機(jī)上,滾動(dòng)時(shí)元素經(jīng)常會(huì)卡住。此時(shí)只有一行CSS會(huì)支持彈性滾動(dòng)。

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

10.畫一個(gè)三角形

.triangle {
   display: inline-block;
   margin-right: 10px;
   /* Basic style */
   border: solid 10px transparent;
}
/* downward triangle */
.triangle.bottom {
   border-top-color: #0097a7;
}
/* Upward triangle */
.triangle.top {
   border-bottom-color: #b2ebf2;
}
/* Leftward triangle */
.triangle.left {
   border-right-color: #00bcd4;
}
/* Right triangle */
.triangle.right {
   border-left-color: #009688;
}

11.自定義選定的文本樣式

文本選擇的顏色和樣式可以通過styles自定義。關(guān)鍵樣式如下:

::selection {
  color: #ffffff;
  background-color: #ff4c9f;
}

12. 不允許選擇文本

使用用戶選擇的樣式:none;

13. 使用filter:grayscale(1)將頁面置于灰度模式

一行代碼會(huì)將頁面置于灰色模式。

body{
  filter: grayscale(1);
}

總結(jié)

以上就是我今天想與你分享的13個(gè)關(guān)于CSS的技巧,希望這些技巧對你有用。

責(zé)任編輯:華軒 來源: web前端開發(fā)
相關(guān)推薦

2024-06-11 10:05:24

2021-08-04 08:22:53

前端技術(shù)編程

2020-01-14 11:09:36

CIO IT技術(shù)

2021-05-27 10:10:15

IT量子計(jì)算機(jī)前沿技術(shù)

2024-01-19 11:33:12

2024-01-19 20:36:17

2019-07-01 09:10:00

前端開發(fā)技術(shù)

2012-02-22 11:13:53

Java

2011-05-20 09:56:15

J2EE

2024-07-19 13:04:51

2020-12-28 10:35:38

前端數(shù)據(jù)技術(shù)

2022-10-25 15:55:13

2013-04-24 11:33:31

Android開發(fā)Android有用習(xí)慣

2009-06-22 17:32:25

J2EE平臺

2023-05-28 23:23:44

2024-08-20 15:23:27

JavaScript開發(fā)

2022-07-08 09:27:48

CSSIFC模型

2023-03-06 10:42:34

CSS前端

2025-02-13 09:37:26

2021-04-20 08:11:33

Css前端@property
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號