如何水平对齐裁剪元素?元素、水平

由网友(执着 Paranoid)分享简介:如何从两侧向中心,这也缩小到它的高度调整裁剪图像?或者只是中心裁剪图像? (见4,5 http://jsfiddle.net/iegik/ZzXru )| ////////// || ---------- | ---------------- ------------| | | / | | / | | ||按比例|...

如何从两侧向中心,这也缩小到它的高度调整裁剪图像?或者只是中心裁剪图像? (见4,5 http://jsfiddle.net/iegik/ZzXru )

  | ////////// |
 | ---------- | ---------------- ------------
 | | | / | | / | | |
 |按比例| | / |按比例| / | |空|
 |宽度| | / |高度| / | | DIV |
 | | | / | | / | | |
 | ---------- | ---------------- ------------
 | ////////// |
 

  --------------
| ////////////// |
| // ---------- // |
| / | | / |
| / |刚| / |
| / |裁剪| / |
| / | | / |
| // ---------- // |
| ////////////// |
 --------------
 

解决方案 WORD图片页面水平对齐与垂直对齐怎么设置

如果您还没有支持IE8或降低你可以这样来做。更改,而不是使用图像元素的样式属性。

 图{
     显示:块;
     背景重复:不重复;
     背景位置:中心中心;
     背景尺寸:盖;
}

<人物风格=背景图像:网址(http://placekitten.com/250/300)>< /图>
 

这可让图像居中,填充容器,你将不必担心横向和纵向。该图像的宽高比将是preserved。如果你想看到整个图像,但在一侧或其它缝隙,使用背景大小:含有

How to align cropped image from both sides to the center, which also is scaled to its height? Or just center cropped image? (see 4, 5 in http://jsfiddle.net/iegik/ZzXru )

 |//////////|
 |----------|   ----------------   ------------
 |          |   |/|          |/|   |          |
 |scaled by |   |/|scaled by |/|   |  empty   |
 |  width   |   |/|  height  |/|   |   div    |
 |          |   |/|          |/|   |          |
 |----------|   ----------------   ------------
 |//////////|

or

 -------------- 
|//////////////|
|//----------//| 
|/|          |/|
|/|   just   |/|
|/| cropped  |/|
|/|          |/|
|//----------//| 
|//////////////|
 --------------

解决方案

If you don't have to support IE8 or lower you could do it this way. Change the style attribute instead of using image elements.

figure {
     display: block;
     background-repeat: no-repeat;
     background-position: center center;
     background-size: cover;
}

<figure style="background-image:url(http://placekitten.com/250/300)"></figure>

This lets the image be centered, fill the container, and you won't have to worry about landscape vs. portrait. The image's aspect ratio will be preserved. If you want to see the whole image but with gaps on one side or the other, use "background-size: contain".

阅读全文

相关推荐

最新文章