简体   繁体   English

HTML / CSS图像中心对齐

[英]HTML/CSS Image center alignment

I have made a website where the homepage looks like the this : 我创建了一个网站,主页看起来像这样:

在此输入图像描述

I want to move the ficstore logo in the middle and split the bar into two halves and put one on either side , like this : 我想在中间移动ficstore徽标并将条形分成两半并在两侧放置一个,如下所示: 在此输入图像描述

I've split my bar image into two different parts for each side and tried to put the images in different columns. 我将条形图像分成两个不同的部分,并尝试将图像放在不同的列中。 But it just doesn't seem to work. 但它似乎没有用。

This is the snippet for the current code : 这是当前代码的片段:

<div class="container">
    <div class="row">
        <div class="col-xs-8">
                        <h2 style="font-family:helvetica;"><span>Home Page</span></h2>

        </div>
        <div class="col-xs-4">
            <img src="http://lorempixel.com/400/200/" class="img-responsive right" style="width:400px; z-index:1;" />
        </div>
        <img src="http://lorempixel.com/400/200/" class="img-responsive right" style="position: absolute; margin-top: 135px; z-index: -2;" />
    </div>
<hr class="style18" />

Can someone help? 有人可以帮忙吗?

I've tried the following code as well : 我也尝试过以下代码:

<div class="container">
    <div class="row">
        <div class="col-xs-8">
            <h2 style="font-family:helvetica;"><span>Book Info</span></h2>
        </div>
        <div class="flex-row">
            <div>
                <img src="http://lorempixel.com/400/200/" class="img-responsive right" style="width:400px; z-index:1;" />
            </div>
            <div>
                <img src="http://lorempixel.com/400/100/" class="img-responsive right" style="position: absolute; margin-top: 135px; z-index: -2;" />
            </div>
            <div>
                <img src="http://lorempixel.com/400/100/" class="img-responsive right" style="position: absolute; margin-top: 135px; z-index: -2;" />
            </div>
        </div>
    </div>
<hr class="style18" />

Css : Css:

.flex-row {
  display: flex;
  align-items: center;
  justify-content: center;
}

This is a great time to use flex: 这是使用flex的好时机:

HTML: HTML:

<div class='flex-row'>
  <div><img src="left.png"></div>
  <div><img src="center.png"></div>
  <div><img src="right.png"></div>
</div>

CSS: CSS:

.flex-row {
  display: flex;
  align-items: center;
  justify-content: center;
}

This is one way to do it. 这是一种方法。 I would encourage you to ditch whatever framework you are using. 我鼓励你抛弃你正在使用的任何框架。 col-x-whatever is bad news bears. col-x-whatever是坏消息熊。

Here's a fiddle too - with an inline-block way. 这里也是一个小提琴 - 采用内联块方式。

https://jsfiddle.net/sheriffderek/fcwyg0zb/ https://jsfiddle.net/sheriffderek/fcwyg0zb/

inline-block 内联块

.images { 
  text-align: center;
}

.images .image-w {
  display: inline-block;
  vertical-align: middle;
}


flexbox Flexbox的

 .image-w img { display: block; width: 100%; height: auto; } .one { max-width: 200px; } .two { max-width: 400px; margin: 0 1rem; } .three { max-width: 200px; } .images { display: flex; flex-direction: row; align-items: center; justify-content: center; } 
 <section class='images'> <div class='image-w one'> <img src='https://placehold.it/300x150' alt='left'> </div> <div class='image-w two'> <img src='https://placehold.it/600x300' alt='center'> </div> <div class='image-w three'> <img src='https://placehold.it/300x150' alt='right'> </div> </section> 

I suggest you have to have 3 images. 我建议你必须有3张图片。 The bar should divided in two. 酒吧应分为两个。 Put the Fictore in the middle then add display:block. 将Fictore放在中间然后添加display:block。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM