2012-11-29 141 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> 
相关问题