本文详情:http://www.zymseo.com/276.html
图片上下居中的问题常用的几种方法:
图片已知大小和未知大小,自行理解

  1. .main{
  2. width: 400px;height: 400px;
  3. border: solid 1px red;
  4. text-align: center;
  5. }
  6. <div class="main"><img src="1.png"></div>

下图为其实状态和结束状态:

方法一:diaplay:table-cell 单元表格的形式

  1. display:table-cell;
  2. vertical-align:middle;

方法二:flex;align-items: center;justify-content: center 弹性盒子布局

  1. display:flex;
  2. align-items:center;
  3. justify-content:center;

方法三:position加margin

  1. position: relative;
  2. margin: auto;
  3. position: absolute;
  4. left: 0;
  5. right: 0;
  6. top: 0;
  7. bottom: 0;

方法四:position加 transform

  1. position: relative;
  2. position: absolute;
  3. top:50%;
  4. left:50%;
  5. transform:translate(-50%,-50%);

方法五:纯position

  1. position:relative;
  2. position: absolute;
  3. left: 50%;
  4. top: 50%;
  5. margin-left:-50px;
  6. margin-top:-50px;

html/css系列-图片上下居中的更多相关文章

  1. css div图片上下左右居中

    <style type="text/css"> div{border:1px solid #ccc;height:500pc;width:500px;text-alig ...

  2. 只用CSS实现容器内图片上下左右居中

    一直以来,大家都知道,DIV容器内设置 text-align:center 即可让图片居中,但是DIV内默认的图片是上对齐,不会上下居中,如果想要实现这样的效果,JS判断是比较麻烦的,因为DIV容器内 ...

  3. <转载>使CSS文字图片div元素居中方法之水平居中的几个方法

    文字居中,文字垂直居中水平居中,图片居中,图片水平居中垂直居中,块元素垂直居中?当我们在做前端开发是时候关于css居中的问题是很常见的.情 况有很多种,不同的情况又有不同的解决方式.水平居中的方式解决 ...

  4. div css 伪类 不固定图片大小 居中, css div 实现三角形

    div css 伪类 不固定图片大小 居中 <style> .pic_box{width:300px; height:300px; background-color:#beceeb; fo ...

  5. css设置图片居中、居左、居右

      CreateTime--2017年12月8日14:25:09 Author:Marydon css设置图片居中.居左.居右 图片一般默认是居左显示的,如何更改它的水平位置呢? <div st ...

  6. css图片居中,通过纯css实现图片居中的多种实现方法

    在网页布局中,图文排版是我们常用的,那么经常会遇到如何让图片居中显示呢,这篇文章将总结常用css实现图片居中的方法总结: html结构: <div class="demo" ...

  7. css全局定位内容图片自动居中

    最近在做一个资讯站点时候,因为采集的数据,图片不居中,导致界面很不美观,所以需要全局定义下图片输出时候进行居中. .content img { max-width:800px;_width:expre ...

  8. html+css实现图片或元素的垂直、水平同时居中的多种方法

    实现元素或图片的上下.左右居中的三种方法 效果图如下: 方法一:利用vertical-align属性实现图片上下居中 先设置父元素样式text-align: center,实现图片左右居中,给图片添加 ...

  9. 通过纯css实现图片居中的多种实现方式

    html结构: <div class="demo" style="width: 800px;height: 600px; border:1px solid #ddd ...

随机推荐

  1. sklearn包源码分析(二)——ensemble(未完成)

    网络资源 sklearn包tree模型importance解析

  2. [LC] 250. Count Univalue Subtrees

    Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of ...

  3. [LC] 46. Permutations

    Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...

  4. MySQL5.7安装教程(RPM)

    博主本人平和谦逊,热爱学习,读者阅读过程中发现错误的地方,请帮忙指出,感激不尽 前言: 对应服务器信息: 192.168.247.53 一.MySQL安装(RPM) 1.系统环境设置: 1.1清空系统 ...

  5. prisoners-of-war|

    The Nazi kept those ________ in their concentration camps.  A. prisoner-of-wars  B. prisoner-of-war ...

  6. LeetCode Day 5

    LeetCode0005 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab& ...

  7. Nginx笔记总结八:ngx_http_core_module模块中的变量

    $arg_patameter HTTP请求中某个参数的值,如/index.php?site=www.ttlsa.com,可以用$arg_site取得www.ttlsa.com这个值 $args HTT ...

  8. 学习和使用 Styled Layer Descriptor SLD样式文件

    1. SLD 文件大致作用,可以浏览下示意图: 点要素的符号化:http://docs.geoserver.org/stable/en/user/styling/sld-cookbook/points ...

  9. <JZOJ5937&luogu3944>斩杀计划&肮脏的牧师

    第一次写桶排相关题.... #include<cstdio> #include<iostream> #define rint register int template < ...

  10. python socketserver 实现 ftp功能

    需求: 用户加密认证 允许同时多用户登录 每个用户有自己的家目录 ,且只能访问自己的家目录 对用户进行磁盘配额,每个用户的可用空间不同 允许用户在ftp server上随意切换目录 允许用户查看当前目 ...