获取浮动div以垂直对齐

发布于 2024-11-29 20:46:26 字数 4472 浏览 3 评论 0原文

这是我面临的挑战。我试图让一个 div 出现在另一个对象后面并与其居中对齐。

这就是我到目前为止所做的: http://jsfiddle.net/imoda/GYha2/

这是我想要得到的结果

在此处输入图像描述

正如你所看到的,我很接近。我只是无法让它对齐中心并将其自身定位在另一个对象后面。

有什么想法吗?

HTML:

<div id="banner" class="grid_12">
    <div class="bannerBgT"></div>
    <div class="bannerBgY">
        <div id="planPricingWrapper">
            <div id="planPrices">
                <div class="planPrice">
                    <div class="planPriceX"> </div>
                    <div class="planPriceR"></div>
                    <div class="clear"></div>
                </div>
                <div class="clear_10px"></div>
                <div class="planPrice">
                    <div class="planPriceX"> </div>
                    <div class="planPriceR"></div>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="planPriceOptions">
                <div class="planPriceOptionsBgT" id="supremacy"></div>
                <div class="planPriceOptionsBgY" id="supremacy">
                    <div><img src="http://www.patientacquisitionsystem.com/images/plans/pricing_title_supremacy.png" width="183" height="27" alt="Supremacy" id="titleImg" /></div>
                    <img src="http://www.patientacquisitionsystem.com/images/plans/pricing_plan_supremacy.png" width="146" height="156" alt="" />
                    <div class="planFeatures"> <b>Includes Gold &amp; Platinum Features Plus:</b>
                        <ul>
                            <li>Class 3 Rayhawk Design</li>
                            <li>Class 3 Content Management</li>
                            <li>Up to 6 Content Modules</li>
                            <li>Inclusion in 2 or more directories/portals</li>
                            <li>Access to Rayhawk brand management services*</li>
                            <li>Mobile device enabled educational content/videos</li>
                            <li>Marketing materials deployment system*^</li>
                            <li>2 hours per month of additional services</li>
                        </ul>
                    </div>
                </div>
                <div class="planPriceOptionsBgB" id="supremacy"></div>
            </div>
        </div>
        <div class="clear"></div>
    </div>
    <div class="bannerBgB"></div>
</div>

CSS:

#planPricingWrapper {
    padding: 20px;
}

#planPrices {
    float: right;
}

#planPrices * {
    z-index: 1;
}

.planPrice > * {
    float: left;
}

.planPriceX {
    width: 280px;
    height: 131px;
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_bg_x.png) repeat-x;
}

.planPriceR {
    width: 11px;
    height: 131px;
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_bg_r.png) no-repeat;
}

#planPriceOptions {
    z-index: 9999999;
}

.planPriceOptionsBgT, .planPriceOptionsBgB {
    width: 614px;
}

.planPriceOptionsBgT#supremacy, .planPriceOptionsBgY#supremacy, .planPriceOptionsBgB#supremacy {
    background-color: #181818;
}

.planPriceOptionsBgT {
    height: 10px;
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_plan_bg_t.png) no-repeat;
}

.planPriceOptionsBgY {
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_plan_bg_y.png) repeat-y;
    color: #FFF;
    text-align: center;
    padding: 20px;
    width: 574px;
    min-height: 250px;
}

.planPriceOptionsBgY #titleImg {
    margin-bottom: 10px;
}

.planPriceOptionsBgB {
    height: 12px;
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_plan_bg_b.png) no-repeat;
}

.planFeatures {
    display: inline-block;
    vertical-align: top;
    font-size: 14px;
    text-align: left;
    list-style: square;
    margin-left: 10px;
}

.planFeatures ul {
    list-style: square;
}

Here's the challenge I'm facing. I'm trying to get a div to appear behind another object and to center align to it.

This is what I'm up to so far: http://jsfiddle.net/imoda/GYha2/

And this is the result I'm trying to get

enter image description here

As you can see, I'm close. I just can't get it to align center and to position itself behind the other object.

Any thoughts?

HTML:

