В настоящий момент нет официального способа сделать это, но вы можете использовать небольшой трюк, чтобы достичь этого! Помните, что это экспериментально, и у него есть некоторые ограничения ... (проверьте эту ссылку , если вы беспокоитесь о совместимости с навигатором)
Что вы можете сделать, это использовать селектор CSS3: псевдо classe nth-child()
#list>* {
display: inline-block;
padding: 20px 28px;
margin-right: 5px;
border: 1px solid #bbb;
background: #ddd;
color: #444;
margin: 0.4em 0;
}
#list :nth-child(-n+4) {
color: #600b90;
border: 1px dashed red;
background: orange;
}
The oranges elements are the previous sibling li selected using li:nth-child(-n+4)
1
2
3
4
5
6
7
8
9
В ответе на этот вопрос лежит ваше решение, только в Javascript ...
Сгенерировать более светлый / темный цвет в css с помощью javascript
I «Не собираюсь писать, но простой поиск Google для« lighten hex color php »дает:
function colourBrightness($hex, $percent) {
// Work out if hash given
$hash = '';
if (stristr($hex,'#')) {
$hex = str_replace('#','',$hex);
$hash = '#';
}
/// HEX TO RGB
$rgb = array(hexdec(substr($hex,0,2)), hexdec(substr($hex,2,2)), hexdec(substr($hex,4,2)));
//// CALCULATE
for ($i=0; $i<3; $i++) {
// See if brighter or darker
if ($percent > 0) {
// Lighter
$rgb[$i] = round($rgb[$i] * $percent) + round(255 * (1-$percent));
} else {
// Darker
$positivePercent = $percent - ($percent*2);
$rgb[$i] = round($rgb[$i] * $positivePercent) + round(0 * (1-$positivePercent));
}
// In case rounding up causes us to go to 256
if ($rgb[$i] > 255) {
$rgb[$i] = 255;
}
}
//// RBG to Hex
$hex = '';
for($i=0; $i < 3; $i++) {
// Convert the decimal digit to hex
$hexDigit = dechex($rgb[$i]);
// Add a leading zero if necessary
if(strlen($hexDigit) == 1) {
$hexDigit = "0" . $hexDigit;
}
// Append to the hex string
$hex .= $hexDigit;
}
return $hash.$hex;
}
http://lab.pxwebdesign.com.au/?p = 14
Ваш Google так же хорош, как и мой!
Ссылки на Michael Michael довольно страшны. Но решение прост. Это может быть более ясным, если вы рассматриваете просто изображение с серой шкалой:
function create_pallette($start, $end, $entries=10)
{
$inc=($start - $end)/($entries-1);
$out=array(0=>$start);
for ($x=1; $x<$entries;$x++) {
$out[$x]=$start+$inc * $x;
}
return $out;
}
Только использование трехмерного вектора (RGB) вместо 1D-вектора.
C.