水平内联对齐

发布于 2024-11-26 23:36:17 字数 319 浏览 1 评论 0原文

我在名为 Mission 的部分 id 中分配了 h2 和 p 元素。您可以在此处查看详细代码 http://jsfiddle.net/5Umm3/ 我经常遇到在水平方向对齐两个元素的问题。相反,它们开始垂直对齐,高度为 45 px,我希望 h2 元素即任务在部分 id 任务的 45 px 高度中垂直居中对齐,并且 p id 也在 45 px 高度中垂直居中对齐。 h2 和 p 彼此水平对齐。我还看到 p 有一些粗体类型,而我没有给它加粗,在这种情况下它是否继承了以前的 id 的字体粗细?提前感谢您的帮助。

I assigned a h2 and p element within a section id named mission. You can check the detailed code here http://jsfiddle.net/5Umm3/
I constantly face problem to align two elements in horizontally direction. Rather they start aligning vertically, the height is 45 px and I wanted h2 element i.e. mission to be vertically center aligned in 45 px height of the section id mission and the p id also to vertically center align in 45 px height. h2 and p being horizontally aligned inline to each other. Also I see the p to have somewhat bold type without me giving it bold, does it inherits the font weight from the previous id in this scenario? Thanks for your help in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抹茶夏天i‖ 2024-12-03 23:36:17

我认为这就是您所追求的:

  1. 使 #mission 中的 h2p 并排放置。
  2. 删除 p 上的粗体

为此,我将 display:inline-block; 添加到 h2p 中。

h2 也与顶部垂直对齐。两者都添加了宽度。

我用 font-weight:normal; 删除了 bold

#mission h2{
    text-align:left;
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size:22px;
    font-weight:bold;
    margin-left:40px;
    color:blue;
    display:inline-block;
    width:200px;
    vertical-align:top;
}
#mission p{
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size:14px;
    margin-right:40px;
    display:inline-block;
    width:450px;
    font-weight:normal;
}

http://jsfiddle.net/jasongennaro/5Umm3/2/

I think this is what you are after:

  1. make the h2 and the p in the #mission sit side by side.
  2. remove the bold on the p.

To do that, I added display:inline-block; to both the h2 and the p.

The h2 was also vertically aligned to the top. Width was added to both.

And I removed the bold with font-weight:normal;.

#mission h2{
    text-align:left;
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size:22px;
    font-weight:bold;
    margin-left:40px;
    color:blue;
    display:inline-block;
    width:200px;
    vertical-align:top;
}
#mission p{
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size:14px;
    margin-right:40px;
    display:inline-block;
    width:450px;
    font-weight:normal;
}

http://jsfiddle.net/jasongennaro/5Umm3/2/

扬花落满肩 2024-12-03 23:36:17

我真诚地试图理解你的问题是什么,但我只是无法理解其中的大部分内容。尝试使用带有明确问题、以问号结尾的短句来提问。

唯一以问号结尾的句子是用 p 粗体询问。如果您在任何合理的调试器(如 Firebug 或 Chrome 调试器)中查看 HTML,您可以看到 p 由于以下 CSS 而变得粗体:

#mission {font-weight: bold;}

由于 p 标记包含在任务部分内,因此它被任务部分,除非您在本地覆盖 p 格式。如果你想单独控制 p ,你可以像这样使用 CSS:

#mission p {font-weight: normal;}

至于你写的所有关于对齐的内容,我不明白你的问题是什么。请重新表述一个简单的问题,我们可以尽力提供帮助。

编辑:
仍在猜测您想要什么,但如果您希望“Mission”标题的左边缘与其下方文本的左边缘对齐,请删除 CSS 这部分中指示的行:

#mission h2{
    text-align:left;
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size:22px;
    font-weight:bold;
    margin-left:40px;    // <---- Remove this line
    color:blue;
}

I honeztly tried to understand what your question was, but I just can't follow most of it. Try using short sentences with a clear question that end in a question mark to ask a question.

The only sentence that ends in a question mark is asking with the p has bold. If you look at your HTML in any reasonable debugger (like Firebug or Chrome debugger), you can see that the p gets bold because of this CSS:

#mission {font-weight: bold;}

Since the p tag is contained inside the mission section, it is covered by any settings on the mission section unless you override the p formatting more locally. If you wanted to control the p separately, you could use CSS like this:

#mission p {font-weight: normal;}

As for all that you wrote about alignment, I don't follow what your question is. Please rephrase a simple question and we can try to help.

Edit:
Still guessing what you want here, but if you want the left edge of the "Mission" title to line up with the left edge of the text below it, then remove the indicated line in this part of your CSS:

#mission h2{
    text-align:left;
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size:22px;
    font-weight:bold;
    margin-left:40px;    // <---- Remove this line
    color:blue;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文