2011-11-12 45 views
3

我需要切片此圖像中的CSS背景 http://i28.lulzimg.com/f0f166e559.png切片與CSS的圖像以不同的尺寸

使用,但我無法找到如何做一個適當的解決方案,我想在 有相同的背景不同的大小,但標題頂角相同的大小。

http://screensnapr.com/v/9h30Wr.png

請某人能引導我正確的CSS彩色圖片作爲背景。 謝謝你的幫助。

+0

你認爲Photoshop? – JJJ

+0

我需要正確的css代碼來使用這個圖像作爲背景,並且photoshop不會爲這個圖像生成這樣的代碼。 – user969068

+0

我的意思是使用Photoshop來切片圖像和CSS,把元素放在一起,只要你喜歡。 – JJJ

回答

2

這裏幾乎是純CSS的解決方案。僅在Chrome中進行測試。調整圖像大小和邊距以滿足您的需求。你只需要兩個小圖片來自您的大圖片裁剪:

CSS(base.css)

* { 
    margin: 0px; 
    padding: 0px; 
} 

#title_element { 
    position: absolute; 
    right: 0px; 
    top: 0px; 
    width: 191px; 
    height: 28px; 
    background: #1f252b; 
    background: url("title.png") no-repeat; 
    z-index: 1; 
} 

h1 { 
    margin-left: 20px; 
    margin-top: 2px; 
    color: #fff; 
    font-size: 16px; 
    text-align: center; 
} 

#title_bar { 
    position: relative; 
    background: #1f252b; 
    height: 6px; 
    margin-top: 21px; 
    border-left: 1px solid #4d5259; 
    border-right: 1px solid #4d5259; 
    border-top: 1px solid #4d5259; 
    -webkit-border-top-left-radius: 5px; 
    border-top-left-radius: 5px; 
} 

#content { 
    position: relative; 
    background: #191e25; 
    background: url("grain.png") repeat; 
    border: 2px solid #191e25; 
    -webkit-border-bottom-left-radius: 5px; 
    -webkit-border-bottom-right-radius: 5px; 
    border-bottom-left-radius: 5px; 
    border-bottom-right-radius: 5px; 
} 

HTML(index.html)

<!DOCTYPE html> 
<html> 
<head> 
    <title>Test</title> 
    <link rel="stylesheet" href="base.css" type="text/css" media="screen"/> 
</head> 

<body> 
    <div id="title_element"> 
     <h1>Your Title</h1> 
    </div> 
    <div id="title_bar"> 
    </div> 
    <div id="content"> 
     <p>Lots</p> 
     <p>of</p> 
     <p>text</p> 
     <p>to</p> 
     <p>test</p> 
     <p>this layout to work ok</p> 
    </div> 
</body> 
</html> 
+0

謝謝先生,正是我需要的,在所有瀏覽器中測試並完美工作。 :) – user969068

1

你可以這樣做:

div{ 
    width:633px; 
    min-height:100px; 
    position:relative; 
    margin-top:60px; 
    background:url(http://i.imgur.com/U0NhH.jpg) repeat-y top left ; 

} 
div:after, div:before{ 
    content:''; 
    position:absolute; 
    left:0; 
    background:url(http://i.imgur.com/J6kEf.jpg) no-repeat ; 
    width:100%; 
    height:35px; 
} 
div:after{ 
    top:-35px; 
} 
div:before{ 
    height:10px; 
    bottom:-10px; 
    background:url(http://i.imgur.com/J6kEf.jpg) no-repeat left bottom; 
} 

入住這http://jsfiddle.net/zADDG/

更新:

入住這http://jsfiddle.net/zADDG/2/

+0

謝謝sandeep爲你的努力,但仍然存在你的代碼中的問題,你的代碼我不能使用相同的樣式來使不同大小的盒子在寬度和高度上小/大,我希望它是一個靈活的div,它可以自動隨內容調整。 – user969068

+0

你想要寬度必須靈活? – sandeep

+0

在你的例子中,你的寬度大小是633px,可以說我想用433px製作一個新的div,看看我丟失的頂部和底部圖像http://jsfiddle.net/zADDG/1/和http://screensnapr.com/ v/jmy9DW.png和你的身高代碼工作完美...再次感謝你。 – user969068