这篇文章主要介绍“怎么用CSS Frasbox创建一个CSS比较表”,在日常操作中,相信很多人在怎么用CSS Frasbox创建一个CSS比较表问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用CSS Frasbox创建一个CSS比较表”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
比较表是由多个相互堆叠的ULs组成的。我将使用CSS Flex框使它们都相等的宽度,并以相同的速率扩展和收缩,因此它们的行为与表中的行类似。
One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen Twenty Twenty-one Twenty-two Twenty-three Twenty-four Twenty-five Twenty-six Twenty-seven Twenty-eight Twenty-nine Thirty Thirty-one Thirty-two Thirty-three Thirty-four Thirty-five Thirty-six Thirty-seven Thirty-eight Thirty-nine Forty Forty-one Forty-two Forty-three Forty-four Forty-five Forty-six Forty-seven Forty-eight Forty-nine Fifty Fifty-one | <div class="comparisontable">
<ul class="row" >
<li class="legend">Office Chairs</li>
<li><img src="Eurotech-chair.jpg"/><br />Eurotech</li>
<li><img src="Hbada-chair.jpg"/><br />Hbada</li>
<li><img src="Zenith-chair.jpg"/><br />Zenith</li>
<li><img src="amazonbasics-chair.jpg"/><br />Amazonbasics</li>
</ul>
<ul class="row" >
<li class="legend">Weight</li>
<li>25kg</li>
<li>13kg</li>
<li>17kg</li>
<li>28kg</li>
</ul>
<ul class="row" >
<li class="legend">Cost</li>
<li>$$</li>
<li>$</li>
<li>$$</li>
<li>$</li>
</ul>
<ul class="row" >
<li class="legend">Delivery</li>
<li>Domestic</li>
<li>International</li>
<li>International</li>
<li>Domestic</li>
</ul>
<ul class="row" >
<li class="legend">Verdict</li>
<li>Best ChairforBack Pain</li>
<li>Best budget chair</li>
<li>All MeshforCooling</li>
<li>Only ChairwithTop Grain Leather</li>
</ul>
<ul class="row" >
<li class="legend"></li>
<li><a href=""class="calltoaction">Buy Now</a></li>
<li><a href=""class="calltoaction">Buy Now</a></li>
<li><a href=""class="calltoaction">Buy Now</a></li>
<li><a href=""class="calltoaction">Buy Now</a></li>
</ul>
</div>
|
每个UL中的第一个Li元素是特征/图例。为了轻松地将它们与其他的包装不同,我把那些Li元素作为一个“传奇”的CSS类。
CSS:
现在是有趣的部分-将标记转换为比较表。使用CSS FrasBox,转换UL元素相对容易,因此它们在布局、弯曲和拉伸方面是水平的,因此它们的行为更像表单元。
我已经删除了一些不必要的线,所以你可以把重点放在下面的重要位置:
One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen Twenty Twenty-one Twenty-two Twenty-three Twenty-four Twenty-five Twenty-six Twenty-seven Twenty-eight Twenty-nine Thirty Thirty-one Thirty-two Thirty-three Thirty-four Thirty-five Thirty-six Thirty-seven Thirty-eight Thirty-nine Forty Forty-one Forty-two Forty-three Forty-four Forty-five Forty-six Forty-seven Forty-eight | div.comparisontable{
显示:flex;
FLEX-Direction:Column;
}
div.comparisontable ul.row{
列表样式:无;
显示:flex;
Flex:1;
flex-wrap: wrap;
}
div.comparisontable ul.row li{
背景:#c9f4ca;
Flex:1;
PADDING:10PX;
Border-bottom:1px solid gray;
}
div.comparisontable ul.row li.legend{
背景:#6640d8;
color: white;
边界:无;
宽度:200px;
border-bottom: 1px solid white;
}
div.comparisontable ul.row:first-of-type li{
Text-align:Center;
}
div.comparisontable ul.row:last-of-type li{
Text-align:Center;
边界底部:无;
P.O.Box-Shadow:0 6PX 6PX RGBA(0.0,0.23);
}
div.comparisontable ul.row:first-of-type li.legend.legend,
div.comparisontable ul.row:last-of-type li.legend{
背景:透明;
盒影:无;
}
|
“特征列表”或“传奇”列是每行的第一个Li元素。它具有明确的宽度为200 px,不像其他的Li元素是Flex宽度(Flex:1)。
比较表的制作
现在,比较表没有响应。也就是说,即使屏幕尺寸变得非常小,每行中的“列”仍然并排。
在CSS Flex框中,通过将Flex方向属性从“行”设置为“列”,可以轻松地将Flex子元素的显示顺序从默认的“并排”行为改为“在下一个上叠加”。
现在在我的比较表中,UL元素本身是堆叠的,尽管孩子的Li元素像表中的单元格一样并排出现。当屏幕足够小的时候,我会把它们改成堆叠。
One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen Twenty Twenty-one Twenty-two Twenty-three Twenty-four Twenty-five Twenty-six Twenty-seven | @media screen and (max-width:650px){
div.comparisontable ul.row{
FLEX-Direction:Column;
}
div.comparisontable img{
width: auto;
高度:自动;
}
div.comparisontable ul.row li{
margin-right: 0;
width: auto;
flex: auto;
}
div.comparisontable ul.row:first-of-type li.legend.legend,
div.comparisontable ul.row:last-of-type li.legend{
显示:无;
}
div.comparisontable ul.row li.legend{
width: auto;
}
}
|
现在,当我调整窗口大小时,比较表崩溃,每个“单元格”出现在自己的行上:
到此,关于“怎么用CSS Frasbox创建一个CSS比较表”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!