gpt4 book ai didi

javascript - 垂直居中相对位置+未知高度

转载 作者:太空宇宙 更新时间:2023-11-03 17:32:56 25 4
gpt4 key购买 nike

我的 WP 站点中有两个专栏。一个有文本/内容,另一个有背景图片。两者相对定位,高低不明。

HTML(使用 twitter - bootstrap 3 标记)

<article>

<div id="...removed php code ">

<div class="row">

<div class="col-md-8 indx-img" style="background-image:url('...');">
</div>

<div class="col-md-4 text-cell">
<h1><?php the_title(); ?></h1>
<h3><?php the_category(' '); ?></h3>
</div>

</div><!-- /row -->

</article>

CSS

.indx-img {
position: relative;
padding: 16% 0;
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
}

.text-cell {
position: relative;
padding: 0 25px;
margin: 0;
}

我希望 text-cell div 在其列中垂直居中。列的高度由其相邻列 index-img div 和 padding: 15% 0

设置

最佳答案

你可以摆弄变换转换百分比和边距顶部百分比..类似的东西(玩 x 和 y 数字以获得期望的结果)

.text-cell {
position: relative;
padding: 0 25px;
margin: x% 0 0;
transform: translateY(y%)
}

或者在 jquery 中找出行高,然后在 jquery 中为那个 .text-cell div 设置偏移量

关于javascript - 垂直居中相对位置+未知高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30227395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com