Īpašība background-clip
Īpašība background-clip nosaka, kā
fona aizpildījums vai fona attēls tiks
novietots attiecībā pret elementu: zem apmales,
tikai iekšpus padding vai tikai virs satura.
Īpatnības
- Lietojot
border-boxar caurspīdīgām malām, fons būs redzams zem tām - Vērtībai
textir nepieciešami pārlūkprogrammu prefiksi pilnīgai atbalstam - Īpašība strādā ar gradientiem un vairākiem foniem
- Ar
border-radiusfons tiek apgriezts pa noapaļotajiem stūriem
Pārlūkprogrammu atbalsts
Visas modernās pārlūkprogrammas atbalsta border-box, padding-box un content-box.
Vērtībai text ir nepieciešams prefikss -webkit- un to atbalsta Chrome, Safari, Edge.
Sintakse
selektors {
background-clip: border-box | padding-box | content-box | text;
}
Vērtības
| Vērtība | Apraksts |
|---|---|
border-box |
Fons izplatās līdz ārējai malas malai (zem apmales). |
padding-box |
Fons tiek apgriezts pa iekšējo malas malu (neieiet zem border). |
content-box |
Fons tiek parādīts tikai virs satura (tiek apgriezts padding). |
text |
Fons tiek apgriezts pa tekstu. |
Noklusējuma vērtība: border-box.
Piemērs . Vērtība border-box
Fons iet zem daļēji caurspīdīgas apmales:
<div id="elem"></div>
#elem {
background-clip: border-box;
background-color: #ffd6d6;
background-repeat: no-repeat;
border: 10px dashed rgba(0,0,0,0.3);
padding: 30px;
width: 250px;
height: 150px;
}
:
Piemērs . Vērtība padding-box
Fons neiet zem apmales:
<div id="elem"></div>
#elem {
background-clip: padding-box;
background-color: #ffd6d6;
background-repeat: no-repeat;
border: 10px dashed rgba(0,0,0,0.5);
padding: 30px;
width: 250px;
height: 150px;
}
:
Piemērs . Vērtība content-box
Fons neiet uz padding:
<div id="elem">
teksts teksts teksts teksts teksts
teksts teksts teksts teksts teksts
teksts teksts teksts teksts teksts
</div>
#elem {
background-clip: content-box;
background-color: #ffd6d6;
background-repeat: no-repeat;
border: 10px dashed rgba(0,0,0,0.3);
padding: 30px;
width: 250px;
height: 150px;
}
:
Piemērs . Vērtība text
Fons tiek apgriezts pa tekstu (nepieciešams -webkit-text-fill-color
ar vērtību transparent):
<div id="elem">teksts teksts teksts</div>
#elem {
display: inline-block;
background: linear-gradient(to right, red, blue);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
font-size: 40px;
font-weight: bold;
}
:
Skatiet arī
-
īpašība
background,
kas ir saīsinājuma īpašība fonam -
īpašība
background-origin,
kas nosaka fona sākotnējo pozīciju