bootstrap,div左侧图像和底部按钮

时间:2017-01-24 20:11:34

标签: css twitter-bootstrap css-float twitter-bootstrap-2

我怎么能用bootstrap做这样的事情

what i want creat

我想要一个div,左边有一个图像(float:left) 和一个文本(可以有一行或两行或更多行),右下角是一个按钮 但是我希望在这个位置一直对齐按钮(不要关心div有一个,两个或多个行文本)

是的,任何帮助 (抱歉英语不好)

编辑: 我用这个HTML代码和Bootstrap v3.3.7(css)                     

              <div class="col-lg-6" style="text-align: right; ">
                <img src="http://placehold.it/150x150" class="pull-right">
                <h1>Ipsum</h1>
                <p><b>Ipsum dolor</b></p>
                <p>
                  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis quidem voluptatibus consequatur
                </p>
                <button>consectetur</button>
              </div>

              <div class="col-lg-6" style="text-align: left; ">
                <img src="http://placehold.it/150x150" class="pull-left">
                <h1>Dolor</h1>
                <p><b>Dotum dolor</b></p>
                <p>
                  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis quidem voluptatibus consequatur
                </p>
                <button>consectetur</button>
              </div>

            </div>

link to jsfiddle

2 个答案:

答案 0 :(得分:0)

使用纯Bootstrap 3.3.7类是不可能的。 Bootstrap使用浮动,但你需要在这里使用flex box模型。

这是一个可能的Flexbox模型解决方案:

.flex_row {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
        -ms-flex-direction: row;
            flex-direction: row;
    -ms-flex-wrap: nowrap;
        flex-wrap: nowrap;
    -webkit-box-pack: start;
        -ms-flex-pack: start;
            justify-content: flex-start;
    -ms-flex-line-pack: stretch;
        align-content: stretch;
    -webkit-box-align: start;
        -ms-flex-align: start;
            align-items: flex-start;
}

.article {
    box-sizing: border-box;
    -webkit-box-flex: 1;
        -ms-flex: 1 1 50%;
            flex: 1 1 50%;
    -ms-flex-item-align: stretch;
        -ms-grid-row-align: stretch;
        align-self: stretch;
    padding: 10px;
}

.content {
    box-sizing: border-box;
    -webkit-box-flex: 1;
        -ms-flex: 1 1 auto;
            flex: 1 1 auto;
    -ms-flex-item-align: stretch;
        align-self: stretch;
    padding: 0 10px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
        -ms-flex-direction: column;
            flex-direction: column;
    -ms-flex-wrap: nowrap;
        flex-wrap: nowrap;
}

.textBlock {
    -webkit-box-flex: 1;
        -ms-flex: 1 1 auto;
            flex: 1 1 auto;
    -ms-flex-item-align: stretch;
        -ms-grid-row-align: stretch;
        align-self: stretch;
}

.buttonBar {
    -webkit-box-flex: 0;
        -ms-flex: 0 0 auto;
            flex: 0 0 auto;
}

.onLeft {
    text-align: right;
}

.onRight {
    text-align:  left;
}

.image {
    -webkit-box-flex: 0;
        -ms-flex: 0 0 auto;
            flex: 0 0 auto;
    background-color: grey;
    width: 150px;
    height: 200px;
}
<div class="flex_row">
    <div class="article onLeft flex_row">
        <div class="content">
            <div class="textBlock">
                <h1>Dolor</h1>
                <p><b>Dotum dolor</b></p>
                <p>
                  Lorem ipsum dolor sit amet, con tatibus consequatur
                </p>
            </div>
            <div class="buttonBar">
                <button>myButton on left</button>
            </div>
        </div>
        <div class="image"></div>
    </div>

    <div class="article onRight flex_row">
        <div class="image"></div>
        <div class="content">
            <div class="textBlock">
                <h1>Ipsum</h1>
                <p><b>Ipsum dolor</b></p>
                <p>
                  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis quidem voluptatibus consequatur
                </p>
            </div>
            <div class="buttonBar">
                <button>myButton on right</button>
            </div>
        </div>
    </div>
</div>

这是我的香草css:

.flex_row {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-content: stretch;
    align-items: flex-start;
}

.article {
    box-sizing: border-box;
    flex: 1 1 50%;
    align-self: stretch;
    padding: 10px;
}

.content {
    box-sizing: border-box;
    flex: 1 1 auto;
    align-self: stretch;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
}

.textBlock {
    flex: 1 1 auto;
    align-self: stretch;
}

.buttonBar {
    flex: 0 0 auto;
}

.onLeft {
    text-align: right;
}

.onRight {
    text-align:  left;
}

.image {
    flex: 0 0 auto;
    background-color: grey;
    width: 150px;
    height: 200px;
}

答案 1 :(得分:0)

<div class="col-md-6 col-sm-6 col-xs-12">
                    <div class="col-md-8">
                        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis quidem voluptatibus consequatur</p>
                        <button class="btn btn-success pull-right">Demo Button</button>
                    </div>
                    <div class="col-md-4">
                        <img img src="http://placehold.it/150x150" alt="Demo Imag1">
                    </div>
                </div>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <div class="col-md-4">
                        <img img src="http://placehold.it/150x150" alt="Demo Imag1">
                    </div>
                    <div class="col-md-8">
                        <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis quidem voluptatibus consequatur</p>
                        <button class="btn btn-success pull-left">Demo Button</button>
                    </div>
                </div>