Change elements using CSS?
I have a pretty simple layout, for example:
<div class="card">
<span class="attack">1</div>
<span class="defence">2</div>
</div>
They are located one above the other with a simple display: block. What I want to achieve is when the card is in certain areas, the “attack” shows below, and the “defense” shows above. I know I can do this with jQuery, but can I achieve the same effect using pure CSS?
+5
6 answers
, :
.card {
width: 100px;
height: 150px;
float: left;
}
.attack, .defence {
width: 100px;
height: 75px;
clear: right;
}
/* Play with height and padding-top of .defence to
get the text to the very bottom */
.attack-top .card .attack {
float: left;
}
.attack-top .card .defence {
float: right;
height: Wpx;
padding-top: Xpx;
}
/* Play with height and padding-top of .attack to
get the text to the very bottom */
.defence-top .card .attack {
float: right;
height: Ypx;
padding-top: Zpx;
}
.defence-top .card .defence {
float: left;
}
, , , .
- " ". , (
.attack-top.defence-top, , ). - ,
.card100 150 . , ..card/, - , , , ( ).
+1
You can do this using (if you only want to swap in div.card):
.card .attack {
position: relative;
top: 1em;
}
.card .defence {
position: relative;
top: -1em;
}
But, as others have said, this can have some unintended side effects. For example. the above pattern will correctly move the swap position for only 1 string blocks.
0