简体   繁体   English

CSS背景图片对齐问题

[英]CSS background-image alignment issue

My background image won't align between the divs in this code - I have tried clearing them to no avail. 我的背景图片在此代码中的div之间无法对齐-我试图清除它们无济于事。 Anyone know what's causing it, or how I can get it to work? 有人知道是什么原因引起的,或者我如何使它工作? CSS in html for convenience. 为了方便起见,HTML中的CSS。

<div class="header" style="height:200px; background-image: url(bg.png); margin:-8px;">
<img src="logo.png" style="margin-left:auto; margin-right:auto;" />
</div>

<div style="text-align:center;">
    <div style="background-image: url(bg.png);background-position:center;  
display:inline-block; width:90px; border-bottom-left-radius: 20px;">Div 1</div>
    <div style="background-image: url(bg.png);background-position:center;  
display:inline-block; width:400px;margin:-4px;">Div 2</div>
    <div style="background-image: url(bg.png);background-position:center;  
display:inline-block; width:90px;border-bottom-right-radius: 20px;">Div 3</div>
</div> 

Here's a fiddle: http://jsfiddle.net/FphKk/ 这是一个小提琴: http : //jsfiddle.net/FphKk/

Image: http://i.imgur.com/YLVpI.png 图片: http//i.imgur.com/YLVpI.png

Your margins are shifting the divs and therefore their backgrounds causing the stripe misalignment: 您的页边距正在移动div,因此其背景导致条纹未对齐:

No margins: Fiddle here 没有利润: 在这里摆弄

Added back the inline-block and removed margins in addition to creating a container div with a set width - otherwise the stripes misalign based on window width. 除了创建具有设置宽度的容器div之外,还添加了内联块并删除了边距-否则,条纹将基于窗口宽度而未对齐。

Fiddle here 在这里摆弄

I can't see any background images, but as far as I can tell, the 2nd <div> wouldn't align between the 1st and 3rd <div> , because you used display:inline-block; 我看不到任何背景图像,但据我所知,第二个<div>在第一个和第三个<div>之间不会对齐,因为您使用了display:inline-block; instead of display:inline; 而不是display:inline; .

http://jsfiddle.net/bcnobel/FphKk/1/ http://jsfiddle.net/bcnobel/FphKk/1/

I honestly can't tell what this does to your background image's position, because you didn't set the full url to the image. 老实说,我不知道这对背景图片的位置有什么影响,因为您没有为图片设置完整的url。
I will look into that as soon as you change the url's. 您更改网址后,我会立即进行调查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM