简体   繁体   English

水平拉伸图像中间

[英]Stretch middle of image horizontally

How do I stretch just the middle of an image horizontally? 如何仅水平拉伸图像的中间?

For example, I have this image: 例如,我有此图像:

光泽按钮背景
(source: lawrenceinspections.com ) (来源: lawrenceinspections.com

I want the rounded corners to be the same as it is now (so stretching the whole image will not work). 我希望圆角与现在相同(因此拉伸整个图像将不起作用)。 I just want to take the middle and stretch it based off what content is inside. 我只想取中间的内容,并根据其中的内容进行扩展。 Vertically everything should stay the same height. 垂直方向,所有物体都应保持相同的高度。

How do I do this? 我该怎么做呢? Thanks! 谢谢!

  1. Make a copy of image and put it to a div with style="overflow:hidden"; 复制图像并使用style =“ overflow:hidden”;将其放入div中;
  2. Center image in that div; 该div中的中心图片;
  3. Dublicate that div and place it side-by-side any times you need; 复制该div并在需要时并排放置;
  4. Wrap thouse divs with two divs on starn and on end, countaining the copy of you image start and image end accordinatly; 将Thouse div分别在starn和end上包裹两个div,并一致地确定图像的开始和结束位置;

You'll most likely need three separate images. 您很可能需要三个单独的图像。 And three separate divs. 和三个单独的div。

One div for the left side with the left side of the image, one div for the center - which would be where your content is, and one div to the right side which would also just be an image. 左侧是一个div,图像的左侧是一个div,中间是一个div-这是您的内容所在的位置,右侧是一个div,它也只是图像。

Hopefully that makes sense. 希望这是有道理的。 You can also make a similar looking button using pure CSS without using any graphics. 您也可以使用纯CSS创建类似外观的按钮,而不使用任何图形。

Here's an example with pure css (though thats not what you asked, I know :)): 这是一个纯css的示例(尽管那不是您所要求的,我知道:)):

http://jsfiddle.net/PWNLf/1/ http://jsfiddle.net/PWNLf/1/

.button{
    background: rgb(194,172,224); /* Old browsers */
background: -moz-linear-gradient(top,  rgba(194,172,224,1) 0%, rgba(232,241,242,1) 30%, rgba(186,241,244,1) 31%, rgba(18,65,206,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(194,172,224,1)), color-stop(30%,rgba(232,241,242,1)), color-stop(31%,rgba(186,241,244,1)), color-stop(100%,rgba(18,65,206,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  rgba(194,172,224,1) 0%,rgba(232,241,242,1) 30%,rgba(186,241,244,1) 31%,rgba(18,65,206,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  rgba(194,172,224,1) 0%,rgba(232,241,242,1) 30%,rgba(186,241,244,1) 31%,rgba(18,65,206,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  rgba(194,172,224,1) 0%,rgba(232,241,242,1) 30%,rgba(186,241,244,1) 31%,rgba(18,65,206,1) 100%); /* IE10+ */
background: linear-gradient(to bottom,  rgba(194,172,224,1) 0%,rgba(232,241,242,1) 30%,rgba(186,241,244,1) 31%,rgba(18,65,206,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c2ace0', endColorstr='#1241ce',GradientType=0 ); /* IE6-9 */
color: #fff;
font-family: helvetica;
padding: 30px 60px;
    border-radius: 40px;
    text-decoration: none; 
    border: 1px solid #1241CE;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM