星空网 > 软件开发 > 网页设计

web字体浮在图像中央

在做项目的过程中遇到了需要将图像作为背景,将字体显示在图像中央需求。

尝试了两种做法:

第一种方法为设置一个div设置属性为relative固定这个框的位置,将图片铺在div块里。

在div再设一个div存放字体,z-index设置为2,及图片在下面,字体在上面,字框的属性设置为absoulte(绝对定位)。

这样就可以设置字体对于图像的偏移,具体代码如下:

 <div" style="position: relative;" >  <img src='/images/loading.gif' data-original="http://www.cnblogs.com//images/mobile/mobile1.jpg" />  <div style="position: absolute; z-index: 2; left: 45%; top: 45%">字体</div></div>

缺点:如果字体是可变的,则不好设置偏移的位置。图像也不是自适应,在不同的浏览器中效果也不相同

第二种方法为将图像作为背景,字体居中显示。

具体代码如下:

<style> #text{  background: url(/images/mobile.jpg);  filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')";  -moz-background-size: 100%100%;  background-size: 100%100%;} #textfont{
text-align:center }

<div id = "text" style ="width : 100px ;height:100px">  

    <div style ="text-align:center; line-height:100px; " >字体</div>

</div>


 




原标题:web字体浮在图像中央

关键词:web

web
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

英代标识:https://www.goluckyvip.com/tag/77380.html
英代信息标签:https://www.goluckyvip.com/tag/77381.html
挥代英怎么读:https://www.goluckyvip.com/tag/77382.html
英代信息是什么:https://www.goluckyvip.com/tag/77383.html
英代的作用:https://www.goluckyvip.com/tag/77384.html
英代协议:https://www.goluckyvip.com/tag/77385.html
深圳到西安自驾路线攻略 深圳到西安自驾最佳路线:https://www.vstour.cn/a/411228.html
松花蛋是哪里的特产松花蛋的产地:https://www.vstour.cn/a/411229.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流