热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

以图像为中心,以图像为中心。-centeringresponsivedivswithimagesinside

Iwouldliketocenterthefollowingjsfiddletobecenteredverticallyatallltimes,responsivede

I would like to center the following jsfiddle to be centered vertically at alll times, responsive design makes it hard for me to guess where to get a value from because all tutorials on StackOverflow have been saying "The div containing the content must have a width and height." I have made a picture illustration on how it is now(bad) and how i would want it to be (good)

我想把下面的jsfiddle垂直居中到alll时间,响应性设计使我很难猜到从哪里获得值,因为StackOverflow上的所有教程都说过“包含内容的div必须有宽度和高度”。我已经做了一个图片说明它现在是如何(坏)以及我希望它如何(好)

telefoon

mail
telefoon
mail

CSS

CSS

.wrapper {
    height: 80vh;
    margin: 0 auto;
    width: 90%;
}
.rowOne, .rowTwo {
    width: 50%;
    height: auto;
    float: left;
}
.Absolute-Center.is-Image {
  height: auto;
}

.Absolute-Center.is-Image img {
  width: 50%;
  height: auto;
}

6 个解决方案

#1


1  

Give following css will do a trick:

给予以下css将做一个小技巧:

.rowOne > div {
    text-align: center;
}


.rowTwo > div {
    text-align: center;
}

Updated Fiddle

更新的小提琴

#2


1  

First you should add extra div to your markup and put rowOne and rowTwo in the extra div, named middle:

首先,您应该在标记中添加额外的div,并将rowOne和rowTwo放在额外的div中,命名为middle:

Markup

标记

Then you should add some CSS:

然后你应该添加一些CSS:

CSS

CSS

.wrapper{
    display: table;
    position: absolute;
    height: 100%;
    width: 100%;
}
.wrapper .middle {
    display: table-cell;
    vertical-align: middle;
}
.wrapper div{ text-align:center }
.wrapper div a{ display: inline-block }

#3


1  

Please check code.. Please in HTML wrap with div class .centered and in css position:absolute and transform suing css3 .. Its pretty easy and cool.

请检查代码. .请在HTML包装与div类。居中和css位置:绝对和转换起诉css3。很简单,很酷。

https://jsfiddle.net/34o9vcba/19/

https://jsfiddle.net/34o9vcba/19/

.wrapper {
    height: 100vh;
    margin: 0 auto;
    position: relative;
    width: 100%;
}
.rowOne, .rowTwo {
    width: 50%;
    height: auto;
    float: left;
}
.Absolute-Center.is-Image {
  height: auto;
}

.centered {
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
  text-align: center;
}

.Absolute-Center.is-Image img {
  width: 50%;
  height: auto;
}
telefoon
mail
telefoon
mail

#4


0  

Ok, try this.

好吧,试试这个。

html, body {
height: 100%;
}

body {
margin: 0;
}

.wrapper {
height: 100%;
width: 100%;
margin: 0 auto;
text-align: center;
}

.centered {
position: relative;
overflow: hidden;
top: 50%;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
}

#5


0  

I worked it out!

我出来工作!

telefoon
mail
telefoon
mail
.telefoonButton, .mailButton, .infoButton, .contactButton { float: left; } .wrapper{ display: table; position: absolute; height: 100%; width: 100%; } .wrapper .middle { display: table-cell; vertical-align: middle; } .wrapper div{ text-align:center } .wrapper div a{ display: inline-block } .rowOne, .rowTwo { width: 50%; height: auto; float: left; } .Absolute-Center.is-Image { height: auto; } .Absolute-Center.is-Image img { width: 50%; height: auto; }

#6


0  

Change your css code like below:

更改css代码如下所示:

.Absolute-Center.is-Image {
    display: block;
    margin: 0px auto;
  }

推荐阅读
author-avatar
好学的程序员
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有