将标题置于没有Flexbox的响应式映像之上(Put heading on top of Responsive image without Flexbox)

编程入门 行业动态 更新时间:2024-10-28 18:32:43
将标题置于没有Flexbox的响应式映像之上(Put heading on top of Responsive image without Flexbox)

我想在图像顶部放置一个标题,垂直和水平居中对齐。 我通过Flexbox实现了它。 但是,某些浏览器不支持Flexbox。 没有flexbox有没有办法做到这一点?

注意:图像必须是响应式的。 所以我不能将背景图像用于div

<div class="col-md-3 col-6 category" @click="openPopup('cement')"> <img src="https://www.quotzap.com/static/images/categories/cement.jpg" width="100%" /> <h2>Cement</h2> </div> .category{ cursor: pointer; transition: all .2s ease; justify-content: center; display: -webkit-flex; display: flex; align-items: center; } .category h2{ max-width: 100px; text-align: center; position: absolute; color: #ffffff; line-height: 1.5; } .category img{ border-radius: 5px; box-shadow: 0px 2px 10px 0px rgba(143,143,143,0.68); position: relative; -webkit-filter: brightness(70%); transition: all .2s ease; }

I want to put a heading on top of an image, vertically and horizontally center aligned. I've achieved it through Flexbox. However, some browsers are not supporting Flexbox. Is there is any way to do it without flexbox?

Note: The image must be responsive. So I can't use background image for div

<div class="col-md-3 col-6 category" @click="openPopup('cement')"> <img src="https://www.quotzap.com/static/images/categories/cement.jpg" width="100%" /> <h2>Cement</h2> </div> .category{ cursor: pointer; transition: all .2s ease; justify-content: center; display: -webkit-flex; display: flex; align-items: center; } .category h2{ max-width: 100px; text-align: center; position: absolute; color: #ffffff; line-height: 1.5; } .category img{ border-radius: 5px; box-shadow: 0px 2px 10px 0px rgba(143,143,143,0.68); position: relative; -webkit-filter: brightness(70%); transition: all .2s ease; }

最满意答案

尝试将CS​​S更改为此...如果您不想使用弹性框。

.category{ cursor: pointer; transition: all .2s ease; justify-content: center; position: relative; align-items: center; z-index: 0; } .category h2{ max-width: 100px; text-align: center; top:50%; left:50%; transform:translate(-50%, -50%); width:50%; position: absolute; color: #ffffff; line-height: 1.5; z-index:2; } .category img{ z-index: 1; border-radius: 5px; box-shadow: 0px 2px 10px 0px rgba(143,143,143,0.68); position: relative; -webkit-filter: brightness(70%); transition: all .2s ease; }

Try changing your CSS to this... if you dont want to use flex box.

.category{ cursor: pointer; transition: all .2s ease; justify-content: center; position: relative; align-items: center; z-index: 0; } .category h2{ max-width: 100px; text-align: center; top:50%; left:50%; transform:translate(-50%, -50%); width:50%; position: absolute; color: #ffffff; line-height: 1.5; z-index:2; } .category img{ z-index: 1; border-radius: 5px; box-shadow: 0px 2px 10px 0px rgba(143,143,143,0.68); position: relative; -webkit-filter: brightness(70%); transition: all .2s ease; }

更多推荐

本文发布于:2023-07-06 20:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1054506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:映像   标题   Flexbox   Put   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!