zoukankan      html  css  js  c++  java
  • How to center an image?

    I find three ways to center an image in a div:

    <style type="text/css">
            .container1
            {
                border: solid 1px #666;
                 100px;
                height: 100px;
            }
            .container1 img
            {
                margin: 42px 0px 0px 42px; /* (100-16)/2 = 42 */
            }
            .container3
            {
                border: solid 1px #666;
                 100px;
                height: 100px;
                position: relative;
            }
            .container3 img
            {
                position: absolute;
                top: 42px;
                left: 42px; /* (100-16)/2 = 42 */
            }
            .container4
            {
                border: solid 1px #666;
                 100px;
                height: 100px;
                position: relative;
            }
            .container4 img
            {
                position: absolute;
                top: 50%;
                margin-top: -8px; /* 16/2 = 8 */
                left: 50%;
                margin-left: -8px;
            }
        </style>
        <div class="container1">
            <img src="mini/clock.gif" mce_src="mini/clock.gif" alt="" />
        </div>
        <br />
        <div class="container3">
            <img src="mini/clock.gif" mce_src="mini/clock.gif" alt="" />
        </div>
        <br />
        <div class="container4">
            <img src="mini/clock.gif" mce_src="mini/clock.gif" alt="" />
        </div>

    In my opinion, the third method is graceful and accurate, which i borrow from my last example.

  • 相关阅读:
    四叶草社交平台——十天冲刺(7)
    四叶草社交平台——十天冲刺(6)
    多表查询
    单表 查询
    django模板的导入
    2019-3-1
    DJANGO 28
    路由
    Django项目的创建与介绍
    数据传输方式
  • 原文地址:https://www.cnblogs.com/sanshi/p/1454732.html
Copyright © 2011-2022 走看看