简体   繁体   English

删除两个图像之间的空间并居中的代码

[英]Code for removing space between 2 images and centering

I am having difficulty with code for two images that I want to be centered and to have no space in-between. 我想为两个要居中且中间没有空格的图像编写代码时遇到困难。

I am inexperienced and don't really know how to merge both codes into 1.. 我没有经验,也不知道如何将两个代码合并为1.。

Code I am using for removing space in-between images: 我用于删除图像之间空间的代码:

<div class="row">
<p style="line-height: 0.0em;"><img src="photo1 "/><img src=”photo2” /></p>
</div>

Code I am using to center an image: 我用来使图像居中的代码:

<div id="wrapper" style="width:100%; text-align:center">
<img id="yourimage"/>
</div>

Any help would be appreciated. 任何帮助,将不胜感激。

You can use table as well based on your need, 您也可以根据需要使用表格,

<table>
  <tr>
    <td>
         Image 1
    </td>
    <td>
          Image 2
    </td>
  </tr>
</table>

For better control to each DIV, you can use this approach 为了更好地控制每个DIV,可以使用此方法

HTML 的HTML

<div class="container">
    <div class="div1">Div 1</div>
    <div class="div2">Div 2</div>
</div>

CSS 的CSS

div.container {
    background-color: #FF0000;
    margin: auto;   
    width: 304px;
}

div.div1 {
    border: 1px solid #000;
    float: left;
    width: 150px;
}

div.div2 {
    border: 1px solid red;
    float: left;
    width: 150px;
}

Jsfiddle: http://jsfiddle.net/azXMN/ Jsfiddle: http : //jsfiddle.net/azXMN/

Try this : 尝试这个 :

<div id="wrapper" style="width:100%; text-align:center" class="row">
<p style="line-height: 0.0em;"><img src="photo1 "/><img src=”photo2” /></p>
</div>

or you can place one <div> inside another <div> and center the inner <div> with the images. 或者您可以将一个<div>放置在另一个<div> ,并将内部<div>与图像居中。

[PS:Avoid inline CSS as far as possible.Instead put the css in header or external css file] [PS:尽可能避免内联CSS。而应将CSS放在标头或外部CSS文件中]

this is what you want: 这就是你想要的:

<div class="row" style="text-align: center; font-size: 0;>
    <p style="line-height: 0.0em;">
        <img src="http://placekitten.com/150/100">
        <img src="http://placekitten.com/150/100">
    </p>
</div>

example: http://jsfiddle.net/X7cfw/ 示例: http//jsfiddle.net/X7cfw/

Again, avoid inline styling when at all possible 同样,尽可能避免使用内联样式

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

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