调整另一个div底部的div

时间:2015-04-13 00:32:07

标签: html css

我正试图将蓝色div放在这张照片的底部,我因某种原因而陷入困境。

我的CSS:

    .boxes {
        margin-left: 4%;
        margin-right: -4px; 
        height: 345px;
        padding: 5px;
        font-size: 12px;
    }

    .box-one{
        background-image: url("uploadir.com/u/nxa8310f");
        background-repeat: no-repeat;
        background-size: cover;
    }

    .index-image-text {
        padding-bottom: 0;
        margin-bottom: 0;
        font-weight: bold;
        color: white;
        background-color: #2E3192;
        }

HTML:

   <div class="boxes img-rounded box-one grid-20">

    <h1>Pottery Painting</h1>
        <p class="index-image-text">
            Testing<br>             
        </p>

    </div>

它显示了两侧的小差距,但我想要一直在div的底部,没有差距。

这就是它的表现:

https://sc-cdn.scaleengine.net/i/b4a1b72231a52f3a4977f68b76c0a7ad.png

这就是我想要展示的内容: https://sc-cdn.scaleengine.net/i/c66fe095c68250837b4b320c87bf72f0.png

任何想法?这是一个小提琴:jsfiddle.net/kzaLx2vb /

3 个答案:

答案 0 :(得分:0)

可能是这个帮助。

  

<强> HTML:

<div class="boxes img-rounded box-one grid-20">
        <h1>Pottery Painting</h1>
        <p class="index-image-text">Testing</p>
</div>
  

<强> CSS:

body {
    width: 300px;
}
.boxes {
    margin-left: 4%;
    margin-right: -4px; 
    height: 345px;
    font-size: 12px;
}
.box-one{
    background-image: url("http://uploadir.com/u/nxa8310f");
    background-repeat: no-repeat;
    background-size: cover;
}
.index-image-text {
    padding-bottom: 0;
    margin-bottom: 0;
    position:relative; 
    top:75%;            
    font-weight: bold;
    border-bottom-left-radius: 2px;
    border-bottom-right-radius: 2px;
    color: white;
    background-color: #2E3192;
    text-align: center;
    padding-top: 10px;
}
h1 {
    padding-top: 30px;
    text-align: center;
    color:#FFF;
}

JSFiddle: http://jsfiddle.net/5q354m3h/

答案 1 :(得分:0)

实现目标的好方法是给盒子一个相对的风格:

.box-one{
 position:relative;
}

然后绝对定位你的索引图像文本

.index-image-text {
  position:absolute;
  bottom: 0;
  left:0;
  right:0;
}

答案 2 :(得分:0)

http://jsfiddle.net/kzaLx2vb/11/

CSS:

.boxes {
    margin-left: 4%;
    margin-right: -4px; 
    height: 345px;
    font-size: 12px;
    /* addition code */
    padding: 0; /*change your padding from 5px to 0*/
    position: relative; /* set to relative to be the reference outter box */
    border-radius: 10px; /* rounded corner based on the reference image */
    overflow: hidden; /* to cut out for the bottom rounded corner  */
    max-width: 320px; /* this line not required*/
}

.box-one{
    background-image: url("http://uploadir.com/u/nxa8310f");
    background-repeat: no-repeat;
    background-size: cover;
}

h1 {
    color: #fff;
    text-align: center;
}

.index-image-text {
    padding-bottom: 0;
    margin-bottom: 0;
    font-weight: bold;
    color: white;
    background-color: #2E3192;
    /* addition code */
    margin: 0; /* override default padding value on "p" tag */
    padding-top: 10px; /* spacing based on the reference image */
    position: absolute; /* set to absolute to position within relative outter box */
    bottom: 0; /* make the inner box stick to the bottom of outter box */
    width: 100%; /* stretch the inner box to fill up outter box */
    text-align: center; /* position based on the reference image */
    font-family: verdana; /* font fammily based on the image */
}