将div放在另一个动态大小div旁边

时间:2013-02-28 07:01:00

标签: css image html

我需要在div中放置带有id“divThumbnail”,“bannerImageProgress”和“divRemoveBanner”的三个div,并在图像中显示id“wrapper”。加载到“divThumbnail”div中的是一个图像,它可能会改变大小。我需要“bannerImageProgress”在“divThumbnail”的左边,“divRemoveBanner”在它的正下方。由于divThumbnail的大小可以动态改变,定义绝对位置(如代码所示)不会产生所需的行为。

这就是我需要它的方法:[图像旁边有进度条的div,图像下面有删除单词的div]

enter image description here

对于方形图像,“bannerImageProgress”div不会显示在图像旁边:

enter image description here

到目前为止我的HTML代码:

    <div id="wrapper" class="image-area-container">
       <div id="divThumbnail" class="image_outer_div" style="width: 200px; height: 60px; ">
           @if ( Model.HasBanner ) {
           <img id = "bannerThumbnail" src = "@Model.BannerLink" />
           }
       </div>
       <div id = "bannerImageProgress" class = "progress progress-success" style="display: inline-block; float: left; left: 566px;">
           <div id = "bannerImage" class = "bar" style = "float: left; width: 0%;" data-percentage="0">
           </div>
       </div>

       <div id="divRemoveBanner" style="display:none;">
        <a id="removeBanner">Remove</a>
       </div>
    </div>

CSS:

<!-- language: lang-css -->

    .image-area-container {
        float: left;
        width: 65px;
        margin-left: 10px;
    }

    .image_outer_div { 
        height: 60px; 
        overflow: hidden;
        width: 200px; 
        vertical-align: top;
        margin-bottom: 5px;
    }

    .image_area .progress {
        left: 346px;
        position: absolute;
        top: 4px;
        width: 200px;
     }

提前致谢! :)

应用Ali建议的更改后:

进展不顺利。现在“divThumbnail”div和“bannerImageProgress”div重叠:(像这样: -

enter image description here

更改后的代码: -

<div class="image-area-container" style="position:relative; width: 400px;">

                        <div id="divThumbnail" class="image_outer_div" style="width: 200px; height: 60px; float: left; ">
                            @if (Model.HasBanner)
                            {
                                <img id="bannerThumbnail" src="@Model.BannerLink" />
                            }

                        </div>

                        <div id="bannerImageProgress" class="progress progress-success" style="display: inline-block; clear:both; position:absolute; left:0; right:0;">
                            <div id="bannerImage" class="bar" style="float: left; width: 0%;" data-percentage="0">
                            </div>
                        </div>

                    <div id="divRemoveBanner" style="display:none; clear:both; float: left;">
                        <a id="removeBanner">Remove</a>
                    </div>

                </div>

1 个答案:

答案 0 :(得分:0)

为什么不向右浮动进度条而剩下的另外两个? 要么 给图像另一个具有固定宽度的div包装器?