您可以从以下代码中获取 W3schools.com为博客博客帖子定制了它。
<style>
/*----------Price Box--------------*/
.pricecolumns {
float: left;
width: 33.3%;
padding: 8px;
}
.price {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.price:hover {
box-shadow: 0 8px 12px 0 rgba(0,0,0,0.2)
}
.price .priceheader {
background-color: #2CB8DA;
color: white;
font-size: 25px;
}
.price li {
border-bottom: 1px solid #eee;
padding: 20px;
text-align: center;
}
.price .grey {
background-color: #FFFFEF;
font-size: 20px;
}
.pricebutton {
background-color: #FBA614;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
font-size: 18px;
}
</style>
&#13;
<body>
<div class="pricecolumns">
<ul class="price">
<li class="priceheader">Rent</li>
<li class="grey">$ 18.99 / Month</li>
<li>Test The Product on Live Market</li>
<li class="grey"><a href="#" class="pricebutton">Rent</a></li>
</ul>
</div>
<div class="pricecolumns">
<ul class="price">
<li class="priceheader" style="background-color:#4CAF50">Buy</li>
<li class="grey">$ 27.99 Life Time</li>
<li>Buy Forever License</li>
<li class="grey"><a href="#" class="pricebutton">Buy Now!</a></li>
</ul>
</div>
</body>
&#13;
但问题是。街区一个接一个地展示。与网站上显示的2列不同。
我无法添加以下代码(正如教程建议的那样),因为这个代码让博客下拉菜单看起来很奇怪。
* {
box-sizing: border-box;
}
&#13;
答案 0 :(得分:3)
你的CSS有问题。 您在css中使用了错误的css选择器,这是一个错字。
更改此内容
.pricecolumns {
float: left;
width: 33.3%;
padding: 8px;
}
到此 -
.price_columns {
float: left;
width: 33.3%;
padding: 8px;
}
以下是2个comlumns和3个列的认可 -
2列 -
/*----------Price Box--------------*/
.price_columns {
float: left;
width: 33.3%;
padding: 8px;
}
.price {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.price:hover {
box-shadow: 0 8px 12px 0 rgba(0,0,0,0.2)
}
.price .priceheader {
background-color: #2CB8DA;
color: white;
font-size: 25px;
}
.price li {
border-bottom: 1px solid #eee;
padding: 20px;
text-align: center;
}
.price .grey {
background-color: #FFFFEF;
font-size: 20px;
}
.pricebutton {
background-color: #FBA614;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
font-size: 18px;
}
@media only screen and (max-width: 520px) {
.pricecolumns {
width: 100%;
}
}
<body>
<div class="price_columns">
<ul class="price">
<li class="priceheader">Rent</li>
<li class="grey">$ 18.99 / Month</li>
<li>Test The Product on Live Market</li>
<li class="grey"><a href="#" class="pricebutton">Rent</a></li>
</ul>
</div>
<div class="price_columns">
<ul class="price">
<li class="priceheader" style="background-color:#4CAF50">Buy</li>
<li class="grey">$ 27.99 Life Time</li>
<li>Buy Forever License</li>
<li class="grey"><a href="#" class="pricebutton">Buy Now!</a></li>
</ul>
</div>
</body>
3列 -
/*----------Price Box--------------*/
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-moz-box-sizing: border-box;
}
.price_columns {
float: left;
width: 33.3%;
padding: 8px;
}
.price {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.price:hover {
box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2)
}
.price .priceheader {
background-color: #2CB8DA;
color: white;
font-size: 25px;
}
.price li {
border-bottom: 1px solid #eee;
padding: 20px;
text-align: center;
}
.price .grey {
background-color: #FFFFEF;
font-size: 20px;
}
.pricebutton {
background-color: #FBA614;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
font-size: 18px;
}
@media only screen and (max-width: 520px) {
.pricecolumns {
width: 100%;
}
}
<body>
<div class="price_columns">
<ul class="price">
<li class="priceheader">Rent</li>
<li class="grey">$ 18.99 / Month</li>
<li>Test The Product on Live Market</li>
<li class="grey"><a href="#" class="pricebutton">Rent</a></li>
</ul>
</div>
<div class="price_columns">
<ul class="price">
<li class="priceheader" style="background-color:#4CAF50">Buy</li>
<li class="grey">$ 27.99 Life Time</li>
<li>Buy Forever License</li>
<li class="grey"><a href="#" class="pricebutton">Buy Now!</a></li>
</ul>
</div>
<div class="price_columns">
<ul class="price">
<li class="priceheader" style="background-color:red">Buy</li>
<li class="grey">$ 27.99 Life Time</li>
<li>Buy Forever License</li>
<li class="grey"><a href="#" class="pricebutton">Buy Now!</a></li>
</ul>
</div>
</body>
Box-Sizing仅适用于此特定部分:
/*----------Price Box--------------*/
.price_columns {
float: left;
width: 33.3%;
padding: 8px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-moz-box-sizing: border-box;
}
.price {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.price:hover {
box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2)
}
.price .priceheader {
background-color: #2CB8DA;
color: white;
font-size: 25px;
}
.price li {
border-bottom: 1px solid #eee;
padding: 20px;
text-align: center;
}
.price .grey {
background-color: #FFFFEF;
font-size: 20px;
}
.pricebutton {
background-color: #FBA614;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
font-size: 18px;
}
@media only screen and (max-width: 520px) {
.pricecolumns {
width: 100%;
}
}
<body>
<div class="price_columns">
<ul class="price">
<li class="priceheader">Rent</li>
<li class="grey">$ 18.99 / Month</li>
<li>Test The Product on Live Market</li>
<li class="grey"><a href="#" class="pricebutton">Rent</a></li>
</ul>
</div>
<div class="price_columns">
<ul class="price">
<li class="priceheader" style="background-color:#4CAF50">Buy</li>
<li class="grey">$ 27.99 Life Time</li>
<li>Buy Forever License</li>
<li class="grey"><a href="#" class="pricebutton">Buy Now!</a></li>
</ul>
</div>
<div class="price_columns">
<ul class="price">
<li class="priceheader" style="background-color:red">Buy</li>
<li class="grey">$ 27.99 Life Time</li>
<li>Buy Forever License</li>
<li class="grey"><a href="#" class="pricebutton">Buy Now!</a></li>
</ul>
</div>
</body>
答案 1 :(得分:2)
<div class="price_columns">
是你的错误,因为在CSS中你没有下划线的课,你有pricecolumns