<div id="banner" class="grid_12">
    <div class="bannerBgT"></div>
    <div class="bannerBgY">
        <div id="planPricingWrapper">
            <div id="planPrices">
                <div class="planPrice">
                    <div class="planPriceX"> </div>
                    <div class="planPriceR"></div>
                    <div class="clear"></div>
                </div>
                <div class="clear_10px"></div>
                <div class="planPrice">
                    <div class="planPriceX"> </div>
                    <div class="planPriceR"></div>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="planPriceOptions">
                <div class="planPriceOptionsBgT" id="supremacy"></div>
                <div class="planPriceOptionsBgY" id="supremacy">
                    <div><img src="http://www.patientacquisitionsystem.com/images/plans/pricing_title_supremacy.png" width="183" height="27" alt="Supremacy" id="titleImg" /></div>
                    <img src="http://www.patientacquisitionsystem.com/images/plans/pricing_plan_supremacy.png" width="146" height="156" alt="" />
                    <div class="planFeatures"> <b>Includes Gold & Platinum Features Plus:</b>
                        <ul>
                            <li>Class 3 Rayhawk Design</li>
                            <li>Class 3 Content Management</li>
                            <li>Up to 6 Content Modules</li>
                            <li>Inclusion in 2 or more directories/portals</li>
                            <li>Access to Rayhawk brand management services*</li>
                            <li>Mobile device enabled educational content/videos</li>
                            <li>Marketing materials deployment system*^</li>
                            <li>2 hours per month of additional services</li>
                        </ul>
                    </div>
                </div>
                <div class="planPriceOptionsBgB" id="supremacy"></div>
            </div>
        </div>
        <div class="clear"></div>
    </div>
    <div class="bannerBgB"></div>
</div>

CSS:

#planPricingWrapper {
    padding: 20px;
}

#planPrices {
    float: right;
}

#planPrices * {
    z-index: 1;
}

.planPrice > * {
    float: left;
}

.planPriceX {
    width: 280px;
    height: 131px;
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_bg_x.png) repeat-x;
}

.planPriceR {
    width: 11px;
    height: 131px;
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_bg_r.png) no-repeat;
}

#planPriceOptions {
    z-index: 9999999;
}

.planPriceOptionsBgT, .planPriceOptionsBgB {
    width: 614px;
}

.planPriceOptionsBgT#supremacy, .planPriceOptionsBgY#supremacy, .planPriceOptionsBgB#supremacy {
    background-color: #181818;
}

.planPriceOptionsBgT {
    height: 10px;
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_plan_bg_t.png) no-repeat;
}

.planPriceOptionsBgY {
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_plan_bg_y.png) repeat-y;
    color: #FFF;
    text-align: center;
    padding: 20px;
    width: 574px;
    min-height: 250px;
}

.planPriceOptionsBgY #titleImg {
    margin-bottom: 10px;
}

.planPriceOptionsBgB {
    height: 12px;
    background: url(http://www.patientacquisitionsystem.com/images/plans/pricing_plan_bg_b.png) no-repeat;
}

.planFeatures {
    display: inline-block;
    vertical-align: top;
    font-size: 14px;
    text-align: left;
    list-style: square;
    margin-left: 10px;
}

.planFeatures ul {
    list-style: square;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凤舞天涯 2024-12-06 20:46:27

基本上有两种方法可以实现垂直对齐:

  1. 使用表格(使用真正的 HTML 标记或假 CSS display:table-cell 声明)

  2. 使用内联元素(同样,要么是自然内联的真实 HTML 元素,例如 ,要么是 CSS display:inline-block 声明)

这是一个更新的小提琴,它使用 display:inline-block大约< /em> 我想,得到你想要的吧。请注意,我还翻转了 HTML 中的两个 div。

它还使用 *display:inline; Zoom:1; 修改使其适用于 IE6/7

There are basically two ways to do vertically aligning:

  1. Use tables (using either real HTML <table> tags or fake CSS display:table-cell declarations)
  2. Use inline elements (again, either real HTML elements that are naturally inline, like <span>, or CSS display:inline-block declarations)

Here's an updated fiddle that uses display:inline-block to approximately get what you're after, I think. Notice that I also flipped around the two divs in the HTML.

It also uses the *display:inline; zoom:1; hack to make it work with IE6/7

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文