cartas-css

La flexibilidad de CSS es impresionante, hasta podemos crear un juego de cartas solamente con CSS y unas imágenes. Si deseamos crearlo, allá van los pasos:

Descarga estas imágenes y súbelas a tu servidor:

King.gif

Queen.gif

Jack.gif

cardback.gif

Ahora inserta este código CSS y Javascript en tu documento (El código Javascript es para hacer las cartas más grandes o pequeñas, el código CSS debe llevar por id “cardStyles”):

<style id="cardStyles" type="text/css">

/******************************************************************************
* Styles for playing cards.                                                   *
******************************************************************************/

.card {
  background-image: url("graphics/cardback.gif");
  border-color: #808080 #000000 #000000 #808080;
  border-width: 1px;
  border-style: solid;
  font-size: 20pt;
  position: absolute;
  width:  3.75em;
  height: 5.00em;
}

.front {
  background-color: #ffffff;
  color: #000000;
  position: absolute;
  width: 100%;
  height: 100%;
}

.red { color: #ff0000; }

.index {
  font-size: 50%;
  font-weight: bold;
  text-align: center;
  position: absolute;
  left: 0.25em;
  top:  0.25em;
}

.ace {
  font-size: 300%;
  position: absolute;
  left: 0.325em;
  top:  0.250em;
}

.face {
  border: 1px solid #000000;
  position: absolute;
  left: 0.50em;
  top:  0.45em;
  width:  2.6em;
  height: 4.0em;
}

.spotA1 { position: absolute; left: 0.60em; top: 0.5em; }
.spotA2 { position: absolute; left: 0.60em; top: 1.5em; }
.spotA3 { position: absolute; left: 0.60em; top: 2.0em; }
.spotA4 { position: absolute; left: 0.60em; top: 2.5em; }
.spotA5 { position: absolute; left: 0.60em; top: 3.5em; }

.spotB1 { position: absolute; left: 1.55em; top: 0.5em; }
.spotB2 { position: absolute; left: 1.55em; top: 1.0em; }
.spotB3 { position: absolute; left: 1.55em; top: 2.0em; }
.spotB4 { position: absolute; left: 1.55em; top: 3.0em; }
.spotB5 { position: absolute; left: 1.55em; top: 3.5em; }

.spotC1 { position: absolute; left: 2.50em; top: 0.5em; }
.spotC2 { position: absolute; left: 2.50em; top: 1.5em; }
.spotC3 { position: absolute; left: 2.50em; top: 2.0em; }
.spotC4 { position: absolute; left: 2.50em; top: 2.5em; }
.spotC5 { position: absolute; left: 2.50em; top: 3.5em; }

/******************************************************************************
* Miscellaneous styles.                                                       *
******************************************************************************/

body {
  background-color: #40a040;
}

</style>

El código Javascript:

[/code]
El código HTML sería este:
<p>
<a href="#" onclick="return resizeCards(-2)">Cartas más pequeñas</a>
|
<a href="#" onclick="return resizeCards(+2)">Cartas más grandes</a>
</p>



<div style="position:relative;margin-top:1em;">

<div class="card" style="left:0em;top:0em;">
<div class="front">
<div class="index">10<br />&amp;spades;</div>
<div class="spotA1">&amp;spades;</div>
<div class="spotA2">&amp;spades;</div>
<div class="spotA4">&amp;spades;</div>
<div class="spotA5">&amp;spades;</div>
<div class="spotB2">&amp;spades;</div>

<div class="spotB4">&amp;spades;</div>
<div class="spotC1">&amp;spades;</div>
<div class="spotC2">&amp;spades;</div>
<div class="spotC4">&amp;spades;</div>
<div class="spotC5">&amp;spades;</div>
</div>
</div>

<div class="card" style="left:4em;top:0em;">
<div class="front red">

<div class="index">9<br />&amp;hearts;</div>
<div class="spotA1">&amp;hearts;</div>
<div class="spotA2">&amp;hearts;</div>
<div class="spotA4">&amp;hearts;</div>
<div class="spotA5">&amp;hearts;</div>
<div class="spotB3">&amp;hearts;</div>
<div class="spotC1">&amp;hearts;</div>
<div class="spotC2">&amp;hearts;</div>

<div class="spotC4">&amp;hearts;</div>
<div class="spotC5">&amp;hearts;</div>
</div>
</div>

<div class="card" style="left:8em;top:0em;">
<div class="front">
<div class="index">8<br />&amp;clubs;</div>
<div class="spotA1">&amp;clubs;</div>
<div class="spotA3">&amp;clubs;</div>

<div class="spotA5">&amp;clubs;</div>
<div class="spotB2">&amp;clubs;</div>
<div class="spotB4">&amp;clubs;</div>
<div class="spotC1">&amp;clubs;</div>
<div class="spotC3">&amp;clubs;</div>
<div class="spotC5">&amp;clubs;</div>
</div>
</div>

<div class="card" style="left:12em;top:0em;">

<div class="front red">
<div class="index">7<br />&amp;diams;</div>
<div class="spotA1">&amp;diams;</div>
<div class="spotA3">&amp;diams;</div>
<div class="spotA5">&amp;diams;</div>
<div class="spotB2">&amp;diams;</div>
<div class="spotC1">&amp;diams;</div>
<div class="spotC3">&amp;diams;</div>

<div class="spotC5">&amp;diams;</div>
</div>
</div>

<div class="card" style="left:16em;top:0em;">
<div class="front">
<div class="index">6<br />&amp;spades;</div>
<div class="spotA1">&amp;spades;</div>
<div class="spotA3">&amp;spades;</div>
<div class="spotA5">&amp;spades;</div>

<div class="spotC1">&amp;spades;</div>
<div class="spotC3">&amp;spades;</div>
<div class="spotC5">&amp;spades;</div>
</div>
</div>

<div class="card" style="left:20em;top:0em;">
<div class="front red">
<div class="index">5<br />&amp;hearts;</div>
<div class="spotA1">&amp;hearts;</div>

<div class="spotA5">&amp;hearts;</div>
<div class="spotB3">&amp;hearts;</div>
<div class="spotC1">&amp;hearts;</div>
<div class="spotC5">&amp;hearts;</div>
</div>
</div>

<div class="card" style="left:0em;top:6em;">
<div class="front">
<div class="index">4<br />&amp;clubs;</div>

<div class="spotA1">&amp;clubs;</div>
<div class="spotA5">&amp;clubs;</div>
<div class="spotC1">&amp;clubs;</div>
<div class="spotC5">&amp;clubs;</div>
</div>
</div>

<div class="card" style="left:4em;top:6em;">
<div class="front red">
<div class="index">3<br />&amp;diams;</div>

<div class="spotB1">&amp;diams;</div>
<div class="spotB3">&amp;diams;</div>
<div class="spotB5">&amp;diams;</div>
</div>
</div>

<div class="card" style="left:8em;top:6em;">
<div class="front">
<div class="index">2<br />&amp;spades;</div>
<div class="spotB1">&amp;spades;</div>

<div class="spotB5">&amp;spades;</div>
</div>
</div>

<div class="card" style="left:12em;top:6em;">
<div class="front red">
<div class="index">A<br />&amp;hearts;</div>
<div class="ace">&amp;hearts;</div>
</div>
</div>

<div class="card" style="left:16em;top:6em;">
<div class="front">
<div class="index">K<br />&amp;clubs;</div>

<div class="spotA1">&amp;clubs;</div>
<div class="spotC5">&amp;clubs;</div>
</div>
</div>

<div class="card" style="left:20em;top:6em;">
<div class="front red">
<div class="index">Q<br />&amp;diams;</div>

<div class="spotA1">&amp;diams;</div>
<div class="spotC5">&amp;diams;</div>
</div>
</div>

<div class="card" style="left:0em;top:12em;">

<div class="front">
<div class="index">J<br />&amp;spades;</div>

<div class="spotA1">&amp;spades;</div>
<div class="spotC5">&amp;spades;</div>
</div>
</div>

<div class="card" style="left:4em;top:12em;"></div>

</div>

Se puede ver un ejemplo de su funcionamiento.

Vía | BrainJar