The only way to do this (outside of some very laborious positioning) is to combine the elements into a single list, giving each li
a class-name and styling them appropriately:
<div>
<ul>
<li class="left">Item A</li>
<li class="right">Item 1</li>
<li class="left">Item B</li>
<li class="right">Item 2</li>
<li class="left">Item C</li>
<li class="right">Item 3</li>
<li class="left">Item D</li>
<li class="right">Item 4</li>
</ul>
</div>
li {
list-style-type: none;
width: 50%;
}
li.left {
float: left;
background-color: #0f0;
}
li.right {
float: right;
background-color: #00f;
}
@media only screen and (max-width: 480px) {
.left, .right {
float: none;
width: 100%;
}
}
Updated JS Fiddle demo.
As noted by Hashem, in the comments below, it would be possible to use the :nth-child()
selector, rather than class-names, to style the various li
elements left, or right:
li:nth-child(odd) {
float: left;
background-color: #0f0;
}
li:nth-child(even) {
float: right;
background-color: #00f;
}
@media only screen and (max-width: 480px) {
li {
float: none;
width: 100%;
}
}
Updated JS Fiddle demo.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…