HTML element display in horizontal line

后端 未结 4 1252
夕颜
夕颜 2021-02-19 07:08

I have two HTML elements inside a div. I want to display them in a row or a horizontal line. Let\'s say I have two images with the code shown below. How would I make it so there

相关标签:
4条回答
  • 2021-02-19 07:23

    Option 1

    img {
     display:inline;
    }
    

    Option 2

    img {
     display:block;
     float:left;
    }
    

    Updated to reflect current browser capabilities

    Option 3

    img {
     display:inline-block;
    }
    

    However, this will only work if there is enough horizontal space for the images in question.

    0 讨论(0)
  • 2021-02-19 07:25

    The hack is to set position: relative; on the parent div and

    position: absolute; 
    top: 0px; 
    left: {left image's computed width}px; 
    

    on the second one. Other wise you simple increase the div size.

    0 讨论(0)
  • 2021-02-19 07:26

    You can do this with CSS (position attribute) or with a table. It will not have a line break by default unless the pictures are too wide to fit on one line. In that case, it is questionable design to force them to be on the same line.

    0 讨论(0)
  • 2021-02-19 07:29

    The image elements are inline elements, so they display horizontally, unless you changed the "display" CSS rule. I think you don't have enough space for them to fit horizontally.

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