How to center an image?
来源:互联网 发布:js鼠标点击空白处事件 编辑:程序博客网 时间:2024/06/05 20:32
I find three ways to center an image in a div: In my opinion, the third method is graceful and accurate, which i borrow from my last example.<style type="text/css"> .container1 { border: solid 1px #666; width: 100px; height: 100px; } .container1 img { margin: 42px 0px 0px 42px; /* (100-16)/2 = 42 */ } .container3 { border: solid 1px #666; width: 100px; height: 100px; position: relative; } .container3 img { position: absolute; top: 42px; left: 42px; /* (100-16)/2 = 42 */ } .container4 { border: solid 1px #666; width: 100px; height: 100px; position: relative; } .container4 img { position: absolute; top: 50%; margin-top: -8px; /* 16/2 = 8 */ left: 50%; margin-left: -8px; } </style> <div class="container1"> <img src="mini/clock.gif" mce_src="mini/clock.gif" alt="" /> </div> <br /> <div class="container3"> <img src="mini/clock.gif" mce_src="mini/clock.gif" alt="" /> </div> <br /> <div class="container4"> <img src="mini/clock.gif" mce_src="mini/clock.gif" alt="" /> </div>
- How to center an image?
- How to load an url image
- How To Upload An Image into BSP
- How to Get an Android Device Image?
- How to mount an image file.
- How to store an image file to SQliteDB in android
- How to store an image file to SQliteDB in android
- How to Split an Image into Chunks - Java ImageIO
- How to rotate an image with CSS under different browser
- How to mount an ISO Image with AIX 6.1 TL4
- How to access pixel data of an image
- How to burn an ISO-image into a DVD
- i.MX Yocto Project: How do I add an existing package to an image?
- Drawing to an Image
- How to convert an input image from one color space to another space
- CSS - How to align a <div> center?
- How to center absolute element in div?
- How to scroll an image, if it does not fit in the display
- jStore - Persistent storage solution in client-side
- 成功必备的要素
- Prototype/Constructor that i have known
- Use IE userdata behavior as a client-side data storage
- Difference between input and button markup
- How to center an image?
- JavaScript tips and tricks - 1
- Config FCKeditor_2.6.4 with FCKeditor.Net_2.6.3
- Convert word or html to wiki syntax
- JavaScript tips and tricks - 2
- JavaScript tips and tricks - 3
- JavaScript tips and tricks - 4
- JavaScript tips and tricks - 5
- Learning Rhino - 1