Vertical align an image and a multiline text

前端 未结 4 993
天命终不由人
天命终不由人 2020-12-09 02:26

I´m trying to align an image and a text vertically:

+-------------------------+ -- Viewport
|         Text text text  | 
| +-----+ text text text  | 
| |IMAGE| te         


        
4条回答
  •  暖寄归人
    2020-12-09 03:06

    You said you can't use margin/padding answers because of not knowing size. However, why not just use percentage to put the image halfway down, then split everything up into divs?

    Whatever

    And then in your CSS, do this:

    #viewport {
      width:800px;
      height:500px;
      border:1px solid #FFF;
    }     
    
    #image {
      width: 400px;
      float:left;
      height:100%;
      text-align: center;
    }
    
    img {
      margin-top:50%;
    }
    
    #text {
      width:300px;
      float:left;
    }
    

    Obviously all the widths and heights can be percentages or however you wish to handle them. However, this should render how you want it to. Hope I am understanding your question correctly.

提交回复
热议问题