我尝试将图像居中在这个绝对位置div中我尝试边距:0自动但它无法工作。我做错了什么?
<div class="support"> <img src="../image/contact.jpg" /></div>
.support {
position:absolute;
left:30px;
top:50px;
width:300px;
height:450px;
}
.support img {
width:243px;
height:350px;
margin:0 auto;
}
答案 0 :(得分:2)
添加display:block to image:
.support img {
width:243px;
height:350px;
margin:0 auto;
display: block; /* add this */
}
答案 1 :(得分:1)
嘿,请尝试在图像父div中使用此文本对齐中心
.support {
position:absolute;
left:30px;
top:50px;
width:300px;
height:450px;
text-align: center;
}
.support img {
width:243px;
height:350px;
margin:0 auto;
}
<div class="support"> <img src="../image/contact.jpg" /></div>
答案 2 :(得分:1)
你也可以像这样使用display: block;
:
.support {
left:30px;
top:50px;
width:300px;
height:450px;
}
.support img {
width:100px;
height:100px;
margin:0 auto;
display: block;
}
<div class="support"> <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAFoAtAMBIgACEQEDEQH/xAAbAAACAgMBAAAAAAAAAAAAAAADBAIFAAEGB//EAD4QAAIBAwIDBQQGCQMFAAAAAAECAwAEERIhBTFBEyJRYXEGMoGRFEJSobHBBxUjM1OSotHwg+HxFiQ0Q2L/xAAaAQADAQEBAQAAAAAAAAAAAAABAgMABAUG/8QAKREAAgIBBAIBAgcBAAAAAAAAAAECEQMSEyFRBDFBBWEiMkJScYGRBv/aAAwDAQACEQMRAD8A9He3PhWkhIFXjWeeVQ+gt4VCmWtFMYj4UJ4vKrw2DnpQm4fJ4UysFoo2i9RQXh/zFXx4fJ/DoL8PfrGflVFIVnPvEw5AGh4x7ykeYq+fh5+z/S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YPMyYYtRf8DLcRZ9byKTJ0IGRS5dpowxLMR7xJzgUoLp9JwQBjGF2qUbFGB1aVbZt966JRXC6ObU5NuT5ZqQgHY79KLajE8TNyO9C7JZ5W0yYx9rarCztwIz2oOpT3cDzopK6AyMyhlVgBqAwaVfUhBY03GQx0A7kbdMGtFcHvrkeDHlTyhYLEZMhgW5c/WsaZg7YJ25Z9auTb2xjyH0jOdJYbUo9pBI+iN2dzzCr8980rhS5GUkyvR2blj400tkxj7WZ9G+AoGc8v71t7a3tZR20yt10KD99CuLgMx0tqQjAJ50l2+Ak1/erHAhdzhRgbmmyeyt9Nwco25Crq0H1pfhttIR9JMmhV2GfredGnjJj/aJKWO+5OMActvSlcuaTNQjIkOo6Wdx44xWURVQfvFyT67fKt0+oFG45squTtitNJg70qh7oqT8hQoUKZt8Y2rRloFY1MkAMZMcq0r6uZPwoNEi50aFY3G4EDR97flnp8qVZQDg5PnVhZqrGPUoOXwcim+IbSyoNkEZwvQd0VN5adGRz0gPTPzoOrxpxuR9KXIGobdasmGzUYGd9/Km1gkkHdiOMeH96NAAqZUAHHMVgJY945586dY0/YG6IrZsPfkCde7lj91OQ5gVuwDN2i7u2/3cqnaqpiOVBw3UUtcyOWjUu2krkjPnVViSVi6+Q57A7HKnxU1CVTISyhSMYwDSzbMcbb0VNgcf5zpKop7Ik6TjkRTEMiK80MRJbQTr28NwP96negBmwBypDhH/AJJ9PzFRy/lGiMNbRjM10zQR57oxl3NbitbaVQbWNpZMgZMmACR1J51rixOXGdhIcDw71NcK7qHTtp7QjHQ451zuTUbGF7wXyXMdvE8OoppK6+fPckgUjeTXTXJaTCsvd1RtlfTPKgcRZtb948/GsnJW9dFOFyO6OVWhGkmBskty6jAZfjvWUoedZVNCCf/Z" /></div>
答案 3 :(得分:0)
<style>
.support {
left:30px;
top:50px;
width:300px;
height:450px;
margin:0 auto;
}
.support img {
width:243px;
height:350px;
margin:0 auto;
}
</style>
<div class="support"> <img src="../image/contact.jpg" /></div>
试试这个。