我试图在父框中对齐这三个框。
我似乎无法在这里找出问题所在。当我在包装的父框中添加<h3></h3>
标记时,框被按下&#34;向下&#34;在父框之外。这就是我的意思。
我试图将所有盒子元素放在彩色框内。以下是此内容的HTML部分。
.pricing {
width: 100%;
height: 300px;
padding-top: 300px;
background-color: #81F7E5;
vertical-align: text-top
}
.price-box {
width: 30%;
height: 100%;
margin-right: 10px;
display: inline-block;
background-color: #D7DAE5;
border: black solid medium;
}
.price {
width: 100%;
height: 20%;
background-color: ;
border-bottom: black solid medium;
}
.price-box h3 {
display: inline-block;
color: black;
font-size: 25px;
margin-top: 3%;
vertical-align: top;
}
.pricing-text {
position: relative;
top: -150px;
border: solid black medium;
display: block;
width: 400px;
height: 100px;
vertical-align: top;
}
.pricing-text h3 {
text-transform: uppercase;
color: black;
font-size: 2em;
margin-top: 25px;
}
&#13;
<div class="pricing">
<div class="pricing-text">
<h3> Pricing </h3>
</div>
<div class="price-box">
<div class="price">
<h3>$9 per month</h3>
</div>
</div>
<div class="price-box">
<div class="price">
<h3>$14 per month</h3>
</div>
</div>
<div class="price-box">
<div class="price">
<h3>$20 per month</h3>
</div>
</div>
</div>
&#13;
我为这个长期问题道歉。我对前端开发相当陌生,任何建议都会帮助我成长。非常感谢你。
答案 0 :(得分:1)
道歉,如果这是冒昧的,但你的CSS很乱。我已将其清理干净并在评论中解释我认为你出错了。 http://jsfiddle.net/q9xgsqh5/1/
.pricing-text {
position: relative;
top: -150px;
这尤其是我删除的东西,而是依赖于html的自然流程以适应所有内容。虽然这很好用,但它有点乱。
如果您有任何问题,请与我们联系。
答案 1 :(得分:1)
看起来你已经有了很好的建议。根据您的页面是否需要响应,您可以将标记包装在父容器中并添加宽度和高度。然后在剩余代码上使用百分比。添加填充时要小心......记住它会影响容器的总宽度和高度,并会导致不稳定的效果。最后,我使用了临时CSS重置。这使您可以更好地控制样式。我建议您访问此页面作为示例。 http://cssreset.com/
* {
margin: 0;
padding: 0;
border: 0;
}
#wrapper {
width: 960px;
height: 350px;
margin: 0 auto;
}
.pricing {
width: 100%;
min-height: 10%;
/*height: 300px;*/
/*padding-top: 300px;*/
background-color: #81F7E5;
vertical-align: text-top;
margin: 0 auto;
}
.price-box {
width: 30%;
height: 90%;
/*margin-right: 10px;*/
margin-bottom: 10px;
margin-left: 17px;
display: inline-block;
background-color: #D7DAE5;
border: black solid medium;
}
.price {
width: 100%;
height: 20%;
/* background-color: ;*/
border-bottom: black solid medium;
}
.price-box h3 {
display: inline-block;
color: black;
font-size: 25px;
margin-top: 3%;
vertical-align: top;
text-align: center;
}
.pricing-text {
position: relative;
/*top: -150px;*/
border: solid black medium;
display: block;
width: 400px;
height: 100px;
vertical-align: top;
margin: 0 auto;
text-align: center;
}
.pricing-text h3 {
text-transform: uppercase;
color: black;
font-size: 2em;
margin-top: 25px;
}
.price h3 {
text-align: center;
width: 100%;
}
</style>
</head>
<body>
<div id="wrapper">
<div class="pricing">
<div class="pricing-text">
<h3> Pricing </h3>
</div>
<div class="price-box">
<div class="price">
<h3>$9 per month</h3>
</div>
</div>
<div class="price-box">
<div class="price">
<h3>$14 per month</h3>
</div>
</div>
<div class="price-box">
<div class="price">
<h3>$20 per month</h3>
</div>
</div>
</div><!-- end pricing -->
</div><!-- end wrapper -->
答案 2 :(得分:0)
这不是一种正确的方式来做你想做的事情,因为在向每个盒子添加内容时会遇到一些问题。反正
用此
替换此课程的高度.pricing {
height: auto;
}
并添加一个真正的高度
.price-box {
height: 200px;
}
答案 3 :(得分:0)
寻找这样的东西?
.pricing {
width: 100%;
height: 300px;
/*padding-top: 300px;*/
background-color: #81F7E5;
vertical-align: text-top;
}
.price-box {
width: 30%;
height: 100%;
/*margin-right: 5px;*/
margin: 5px 5px;
display: inline-block;
background-color: #D7DAE5;
border: black solid medium;
max-height:75%;
}
.price {
width: 100%;
height: 20%;
background-color: ;
border-bottom: black solid medium;
}
.price-box h3 {
display: inline-block;
color: black;
font-size: 25px;
margin-top: 3%;
vertical-align: top;
}
.pricing-text {
position: relative;
/*top: -150px;*/
border: solid black medium;
display: block;
/*width: 400px;*/
height:40px;
vertical-align: top;
}
.pricing-text h3 {
text-transform: uppercase;
color: black;
font-size: 2em;
margin-top: 0px;
}
<div class="pricing">
<div class="pricing-text">
<h3> Pricing </h3>
</div>
<div class="price-box">
<div class="price">
<h3>$9 per month</h3>
</div>
</div>
<div class="price-box">
<div class="price">
<h3>$14 per month</h3>
</div>
</div>
<div class="price-box">
<div class="price">
<h3>$20 per month</h3>
</div>
</div>
</div>
答案 4 :(得分:0)
错误在.price-box
,您必须删除height: 100%
;
以这种方式做到:
HTML代码,添加了class="content"
的另一个div:
<div class="pricing">
<div class="pricing-text">
<h3> Pricing </h3>
</div>
<div class="price-box">
<div class="price">
<h3>$9 per month</h3>
</div>
<div class="content">
Text of the price-box
</div>
</div>
<div class="price-box">
<div class="price">
<h3>$14 per month</h3>
</div>
<div class="content">
Text of the price-box
</div>
</div>
<div class="price-box">
<div class="price">
<h3>$9 per month</h3>
</div>
<div class="content">
Text of the price-box
</div>
</div>
CSS代码:
.pricing {
width: 100%;
height: 300px;
padding-top: 300px;
background-color: #81F7E5;
vertical-align: text-top
}
.price-box {
width: 30%;
margin-right: 10px;
display: inline-block;
background-color: #D7DAE5;
border: black solid medium;
}
.content {
padding: 10px;
text-align: center;
}
.price {
width: 100%;
height: 20%;
background-color: ;
border-bottom: black solid medium;
}
.price-box h3 {
display: inline-block;
color: black;
font-size: 25px;
margin-top: 3%;
vertical-align: top;
}
.pricing-text {
position: relative;
top: -150px;
border: solid black medium;
display: block;
width: 400px;
height: 100px;
vertical-align: top;
}
.pricing-text h3 {
text-transform: uppercase;
color: black;
font-size: 2em;
margin-top: 25px;
}
我希望我能帮到你。