How can I center align text within div horizontally?

后端 未结 4 652
Happy的楠姐
Happy的楠姐 2021-01-24 13:08

This may be the stupid question,but I can\'t figure it out how to get this.

edit: I just want to center only text horizontally not the image and the image must be remain

4条回答
  •  梦谈多话
    2021-01-24 13:44

    Building on Afzaal Ahmad Zeeshan's answer...

    Put the text between 2 equal images. Set text-align:center on the containing div. This centers the image-text-image as a group.

    Then hide the second image.

    HTML:

    This works now.

    CSS:

    div {
        text-align: center;
    }
    
    img {
        width:30px;
        height:60px;
    }
    
    .cannot-see-me {
        visibility: hidden;
    }
    

    This works because visibility:hidden makes an element invisible, but it still takes up space on the page. So use that here instead of display:none.

提交回复
热议问题