在HTML中定位文本的问题

时间:2012-12-19 11:24:08

标签: html css positioning

我试图在图像和子弹点之间放置一个段落。我认为我在html中有正确的布局,但由于某种原因它只是没有正确显示。见下图:

enter image description here

正如您所看到的,这些段落出现在其他所有内容之下,但这并不是我在html中的显示方式。请参阅下面的代码:

HTML:

<div class="services">
        <div class="serviceHolder" style="opacity: 1;">
            <div class="serviceBox" id="service-plan">
                <div class="serviceIcon"><img src="images/icon-design.jpg" width="129" height="134" alt="design icon"></div>
                <div class="serviceCopy">
                    <h2>Plan</h2>
                    <ul class="serviceBullets">
                        <li><h3>Objectives</h3></li> 
                        <li><h3>Scope</h3></li>
                        <li><h3>Sitemap</h3></li>
                        <li><h3>Wireframes</h3></li>
                    </ul>   
                    <p>Lorem ipsum dolor sit amet, porta quis urna tempor vestibulum purus, vulputate condimentum arcu faucibus aliquam enim accumsan, a nulla nullam morbi bibendum eveniet tempus, parturient consequat sociis quis. Suscipit in vitae ornare lobortis sed, porta et minima odio neque maecenas cras, justo in. </p>
                    <p>Justo arcu lacus, quos pellentesque nam sit. Luctus mauris egestas, leo nisl porttitor urna scelerisque ut, mauris sodales sapien donec dolor, arcu a ante vestibulum lorem vitae quam</p>
                </div>
            </div>
        </div>

CSS:

.services {
width: 100%; float: left; margin: 30px 0;
}

.services .serviceBox {
width: 898px; padding: 30px; border: 1px solid #43C0C2; background-color: white; float:     left; margin-bottom: 10px;
}

.services .serviceIcon {
float: left; margin: 0 30px 50px 0; width: 129px;
}

.serviceBullets {
float: right; font-weight: 100; width: 150px;
}

.serviceBullets li {
list-style-image: url(../images/bullet.gif); color: #43C0C2; margin-bottom: 10px;
}

.services h2 {
font-size: 40px; margin-bottom: 20px; color: #000000;
}

2 个答案:

答案 0 :(得分:0)

您已将Float:left仅添加到right Div,您还需要使用以下代码更新left div

.serviceCopy
{
  float: left;
  width: 721px;
}

在2 div之后,您还需要再添加一个div以清除所有浮点数

<div class="serviceIcon"></div>
<div class="serviceCopy"></div>
<div style="clear:both"></div>

这样你的布局就不会破坏。

答案 1 :(得分:0)

你是否试图让它成为现实 图像 - 计划和段落 - BULLET点?

或者

图像 - 其他所有图像列都在左侧,其他所有内容都在右侧?

如果是前者。

试试这个:

<div class="serviceHolder" style="opacity: 1;">
        <div class="serviceBox" id="service-plan">
            <div class="serviceIcon"><img src="images/icon-design.jpg" width="129" height="134" alt="design icon"></div>
            <div class="serviceCopy">
            <h2>Plan</h2>
                <p>Lorem ipsum dolor sit amet, porta quis urna tempor vestibulum purus, vulputate condimentum arcu faucibus aliquam enim accumsan, a nulla nullam morbi bibendum eveniet tempus, parturient consequat sociis quis. Suscipit in vitae ornare lobortis sed, porta et minima odio neque maecenas cras, justo in. </p>
                <p>Justo arcu lacus, quos pellentesque nam sit. Luctus mauris egestas, leo nisl porttitor urna scelerisque ut, mauris sodales sapien donec dolor, arcu a ante vestibulum lorem vitae quam</p>
             </div>
            <div class="serviceBullets">
                <ul>
                    <li><h3>Objectives</h3></li> 
                    <li><h3>Scope</h3></li>
                    <li><h3>Sitemap</h3></li>
                    <li><h3>Wireframes</h3></li>
                </ul>   
            </div>
        </div>
    </div>

因此它有自己的div和子弹是分开的。

然后将所有人漂浮下来。并定义它们的宽度。 然后添加一个div,以清除浮动。