Display two images side by side on an HTML Page

后端 未结 7 1828
渐次进展
渐次进展 2021-01-06 07:09

I am trying to place two images of the same size side-by-side. If I use a table then I am able to display both images side-by-side. But in my CSS Stylesheet I a

相关标签:
7条回答
  • 2021-01-06 07:38

    Use float:left; you say that you are finding a little left margin so you can try this

    .left{
        float:left;
        margin:0;
        padding:0;
    }
    

    this may be cause of margin or padding. or you should use body tag like

    body{margin:0;
    padding:0;
    }
    

    then you have no need for write margin:0; padding:0;.

    0 讨论(0)
  • 2021-01-06 07:40

    You can do like:

    <style type="text/css">
      .left{float:left;}
    </style>
    
    <img class="left" src="path here" />
    <img class="left" src="path here" />
    
    0 讨论(0)
  • 2021-01-06 07:47

    Just do this:

    <img src="path/image.ext" /><img src="path/image.ext" />
    

    It will display the images inline by default. If not, add:

    <style>img {display: inline;}</style>
    
    0 讨论(0)
  • 2021-01-06 07:50

    What you basically do is your put the two image source tags right next to each other in one line of code. Like this.

    <img src="hi"><img src="hey">
    
    0 讨论(0)
  • 2021-01-06 07:51
    1. Have you tried float:left ?
    2. Attach a different class to every table and then in your css:
    .table_one {
        background-color: #CC0000;
    }
    
    .table_two {
        background-color: #00CC00;
    }
    
    0 讨论(0)
  • 2021-01-06 07:51

    Generally, table is the only way that will work in all situations. Depending on where the two images are in you HTML, there may be a better way, but that depends. Is there an element that contains the two images already? What are that element's layout properties.

    CSS stylesheet that changes properties of a table is a bad bad thing. One should only set properties of a class of tables (using table.className) or a particular table (using table#id). If you cannot change the stylesheet, you have to undo the damage it does to your particular table.

    To do that, find out what properties the stylesheet changed on you, and change them back by issueing a CSS rule for your table (rule with table.className or table#id will override a more general rule) (preferrable) or by hard-coding the property into HTML using inline styles (fine for a quick fix if you only have one such pair).

    0 讨论(0)
提交回复
热议问题