代码之家  ›  专栏  ›  技术社区  ›  Chetan

使用标记,如何将图像及其标题居中?

  •  38
  • Chetan  · 技术社区  · 14 年前

    Hello there!
    
          <image>
          This is an image
    
    Hi!
    

    图像和文本 This is an image

    编辑:请注意,我希望将图像和文本水平居中放置在页面上。

    6 回复  |  直到 14 年前
        1
  •  8
  •   MatTheCat    14 年前

    您需要一个具有定义高度的块容器,行高和垂直对齐图像的值相同:middle; 它应该有用。

    Hello there !
    
    <div id="container">
        <img />
        This is an image
    </div>
    
    Hi !
    
    #container {
        height:100px;
        line-height:100px;
    }
    
    #container img {
        vertical-align:middle;
        max-height:100%;
    }
    
        2
  •  36
  •   Chetan    14 年前

    所以我的代码如下:

    Hello there!
    
          <center><img src="" ...></center>
          <center>This is an image</center>
    
    Hi!
    
        3
  •  22
  •   tremor    5 年前

    我想我有一个简单的解决方案,你可以定义CSS。它也不需要任何扩展或HTML!首先你的降价图像代码:

    ![my image](/img/myImage.jpg#center)  
    

    注意添加的url散列中心。

    现在在CSS中添加此规则:

    img[src*='#center'] { 
        display: block;
        margin: auto;
    }
    

    要查看实际效果,请查看我的JSFiddle,它使用SnarkDown来解析文本区域中的MarkDown- https://jsfiddle.net/tremor/6s30e8vr/

        4
  •  20
  •   Zombo tliff    12 年前

    kramdown

    Hello there!
    
    {:.center}
    ![cardinal](/img/2012/cardinal.jpg)  
    This is an image
    
    Hi!
    
    .center {
      text-align: center;
    }
    
        5
  •  18
  •   Ben Collins    10 年前

    Mou (也许还有杰基尔)这很简单。

    -> This is centered Text <-
    

    考虑到这一点,您可以将其应用于img语法。

    ->![alt text](/link/to/img)<-
    

    Daring Fireball .

        6
  •  7
  •   raisercostin    8 年前

    {: style="text-align:center"}
    That is, while there is value in the items on
    the right, we value the items on the left more.
    

    或者使用@的回复(史蒂文·彭妮)

    {:.mycenter}
    That is, while there is value in the items on
    the right, we value the items on the left more.
    
    <style>
    .mycenter {
        text-align:center;
    }
    </style>
    
        7
  •  0
  •   Aliaksandr Sushkevich    5 年前

    我很惊讶没有人这样说:

    Hello there!
    
    <p align="center">
    
      <img src="">
      This is an image
    
    </p>
    
    Hi!