Html 如何在不使用固定'的情况下使固定图元垂直和水平居中;宽度'&';高度';?
我有一个没有宽度和高度的固定元素,只包含一些灵活的文本。当我想垂直和水平地将文本居中时,我失败了。如何实现?谢谢:) 试试这个Html 如何在不使用固定'的情况下使固定图元垂直和水平居中;宽度'&';高度';?,html,css,Html,Css,我有一个没有宽度和高度的固定元素,只包含一些灵活的文本。当我想垂直和水平地将文本居中时,我失败了。如何实现?谢谢:) 试试这个 div { background: #069; color: #fff; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); } 这可以通过css3转换属性轻松实现 **vertically Middle** div{ background: #
div {
background: #069;
color: #fff;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
这可以通过css3转换属性轻松实现
**vertically Middle**
div{
background: #069;
color:#fff;
position: fixed;
top: 50%;
transform:translateY(-50%);
}
对于水平方向,您需要宽度或其他
div{
background: #069;
color:#fff;
position: fixed;
top: 50%;
transform:translateY(-50%);
transform:translateX(-50%);
//comes horizontally center as per elements width
left:50%;
right:0;
}
div{
background: #069;
color:#fff;
position: fixed;
top: 50%;
transform:translateY(-50%);
transform:translateX(-50%);
//comes horizontally center as per elements width
left:50%;
right:0;
}