简体   繁体   English

如何将这两个放在同一行? (一个居中,一个右对齐)

[英]how to put these two on the same line? (one centered, one right aligned)

I am trying to align two different sets of text to be on the same line. 我正在尝试将两组不同的文本对齐在同一行上。

<h2 style="text-align:center">Only $4 for first-class shipping on all orders!</h2><span style="text-align:right">test</span>​

I'm trying to have these on the same line. 我正在尝试将它们放在同一行上。 i thought the span tag did it, but it doesnt. 我以为span标签做到了,但是没有。 when i put it in a div, it goes down a line, i need it on the same line. 当我将它放在div中时,它沿着一条线下降,我需要在同一条线上。

http://jsfiddle.net/MWDxC/ http://jsfiddle.net/MWDxC/

You need to put display:inline on that H2 tag since it's a block element as default. 您需要在该H2标签上放置display:inline,因为默认情况下它是一个块元素。

http://jsfiddle.net/MWDxC/2/ http://jsfiddle.net/MWDxC/2/

Or you could just move the entire span tag inside the H2 and that would work as well. 或者,您可以将整个span标签移动到H2内,这样也可以正常工作。

You need a wrapping element, change the display and set a float. 您需要一个包装元素,更改显示并设置一个浮点数。 Then it will work. 然后它将起作用。

<div style="text-align:center;">
  <h2 style="display:inline;" >Only $4 for first-class shipping on all orders!</h2>
  <span style="float:right; display:block;">test</span>
</div>

If you want to keep the <h2> centered and the <span> on the right - http://jsfiddle.net/MWDxC/3/ 如果要保持<h2>居中且<span>在右侧-http://jsfiddle.net/MWDxC/3/

<header>
    <h2>Only $4 for first-class shipping on all orders!</h2>
    <span>test</span>
</header>

header {
    position: relative;
}

h2{
    text-align: center;
}

span {
    position: absolute;
    right: 0;
    top: 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 同一行中的两个文本一个对齐,另一个对齐 - Two texts in the same line one aligned left the other centered 如何在同一行上有两个DIV,一个不带HTML表格,一个左对齐,一个右对齐? - How can I have two DIV s on the same line , one aligned to the left and one aligned to the right without an HTML table? 两部分导航。 一个居中,另一个右对齐 - Two part navigation. One centered and the other right aligned 如何以相同的div居中放置两条不同大小的水平线? - How to place two horizontal lines one by one with different sizes aligned centered in same div? 连续两个元素,一个左对齐,一个居中,如何? - Two elements in a row, one left aligned and one centered, how? 我想使标题位于同一行的中心,两个浮点数分别向左和向右浮动 - I want to have a title centered on the same line as two floats one to left and one to right 如何在同一行上获得两个链接,但一个链接在左侧,一个链接在右侧? - How to get two links on the same line but one on the left and one on the right? 材质用户界面。 网格内的 2 个项目; 一个左对齐,一个右对齐。 在同一行 - Material UI. 2 items inside a grid; one left-aligned, one right-aligned. In the same line 居中和右对齐的文本不在同一行上呈现 - Text that is centered and right-aligned not rendered on the same line 如何将表格(2个下拉菜单和按钮)放在一行的中心 - How to put a form (2 dropdowns and button) centered on one line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM