简体   繁体   English

两列文字,中间居中

[英]Two column text with image in middle middle

I have looked around a lot but cannot find a tutorial or suggestion for how to place an image in both the vertical and horizontal center of a page of two-column text. 我到处走走了很多,但找不到关于如何在两列文字页面的垂直和水平中心放置图像的教程或建议。 I've seen explanations for straddling an image across two columns, but aligned at the top of the text. 我已经看到了将图像跨两列但在文本顶部对齐的说明。 I want to align an image in the middle middle.! 我想在中间中间对齐图像。

Is this even possible? 这有可能吗? I would prefer to do it in CSS, but will consider anything that works, (especially if it comes with some instruction.) Thanks for any help you can offer (even if it's to tell me to give up.) (c; 我更愿意在CSS中执行此操作,但会考虑所有可行的方法(尤其是附带一些说明。)感谢您可以提供的任何帮助(即使是告诉我放弃)。

I've found the technique described here and shown below to be very effective: 我发现这里描述的技术非常有效:

HTML HTML

<div class="container">
  <div class="inner">
    <img src="//placehold.it/200x200">
  </div>
</div>

CSS CSS

.container {
  text-align: center;
}

.container:before {
  content: '';
  display: inline-block;
  height: 100%; 
  vertical-align: middle;
 }

.inner {
  display: inline-block;
  vertical-align: middle;
 }

I don't know if this is what you looking for. 我不知道这是您要找的东西。

1) Create two div (as column) and put image at the middle(Image will overlapped the both column.) 1)创建两个div(作为列),然后将图像放在中间(图像将与两列重叠。)

DEMO DEMO

 img
 {
 background: red;
 height: 300px;
 width:400px;
 margin: auto;
 position: absolute;
 top: 0;
 right: 0;
 left: 0;
 bottom: 0;
 }

2) Create 2 div(as column) with opacity:0.5 and put image at the middle (The image will acts like background since z-index is added) 2)创建2个div(作为列),不透明度为0.5,并将图像放在中间(由于添加了z-index,因此图像的作用类似于背景)

DEMO DEMO

img
{
z-index:-1;
}

Good Luck!! 祝好运!!

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

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