2014-03-27 67 views
-1

我有一个div,应该始终在浏览器的中心。现在有一个图片永远在浏览器中间。但问题是div是960px宽,但图片是1263px。我该如何解决问题?当浏览器窗口更小时,我仍然需要的是死掉,应该只在960px处来滚动条。我知道我可以在理论上解决任何问题,如果我将Tell css图像作为背景图像进行整合。但是,这并不工作,遗憾的是,因为我真的需要img标签图像作为背景没有css

#header-bottom { 
    height: 1245px; 
    background: red; 
    width: 960px; 
    margin: 0 auto; 

} 
.header-bottom-wrapper { 
    position: relative; 
    width: 960px; 
    margin: auto; 
    height: 545px; 
} 



<div id="header-bottom"> 
      <div class="header-bottom-wrapper"> 
       <img src="http://dummyimage.com/1263x545/000/fff"> 
       </div> 
      </div> 

http://jsfiddle.net/UcLnD/

+0

为什么你真的需要图像标记? – BenM

+0

,因为我使用的是jqueryslider,需要img标签 – herrsaidy

+1

这个问题描述是由Google翻译给你的 - 翻译后几乎变得非常有意义 – Huangism

回答

0

试试这个:

#header-bottom { 
    height: 1245px; 
    background: red; 
    width: 960px; 
    margin: 0 auto; 
    overflow: hidden; 

} 
.header-bottom-wrapper{ 
    position: relative; 
    width: 960px; 
    margin: auto; 
    height: 545px; 
} 

.header-bottom-wrapper img { 
    margin-left: -152px; 
} 
+0

ok,为什么margin-left:-152px?使用此解决方案,我无法看到整个图像 – herrsaidy

+0

要查看整个图像,请删除溢出:隐藏;为#标题底部。 如果容器的图像比较小,则必须将图像容器/ 2,为什么/ 2之间的差异放大。因为是唯一的方法,以确保你有相同的区别左侧和右侧 – Pirata21

+0

好的,谢谢。但是当我删除溢出:隐藏,我得到的滚动条:( – herrsaidy

0

可以使用负利润率几乎减少空间的图像所需要。

<div class="clipimg"> 
<img src="imagetoowide-1000px" /> 
</div> 
.clipimg { 
width:500px; 
text-align:center; 
} 
clipimg img { 
margin:0 -50%; 
} 

了右/左和文本对齐调缘阴性。

这里举例中心图像和短片双方

例子:http://codepen.io/gc-nomade/pen/hjyEv/

0

林不知道你不使用CSS指定修复的意思。但是图像需要保持相同的大小?如果您希望图像来调整基于browersize它添加到你的CSS:

.header-bottom-wrapper img {width:100%;}

#header-bottom { 
    height: 1245px; 
    background: red; 
    width: 960px; 
    margin: 0 auto; 

} 
.header-bottom-wrapper { 
    position: relative; 
    width: 960px; 
    margin: auto; 
    height: 545px; 
} 

.header-bottom-wrapper img {width:100%;} 


<div id="header-bottom"> 
      <div class="header-bottom-wrapper"> 
       <img src="http://dummyimage.com/1263x545/000/fff"> 
       </div> 
      </div> 
+0

图像应该有相同的大小 – herrsaidy