中心水平溢出图像

时间:2015-10-08 15:33:35

标签: html css image center

我需要将private static String ReplaceLfWithBr(String source) { // text - combination of words and line breaks // should not be preceded by <tag> or followed by <\tag> final String regex = "((?!<.+>)[\\w(\\r?\\n)]+(?!<\\s*/.+>))"; Pattern patern = Pattern.compile(regex, Pattern.MULTILINE); Matcher matcher = patern.matcher(source); StringBuffer sb = new StringBuffer(source.length()); while(matcher.find()){ matcher.appendReplacement(sb, "<br/>"); } matcher.appendTail(sb); return sb.toString(); } 的水平图像置于较小的容器中。我能够以我想要的尺寸插入它,并按照我想要的min-width: 968px ...来剪切它 我已经尝试了所有正常的方法,似乎没有任何工作...... 有什么想法吗?

你说过的问题确实相似,但两者的答案都不适合我......无论如何,谢谢你

2 个答案:

答案 0 :(得分:1)

要在较小的容器中包含大图像,您必须决定使用以下内容“直观地调整大小”图像:

img
{
  max-width:100%;
  height:auto;
  dsplay:block;
}

或者您可以在背景中将其转换为原始尺寸,但显然会减少溢出,所以:

div
{
   width:300px;
   height:200px;
   background-image:url(image.jpg)
   background-position:50% 50%;
}

答案 1 :(得分:0)

您可以使用绝对位置。不要忘记在父母身上设置亲戚的位置。然后你可以使用翻译技巧来确保你的图像水平和垂直居中(见例子):

&#13;
&#13;
div {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 0 auto;
  overflow: hidden;
}
div img {
  position: absolute;
  top: 50%;
  left: 50%;
  -moz-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
&#13;
<div>
  <img src="http://lorempixel.com/400/200/" alt="" />
</div>
&#13;
&#13;
&#13;

相关问题