bootstrap 让文字显示在响应式图片上
来源:互联网 发布:云计算课程有什么 编辑:程序博客网 时间:2024/06/05 11:31
在这个位置折腾了一会,半天没有出效果。
css 样式:
当window 窗口化改变大小时重新调用上面的脚本就可以了,
有两种办法:1)让图片做为背景,文字直接布局在图片上;
2)让图片用img标签插入,文字相对布局在图片上;
先说说第一种办法的问题,要想让背景图片完全显示出来,非得设置外层容器的高度,这样就失去了响应式;
例如:
#content-sec3 { position: relative; max-width: 100%; height: auto; background: url('../images/homepage/accssorybg.jpg') no-repeat top center; background-size: 100% auto; background-color: cadetblue; text-align: center;}高度设置auto 或一个固定值都达不到效果,要么图片显示不全,要么显示有多出来的白边;
最后是用第二中方式实现的,但也有不完美的地方,文本的水平居中成了问题,折腾了半天用脚本解决了,如有更好办法的朋友,希望指教。
做法如下:
html结构:
<div id="content-sec3"> <img class="img-responsive" src="resources/images/homepage/accssorybg.jpg" /> <div id="content-sec3-adjust" style="position: absolute; top: 0; left: 50%;"> <h2 class="title">Vpanel配件 </h2> <p class="title-sub-line hidden-sm hidden-xs"> Vpanel ACCESSORIES </p> <p class="title-more">查看更多 <img src="resources/images/homepage/right.png" /> </p> </div> </div>
css 样式:
#content-sec3 { position: relative; max-width: 100%; height: auto; background-size: 100% auto; text-align: center;} #content-sec3 .title { margin-top:5px; font-family: 微软雅黑; font-size: 20px; color: #333333; } #content-sec3 .title-sub-line { margin-top:15px; margin-bottom: 18px; font-family: 微软雅黑; font-size: 12px; color: #CCCCCC; text-align: center; } #content-sec3 .title-more { margin-bottom: 10px; font-family: 微软雅黑; font-size: 12px; color: #2E84E9; text-align: center; cursor:pointer; }水平居中脚本:
var init = function () { var _bg3width = $("#content-sec3-adjust").width(); $("#content-sec3-adjust").css("margin-left", _bg3width * -1 / 2 + "px"); };
当window 窗口化改变大小时重新调用上面的脚本就可以了,
$(window).resize(function () {
init();
});
阅读全文
0 0
- bootstrap 让文字显示在响应式图片上
- 让文字在图片上滚动显示
- HTML让文字在图片上显示
- CSS让文字半透明显示在图片上
- HTML文字在图片上显示
- 图片滚动和在图片上增加文字显示
- Html 让文字显示在图片的上面
- Html 让文字显示在图片的上面
- QLabel函数重载,在图片上显示文字
- [Android]在RadioButton上显示图片和文字
- 鼠标放在图片上 显示提示的文字
- 鼠标悬停在图片上时,显示遮罩层说明文字
- iOS中在UIButton上同时显示文字和图片
- Android在Button按钮上同时显示文字和图片
- 利用opencv将两张图像在同一窗口上显示,并在图片上显示文字
- 如何让OpenCV的图片显示在MFC窗口上
- 如何让OpenCV的图片显示在MFC窗口上
- Druapl_让中英文切换器显示在Logo图片上
- 创建,删除账户,创建删除用户组
- Spark入门实战系列--7.Spark Streaming(上)--实时流计算Spark Streaming原理介绍
- service mysql start出错,mysql启动不了,解决mysql: unrecognized service错误
- spring boot + redis 实现session共享
- Java消息中间件学习笔记六 -- Spring JMS理论
- bootstrap 让文字显示在响应式图片上
- linux-系统延迟及定时机制
- 树莓派lnmp搭建
- JS设计模式之发布订阅模式
- 连续总结第二十一天
- LeetCode:60. Permutation Sequence
- 洛谷P1084 疫情控制(NOIp2012)
- typedef 定义数组类型用法
- 3、Oracle查询语句-from-字句