1

私の目標は、この投票http://tsn.thesn.net/poll/962に動的なテキストの色を付けて、背景色がない場合はテキストが濃い灰色になり、緑の背景が存在する場合はテキストが白になるようにすることです。

背景とテキストの私のスタイルは次のとおりです。

.chartlist .item { 
  display: block; 
  padding: 0.4em 4.5em 0.4em 0.5em;
  position: relative; 
  z-index: 2;
  font-weight: bold;
  color: @grayDarker; 
}

.chartlist .index { 
  display: block; 
  position: absolute; 
  top: 0; 
  left: 0; 
  height: 100%; 
  background: @green; 
  text-indent: -9999px; 
  overflow: hidden; 
  line-height: 2em;
 }  

LESS でこれに関するドキュメントを読みましたが、構文がどのように機能するかを視覚化するのに問題があります。どんな助けでも大歓迎です、ありがとう。

4

1 に答える 1

0

私はこのようなものを書くでしょう:

.colors(@col){
   color:@col;
}
.colors(@col,@bgcol){
   color:@col;
   background:@bgcol;
}

そして、あなたは書くことができます:

.chartlist .item { 
 /* ... */
  colors(@grayDarker); 
}
.chartlist .index { 
  /* ... */
  colors(white,@green);
} 
于 2012-10-05T14:53:00.130 に答える