2012-11-29 70 views
0

我有一個用於IAB廣告牌廣告的子標題容器,需要考慮廣告應居中的容器中兩個不同寬度的廣告。帶有自動邊距的CSS居中但沒有寬度

我的問題是 - 是否有任何解決方法,不使用自動寬度居中元素的寬度?

我的基本代碼結構如下:

<div class="sub_header_wrap" style="width:970px"> 
    <div class="ad" id="pencil00" style="margin:0 auto;min-height:30px"> 
     <!-- some ad code -- may be 970px or 950px wide --> 
    </div> 
</div> 

我在這裏找到另一種解決辦法,但我想嘗試使用它之前就知道的注意事項。除了我的完整代碼中的廣告位置之外,​​容器中還有其他元素。他們可能會通過這一解決方案的不利影響:

<div class="sub_header_wrap" style="width:970px;text-align:center"> 
    <div class="ad" id="pencil00" style="text-align:left;display:inline-block;min-height:30px"> 
     <!-- some ad code -- may be 970px or 950px wide --> 
    </div> 
</div> 

該解決方案似乎產生在.sub_header_wrap容器附加4PX計算的高度。

+0

我會看到有關添加片段到這個問題。不確定是否可以與供應商分享示例廣告代碼。 – nthdegreeburns

回答

2

解決的辦法是...

<div class="sub_header_wrap" > 
    <div class="ad" id="pencil00" style="margin:0 auto;min-height:30px;max-width: 970px;text-align: center;"> 
     <!-- some ad code -- may be 970px or 950px wide --> 
    </div> 
</div> 

<div class="sub_header_wrap" style="width:970px;text-align:center"> 
    <div class="ad" id="pencil00" style="text-align:left;display:inline-block;min-height:30px; margin-bottom: -4px;"> 
     <!-- some ad code -- may be 970px or 950px wide --> 
    </div> 
</div> 
相關問題