卡住。尝试在标题标签中使用CSS向左,中心和右文本
试图在标题标签中向左/中心/右中心这3个文本?没有运气,请参阅图片。
<body>
<header>
<span>503.984.9317</span>
<span>[email protected]</span>
<span>portland, or</span>
</header>
body {
background-color: pink;
}
header {
background-color: green;
width: 600px;
height: 40px;
margin: auto;
}
span {
background-color: yellow;
}
Trying to left/center/right these 3 spans of text within a HEADER tag? No luck, please see picture.
<body>
<header>
<span>503.984.9317</span>
<span>[email protected]</span>
<span>portland, or</span>
</header>
body {
background-color: pink;
}
header {
background-color: green;
width: 600px;
height: 40px;
margin: auto;
}
span {
background-color: yellow;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
Flexbox
应该非常有效地完成工作,但如果您不想使用它并仅依靠定位。Using
flexbox
should do the work quite efficiently but in case you don't want to use it and rely on positioning only.我建议您使用FlexBox,因为这是定位项目的最佳方法。
但是,由于您不想使用Flexbox,我找到了一种使用浮子来定位元素的替代方法。注意:不建议使用。
我只是为您展示另一种方法。
I would suggest you to use flexbox as it is the optimum way to position items.
But as you don't want to use flexbox, I found an alternative way to position your elements using floats. NOTE: this is not recommended to use.
I am just showing an alternative way just for you.
将此样式添加到您的标题类中并检查输出。
Add this style to your header class and check the output.
CSS中这些情况的最佳盟友当然可以是Flexbox及其惊人的属性。继续前进,看看使用Flex容器(标头)及其子女(跨度)在Flexbox中使用Flex物品的方法。在
Best ally for these cases in CSS can certainly be the flexbox and its amazing properties. Go ahead and take a look at this approach playing with the flex container (header) and its children(spans) known as flex items in FlexBox. Read more on Flexbox in this article.