Proportional scaling, such as black/white scaling, and scaling
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
</Script>
<Style type = "text/css">
<! --
Body {
Margin-left: 0px;
Margin-top: 0px;
Margin-right: 0px;
Margin-bottom: 0px;
}
Img
{
Width: expression_r (this. width> 200 & this. width> this. height? 200: true );
Height: expression_r (this. height> 160? 200: true );
Max-width: 200px; max-height: 160px;
Min-width: 0px; min-height: 0px;
Position: static;
+ Position: relative;
Top:-50%; left:-50%;
Filter: Gray;
}
Div
{
Width: 500px;
Height: 360px;
Background: #000;
Overflow: hidden;
Position: relative;
Display: table-cell;
Text-align: center;
Vertical-align: middle;
}
P
{
Position: static;
+ Position: absolute;
Top: 50%;
Background-color: #0F0;
}
-->
</Style> <Body>
<Div> <p> <ahref = "#"> </a> </p> </div>
</Body>
</Html>
How to reduce the vertical and horizontal center ratio of images in a single box
The image must be displayed in a uniform size without being stretched and centered (for example, vertical and horizontal center in the div of 100*100 ). If some friends have learned some CSS tutorials, they will say that horizontal center is very simple, text-align: center, but vertical center is troublesome. vertical-align: middle may not be effective. The following is a detailed analysis: 1. The line-height method can be used without considering IE6.
Div {width: 100px; height: 100px; line-height: 100px; text-align: center; font-size: 0 ;}
Div img {max-height: 100px; max-width: 100px; vertical-align: middle ;}
This enables the image to be horizontally and vertically centered. Adding a font-size: 0 is to prevent the div under IE from being highly supported. 2. IE6 is invalid for the line-height scheme, and does not support max-width and max-height. Therefore, it is impossible to scale down the image by CSS or other proportions, but it can be implemented with scripts. Let's talk about the vertical center of IE. If the image is no larger than the outer frame, the writing-mode: tb-rl method can be used to attack the virus. This indicates that the text output mode is from top to bottom, from right to left.
Div span {_ height: 100%; _ writing-mode: tb-rl;} height: 100% is required. When the image width or height is larger than the size of the outer frame, we can scale down the image size by using the script and vertically center the image without using functions such as margin or padding scaleImage (img, maxWidth, maxHeight) {// maxWidth and maxHeight can be saved. Add these two parameters for vertical center when the image size is changed
Img. style. maxWidth = maxWidth | img. width;
Img. style. maxHeight = maxHeight | img. height;
// The hasLoadFunc parameter is used to limit that the image has only one vertical center adjustment method.
If (! Img. hasLoadFunc) {img. hasLoadFunc = true;
// If the image has been changed to SRC, scale down the image again.
Img. attachEvent ("onload", function () {var t = new Image ();
// Obtain the real size of the image without changing the image Style
T. onload = function () {// set the image width and height to automatic, because the image width and height have been set to a fixed value in the mode table.
Img. style. width = img. style. height = "auto ";
Var maxWidth = parseInt (img. style. maxWidth );
Var maxHeight = parseFloat (img. style. maxHeight );
If (this. width> parseInt (img. style. maxWidth) | this. height> maxHeight)
// If the image width/height ratio is greater than the width/height ratio of the outer frame (or the image is longer), the width is fixed and the height is automatic. Otherwise, the opposite is true.
If (this. width/this. height> maxWidth/maxHeight)
Img ...... remaining full text>
Pure css Image Auto proportional scaling and vertical center orientation can be used without JS
There is a way, but IE6 or other proportional scaling is invalid because the max-width attribute must be used.
Two Problems
Auto scaling can be achieved through max-width and max-height
Vertical center gives you an idea. Using vertical-align for two inline-block elements at the same time can produce unexpected results. IE7 can use zoom to simulate inline-block.
Write it by yourself, and you will understand