Centering an image that is in an anchor tag

前端 未结 5 1820
迷失自我
迷失自我 2021-01-23 17:50

I have an image in an anchor tag, and I need to center it.

I have managed to do so using this technique that I just came across messing about in the DOM inspector: http:

相关标签:
5条回答
  • 2021-01-23 18:26

    It will work out for you..

    .center
    {
    width: 100%;
    display:block
    text-align: center;
    }
    
    0 讨论(0)
  • 2021-01-23 18:30

    You can use text-align: center; on the #container to center elements within it. Example here: http://jsfiddle.net/m6e3m/3/

    0 讨论(0)
  • 2021-01-23 18:30

    Demo Fiddle

    Try:

    #container{
        width: 600px;
        height:600px;
        background: red;
        display: table-cell; /* <-- allows use of vertical align */
        text-align:center; /* <-- horizontal centering */
        vertical-align:middle; /* <-- vertical centering */
    }
    

    Use the above and you wont need any more CSS for the img

    0 讨论(0)
  • 2021-01-23 18:36

    use -ms-flexbox supported by all browser. DEMO

    #container{
        width: 600px;
        height:600px;
        background: red;
    }
    
    .centre{ 
    height: 100%;
        width:100%;
    
    /* Internet Explorer 10 */
    display:-ms-flexbox;
    -ms-flex-pack:center;
    -ms-flex-align:center;
    
    /* Firefox */
    display:-moz-box;
    -moz-box-pack:center;
    -moz-box-align:center;
    
    /* Safari, Opera, and Chrome */
    display:-webkit-box;
    -webkit-box-pack:center;
    -webkit-box-align:center;
    
    /* W3C */
    display:box;
    box-pack:center;
    box-align:center; 
    }
    
    0 讨论(0)
  • 2021-01-23 18:38

    you can add to container text-align: center and vertical-align: middle;

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