显示背景图像时出现问题
Issues getting a background image to appear
我不确定为什么我不能让background-image
出现在以下代码片段中。网址是正确的,我已经为图像设置了大小。另外,如何在页面中心对齐背景图像?我知道有像right top
这样的属性,但我没有看到垂直和水平居中的属性。
谢谢。
$("#arrow-icon").slideToggle(1000);
.arrow {
height: 400px;
width: 100%;
background-color: blue;
text-align: center;
}
#arrow-icon {
padding-top: 100px;
display: none;
background-image: url("http://optimumwebdesigns.com/icons/down-arrow.ico");
background-repeat: no-repeat;
height: 50px;
width: 50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="arrow">
<div id="arrow-icon">
<!-- <img src="http://optimumwebdesigns.com/icons/down-arrow.ico"> -->
</div>
</div>
问题是div 比图片小。您可以使用 background-size 属性解决此问题
例:
#arrow-icon {
padding-top: 100px;
display: none;
background-image: url("http://optimumwebdesigns.com/icons/down-arrow.ico");
background-repeat: no-repeat;
height: 50px;
width: 50px;
background-size:100% 100%;
}
小提琴 - https://fiddle.jshell.net/800modgt/
或者您可以将div 宽度和高度更改为图像宽度和高度......
在居中方面,只需使用:
background-position: center;
也就是说,我注意到它不在小提琴以前发布的页面上的中心。您可以使用
margin:auto;
使<div>
水平居中
您可以考虑使用 CSS3 进行定位,因为它在更改div 的位置和滑出的距离方面非常通用。这是一个JSFiddle。它适用于侧面动画,但它也适用于标准的向上/向下。
https://jsbin.com/yovaqo/edit?html,css,js,output
相关文章:
- 使用Javascript对象为具有两个背景图像的DIV设置样式时出现问题
- 背景定位下拉菜单问题
- 苹果/野生动物园在移动设备上播放背景视频时出现问题
- SVG模式动画和背景淡入问题
- 背景重叠问题
- iOS 8中滚动时的背景图像闪烁问题
- 尝试在页面刷新时更改背景图像,遇到问题
- 覆盖在“背景大小:包含”上的响应式 DIV - 解决警报触发的问题
- 背景图像不透明度问题
- 将鼠标悬停在 li 元素上时更改背景的问题
- 使用 .css() jQuery 方法更改背景图像时出现问题
- 显示背景图像时出现问题
- 活动时更改菜单项背景的问题
- 浏览器和移动设备的视差背景问题(javascript/jquery)
- 预加载css背景图像,nivo滑块问题
- 拉伸背景以适应iPhone屏幕的问题
- CSS背景颜色问题
- backstretch导致chrome中的其他背景图像出现问题
- 如果背景等于问题
- 在IE和Chrome中使用Javascript获取背景图像的问题