CSS 我希望在同一行上的 P 标签文本彼此相邻
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17679427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I want the P tag text on the same line next to each other
提问by Anthony Boardman
I've been trying to align the P tag text left and right next to each other but can't get it to do so. They are both within the same divs and I'm coding in ems and % could anyone help?
我一直在尝试将 P 标签文本左右对齐,但无法做到这一点。它们都在同一个 div 中,我正在用 em 编码,% 谁能帮忙?
回答by Manoj Meena
make display:inline; for p tag
使显示:内联;对于 p 标签
回答by Paul Renton
You should use span instead of p which has a default display of inline
您应该使用 span 而不是 p ,它具有内联的默认显示
<span>Your text here</span>
The p element is default display block. If you insist on using p, then you need to dive into some CSS. Set a class for the p element (or ID if it is unique) like so
p 元素是默认显示块。如果你坚持使用 p,那么你需要深入研究一些 CSS。像这样为 p 元素(或 ID,如果它是唯一的)设置一个类
<p class="inline-p">Your text here </p>
Then in a separate CSS file, use a selector to reference that class. Please try to avoid inline CSS in your HTML. It can become a nightmare to maintain later.
然后在单独的 CSS 文件中,使用选择器来引用该类。请尽量避免在您的 HTML 中使用内联 CSS。以后维护可能会变成一场噩梦。
.inline-p {
// Modify display for this class
display: inline;
}
You should avoid modifying the properties of HTML tags when there is an existing HTML tag that can accomplish what you are looking to do. Nevertheless, both your options are presented here. Good luck with your website.
当存在可以完成您要执行的操作的现有 HTML 标记时,您应该避免修改 HTML 标记的属性。不过,这里提供了您的两种选择。祝你的网站好运。
回答by Pattle
You can't align text left and right in the same p tag unless you use span. But you could do it using the CSS float property
除非使用跨度,否则不能在同一个 p 标签中左右对齐文本。但是你可以使用 CSS float 属性来做到这一点
<p style="float: left">Some text on the left</p>
<p style="float: right">Some text on the right</p>
回答by jamesmillerio
You haven't posted any code for us to analyze, so speaking generally... you can mess with the "display" CSS style and floats to get them lined up as you need, or you could use a more appropriate tag that is already inline, like a span.
您还没有发布任何代码供我们分析,所以一般来说……您可以使用“显示”CSS 样式和浮动来根据需要排列它们,或者您可以使用更合适的标签内联,就像一个跨度。