2012-10-29 158 views
0

ie image:IE
firefox image:火狐創建箭頭CSS和背景圖像

我試圖創建水平可能會改變大小的箭頭。它應該使用代表以下3個圖像:< --->

我試圖用div和css做到這一點,但它不在IE中工作。身體圖像不居中,看起來像是下劃線。但是,在身體居中的firefox或chrome中不會發生這種情況,並且會與左側和右側圖像的頂端對齊。 < ____>:IE(錯誤) < ----->:火狐(右)

我有以下幾點:

.bodyArrow { 
    width: 38px; 
    background: url("../../images/ArrowBody.png") repeat-x center; 
    height: 5px; 
} 
.arrowLeft { 

    height: 5px; 
    padding-left: 38px; 
    background: url("../../images/ArrowLeft.png") no-repeat 0 0; 
} 
.arrowRight { 
    height: 5px; 
    font-style: normal; 
    padding-right: 3px; 
    background: url("../../images/ArrowRight.png") no-repeat 100% 0; 
} 

<table> 
<tr> 
<td> something </td> 
<td> 
    <DIV class="bodyArrow"> 
    <DIV class="ArrowLeft"> 
    <DIV class="ArrowRight"> 
    </DIV></DIV></DIV> 

</td> 
<td> something </td> 
</tr> 
</table> 

如何使它將有什麼建議?

非常感謝!

+0

不工作在什麼地方? – CoffeeRain

回答

1

可以使用background-size財產伸展背景圖像

background-size:width height; 

和定位的背景圖像,您可以使用Background-position財產

+0

謝謝,但不幸的是,這並沒有幫助。 – BMF

+0

@BMF顯示圖像在IE和Mozilla中的外觀。還有沒有父元素包裝這些元素?如果是,那麼也發佈該代碼。 –

+0

我添加了圖像。這些div位於桌子的一個單元格中。 – BMF

0

這可能會實現。你的div不正確。

<div class="bodyArrow"></div> 
<div class="ArrowLeft"></div> 
<div class="ArrowRight"></div> 

然後你將不得不添加float:left;到你的divs我猜。

.bodyArrow { 
width: 38px; 
background: url("../../images/ArrowBody.png") repeat-x center; 
height: 5px; 
float:left; 
} 
.arrowLeft { 

height: 5px; 
padding-left: 38px; 
background: url("../../images/ArrowLeft.png") no-repeat 0 0; 
float:left; 
} 
.arrowRight { 
height: 5px; 
font-style: normal; 
padding-right: 3px; 
background: url("../../images/ArrowRight.png") no-repeat 100% 0; 
float:left; 
} 
+0

謝謝,但不幸的是,這並沒有幫助。我想我的問題比「水平」更「垂直」 – BMF

+0

我編輯了我的答案。也許它現在會工作? –

+0

不幸的是它沒有。垂直對齊仍然是一樣的。 – BMF

1

你應該使用:after和之前,以避免不必要的標記。它適用於IE8,但您的文檔必須具有文檔類型。

.arrow { 
    position: relative; 
    width: 38px; 
    background: url("../../images/ArrowBody.png") repeat-x center; 
    height: 5px; 
} 

.arrow:before { 
    content: ""; 
    position: absolute; 
    height: 5px; 
    width: 5px; 
    left: *what you need*; 
    background: url("../../images/ArrowLeft.png") no-repeat 0 0; 
} 

.arrow:after { 
    content: ""; 
    position: absolute; 
    height: 5px; 
    width: 5px; 
    right: *what you need*; 
    background: url("../../images/ArrowRight.png") no-repeat 0 0; 
} 

然後在HTML中,你只需要:

<div class="arrow"></div> 

您所需要的Ajust值。更多的信息在這裏:http://www.w3schools.com/cssref/sel_after.asp

這適用於IE8和更高版本。 (和其他瀏覽器)

編輯:忘記也許是最重要的你的情況:使用頂級屬性來調整你的箭頭對齊。

+0

有什麼辦法可以做到類似的東西沒有文檔類型?我不能使用它(不是我的選擇..) – BMF

+0

如果你不能指定一個文檔類型,那麼我想不是。我沒有嘗試過。你沒有使用它有點奇怪,你需要在怪癖模式下工作嗎? – Amida

+0

是的,我這樣做。我想我的問題在下面解決。但是,無論如何感謝您的幫助!非常感謝。 – BMF