Css 将图元添加到居中图元的侧面而不更改对齐方式
我在页面上有一个动态创建的标题。有时,它的两侧有左键和右键,有时只有左键或右键,有时没有 在添加其他元素时,是否有方法将主文本居中并使其居中?当前,当我添加左/右按钮时,整个部件居中。如果我只加一个按钮,整个东西就会移到一边 如何保持主元素居中,但在其周围添加其他元素?Css 将图元添加到居中图元的侧面而不更改对齐方式,css,centering,Css,Centering,我在页面上有一个动态创建的标题。有时,它的两侧有左键和右键,有时只有左键或右键,有时没有 在添加其他元素时,是否有方法将主文本居中并使其居中?当前,当我添加左/右按钮时,整个部件居中。如果我只加一个按钮,整个东西就会移到一边 如何保持主元素居中,但在其周围添加其他元素? 这很好: <h1> <img src="left.png" /> Main Title <img src="right.png" /> </h1> 主标题 这不
这很好:
<h1>
<img src="left.png" />
Main Title
<img src="right.png" />
</h1>
主标题
这不起作用:
<h1>
<img src="left.png" />
Main Title
</h1>
主标题
这可能是一个解决方案:
<!doctype html>
<html>
<head>
<title>Select Test</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
#header {
width: 100%;
position: fixed;
left: 0px;
top: 0px;
}
h1 {
text-align: center;
width: auto;
line-height: 53px;
}
.left {
position: fixed;
top: 5px;
left: 5px;
}
.right {
position: fixed;
top: 5px;
right: 5px;
}
</style>
</head>
<body>
<div id="header">
<img class="left" src="http://files.softicons.com/download/internet-icons/user-icons-by-2shi/png/48/user1.png" />
<h1>My Title</h1>
<img class="right" src="http://files.softicons.com/download/internet-icons/user-icons-by-2shi/png/48/user1.png" />
</div>
</body>
</html>
我发现了我的问题的答案,以防将来有人找到这个帖子 将元素保留在标记(HTML)中,但使用CSS将其样式设置为
可见性:隐藏
,而不是显示:无
。这会在页面上保留格式,但不会呈现要查看的对象
可见性:隐藏
非显示:无
阅读文章了解更多信息…这不是一个好的编码,在
中放置一个img。总之,你知道css吗?@maurelio79是的,我知道如何将元素居中等等
#header {
width: 100%;
margin-top: 0px;
margin-left: 0px;
}