html - 基于百分比的底部值不适用于页面加载
问题描述
我注意到一个奇怪的......“错误”......
我有一些看起来像这样的 CSS:
.header-slider-text {
bottom: 40%;
color: #fff;
font-size: 22px;
left: 3%;
position: relative
}
这针对在我的 WP 插件代码中创建的一些 HTML:
$html .= '<div class="top-header-slider full-width-div">';
$html .= ' <div>';
$html .= ' <img src="'. plugins_url('/plugin-name/images/static/1st-slider.jpg') .'"
alt="Some Alt Text" class="img-responsive top-header-img" />';
$html .= ' </div>';
$html .= ' <div>';
$html .= ' <img src="'. plugins_url('/plugin-name/images/static/2nd-slider.jpg') .'"
alt="Some Alt Text" class="img-responsive top-header-img" />';
$html .= ' <div class="header-slider-text" id="second-header-slide-text">';
$html .= ' <p>At the Nurburgring....</p>';
$html .= ' <a href="">Click here</a>';
$html .= ' <p>and find out why</p>';
$html .= ' </div>';
$html .= ' </div>';
$html .= ' <div>';
$html .= ' <img src="'. plugins_url('/plugin-name/images/static/3rd-slider.jpg') .'"
alt="Some Alt Text" class="img-responsive top-header-img" />';
$html .= ' <div class="header-slider-text" id="third-header-slide-text">';
$html .= ' <a href="">Click Here</a>';
$html .= ' <p>to see more</p>';
$html .= ' </div>';
$html .= ' </div>';
$html .= '</div>';
但是,我注意到当我使用40%
我的bottom
价值时,在页面加载时它不会将我的 div 提高 40%。如果我将值更改为333px
然后它每次都有效。我怎样才能让它使用百分比和工作?
解决方案
绝对定位的元素以这种方式显示在页面上相对于文档的位置,使用顶部、左侧、底部和右侧 CSS 属性,您可以指定精确位置。尝试这个:
.top-header-slider{
position: relative
}
.header-slider-text {
bottom: 40%;
color: #fff;
font-size: 22px;
left: 3%;
position: absolute
}
推荐阅读
- ionic-framework - 如何在测试中模拟 ionBlur
- mysql - 是否可以将一些文件加载到 ecs fargate 临时存储
- firebase - Firestore 文档错误 - 在初始化程序中只能访问静态成员
- spring - 多线程中的Spring事务管理?
- android - 获取用户当前区域android
- geolocation - 我想计算离子 4 中两个位置之间的距离(以 km 为单位)。我使用了一个给我错误的函数
- python - 向模型添加 KL 散度的 Keras 问题
- kotlin - 在 Kotlin 中将“If”替换为“When”
- python - 试图在 Pandas 中获得一致的时间格式
- python - 熊猫数据框 - 计算条件的行总和并将其与列表元素进行比较