简体   繁体   English

如何在不创建两条单独线的情况下将h3与ap对齐?

[英]How do I align an h3 with a p without creating two separate lines?

I have html code that looks like this: 我有看起来像这样的html代码:

<h3>Corruption, the most infallible symptom of constitutional liberty.</h3>
<p>~ Edward Gibbon</p>

The resulting output is below: 结果输出如下:

在此处输入图片说明

As I pointed out w/ the arrow, I don't want Edward Gibbon below the quote, but preferably to the right of "liberty". 正如我用箭头指出的那样,我不希望爱德华·吉本(Edward Gibbon)在引号下,但最好不要在“自由”的右边。

Is this possible, if I have h3 tags involved? 如果我涉及h3标签,这可能吗? Should I be using span or div tags? 我应该使用span或div标签吗? Any guidance would be greatly appreciated! 任何指导将不胜感激!


Updated solution in case anybody needs this in the future (via Greg Jennings): 更新的解决方案,以防将来有人需要(通过Greg Jennings):

<h3>Corruption, the most infallible symptom of constitutional liberty. <span 
class="parastyled" style="font-size: 10px;">~ Edward Gibbon</span></h3>

The resulting output is below: 结果输出如下:

在此处输入图片说明

Just make them inline! 只需使其内联即可!

h3, p{ 
    display: inline;
} 

Note, you probably don't want this to affect all p's and h2's so i'd do this: 注意,您可能不希望这影响所有的p和h2,所以我会这样做:

<div class="same-line">
    <h2>blah balh</h2>
    <p>blah</p>
</div>

CSS: CSS:

.same-line p, .same-line h2{
    display:inline;
}

You can change the display type of the p and h3 tags 您可以更改p和h3标签的显示类型

HTML: HTML:

<h3 class="sameline">Corruption, the most infallible symptom of constitutional liberty.</h3>
<p class="sameline">~ Edward Gibbon</p>

CSS: CSS:

<style type="text/css">
        .sameline {
            display: inline;
        }
    </style>

You should use the correct tools for the job. 您应该使用正确的工具来完成工作。

This is a quote, it belongs in a blockquote : 这是一个引用,它属于blockquote

http://jsfiddle.net/2a2S9/ http://jsfiddle.net/2a2S9/

HTML: HTML:

<blockquote>
    <p>Corruption, the most infallible symptom of constitutional liberty.</p>
    <p class="byline">~ Edward Gibbon</p>
</blockquote>

CSS: CSS:

blockquote { font-weight: bold;
    font-size: 20px; }

blockquote p { display: inline-block; }

blockquote p.byline { font-weight: normal;
    font-size: 12px; }

Use a span inside the tag with the style you want. 在标签内使用所需样式的跨度。 You need an inline element here. 您在这里需要一个内联元素。

<h3>Corruption, the most infallible symptom of constitutional liberty. <span class="parastyled">~ Edward Gibbon</span></h3>

<h3> is a block element, it will use all the available width. <h3>是一个块元素,它将使用所有可用宽度。 You could use a span inside the h3 instead of the p . 您可以在h3内使用一个span而不是p Or you could replace the h3 with an inline element. 或者,您可以用inline元素替换h3

p {

 display:inline;
 float:none;

}

try the following css 试试下面的CSS

h3,p{ 
    float:left;
    width:auto;
} 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM