简体   繁体   English

我的其中一个段落不会与其他段落保持一致

[英]One of my paragraphs will not float left to be in line with the other paragraphs

First time posting on here, but i've used this site countless times when looking for answers so hopefully another one can be provided for me. 第一次在这里发布,但是我在寻找答案时已经使用了无数次,因此希望可以为我提供另一个答案。

My problem is as follows: 我的问题如下:

I have been trying to get all the text to float left and be in line(the title, the author, the description) however, the time does not want to seem to float left to match up with the rest. 我一直试图使所有文本向左浮动并排成一行(标题,作者,描述),但是,时间似乎不想向左浮动以与其余部分匹配。 the "14 hours ago" simply only goes that far (as shown in the pic) when directed to "float left" 当指向“向左浮动”时,“ 14小时前”只是走了那么远(如图所示)

Here is my html and css: 这是我的HTML和CSS:

HTML and CSS HTML和CSS

The Problem 问题

I am new to HTML and CSS, having recently started to teach myself it so any help would be greatly appreciated and apologies in advance if it is a stupid question haha! 我是HTML和CSS的新手,最近开始自学它,因此,如果这是一个愚蠢的问题,任何帮助将不胜感激,并在此道歉。

First of all, do not put a block element inside a line element. 首先,不要将block元素放在line元素内。 In your case, you want to put <p> tag inside <span> . 对于您的情况,您想将<p>标记放在<span> Always try to avoid it even though you can tweak it by css. 即使您可以通过css对其进行调整,也应始终尝试避免它。

Then you maybe misuderstood float and text-align. 然后,您可能会误以为浮动和文本对齐。 Text-align should be the way to go in here in my opinion. 我认为,文本对齐应该是这里的方法。

I would rework your HTML to be honest, one wrapper element like or 老实说,我会重做您的HTML,像这样的包装元素

with two inner elements having a class to set their color would be probably better. 具有两个内部元素来设置其颜色的类可能会更好。

So I suggest something like this: 所以我建议像这样:

<div class="news-section">
  <img src="..." alt="..." />
  <h3>Your news title</h3>
  <div class="header">
    <span class="author">John Doe</span><span class="time">10 hours ago</span>
  </div>
</div>

Then just set color and font size for author and time classes... If I got it correctly from your question. 然后只需为作者和时间类别设置颜色和字体大小即可。

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

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