Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何将绝对定位的[h4]元素居中?_Css_Bootstrap 4 - Fatal编程技术网

Css 如何将绝对定位的[h4]元素居中?

Css 如何将绝对定位的[h4]元素居中?,css,bootstrap-4,Css,Bootstrap 4,我想将绝对定位的[h4]标记居中。[h4]标题的值从数据库中检索,每次都有不同的值 我试过下面的东西 h4{位置:绝对;顶部:20px;左侧:42%;} 当h4标题有大约15个字符时,它就起作用了。但是,如果h4标题的字符数少于或超过18个字符,则不起作用。我的意思是,它只适用于特定的场景。有什么灵活的解决方案吗?用左键试试:50%和转换:翻译(-50%,-50%) 为了更好地解释它到底在做什么 h4{display: flex; justify-content:center; align-it

我想将绝对定位的[h4]标记居中。[h4]标题的值从数据库中检索,每次都有不同的值

我试过下面的东西

h4{位置:绝对;顶部:20px;左侧:42%;}


当h4标题有大约15个字符时,它就起作用了。但是,如果h4标题的字符数少于或超过18个字符,则不起作用。我的意思是,它只适用于特定的场景。有什么灵活的解决方案吗?

左键试试:50%
转换:翻译(-50%,-50%)

为了更好地解释它到底在做什么

h4{display: flex; justify-content:center; align-items: center;}
不使用“位置”特性,u可以使用“显示柔体”使图元居中