简体   繁体   English

如何将3个不同的段落彼此相邻放置?

[英]How to place 3 different paragraphs next to each other?

In my footer I want to make 3 different sections of paragraphs-at left, middle and right. 在我的页脚中,我想在左边,中间和右边制作3个不同的段落部分。 The 3 paragraphs should sit next to each other, not below each other. 这三段应该相邻放置,而不是彼此相邻。

This is how I was trying to do, but I failed to figure it out. 这就是我试图做的,但是我没有弄清楚。

<footer>
        <div id="footer_box">

                        <p id="footer_text_left">
                        should sit at the left.
                        </p>

                        <p id="footer_text_middle">
                        should sit in the middle.
                        </p>
                    <p id="footer_text_right">
                        should sit at the right.

                        </p>

        </div>

                        </footer>

.CSS: .CSS:

#footer_box{
    border-top:2px solid #009933;
    padding-bottom:75px;
    background-color:#3366CC;
    }
    #footer_text_left{
    font-size:15px;
    color:black;
    font-family:Euphemia;


    }
    #footer_text_middle{
    font-size:15px;
    color:black;
    font-family:Euphemia;

    }

    #footer_text_right{

    font-size:15px;
    font-family:Euphemia;
    color:black;

    }

First option: 第一种选择:

p {
  float: left;
}

Second option: 第二种选择:

p {
  float: left;
  width: 30%;
  margin: 0 1%;
}

Third option (best): 第三种选择(最佳):

p {
 display: inline-block;
}

Another thing I saw was that every paragraph had the same rules, you could set the font properties on the body or global paragraph so you won't need to set it on everything. 我看到的另一件事是,每个段落都有相同的规则,您可以在正文或全局段落上设置字体属性,因此无需在所有内容上都进行设置。

That would look like this: 看起来像这样:

body {
   font-size:15px;
   font-family:Euphemia;
   color:black;
}

Or if you want it just on the footer paragraphs: 或者,如果仅在页脚段落中需要它:

footer p {
    font-size:15px;
    font-family:Euphemia;
    color:black;
}

This is Extremely easy to do, either by making the <p> 's inline-block , or float:left them: 非常容易做到,通过制作<p>inline-blockfloat:left它们:

#footer_box p{
    display:inline-block;
}

inline-block , (or inline ) is the best way to do it, as float:left , has some unwanted effects, such as the <p> 's no longer effect the height of their parent, as can be seen in this JSFiddle , compare it with the one below. inline-block (或inline )是完成此操作的最佳方法,因为float:left产生一些不良影响,例如<p>不再影响其父代的高度,如本JSFiddle所示 ,将其与下面的内容进行比较。

JSFiddle 的jsfiddle

See this SO question about it: float:left; 看到这样的问题: float:left; vs display:inline; vs display:inline; vs display:inline-block; vs display:inline-block; vs display:table-cell; vs display:table-cell;

Just capture the paragraph into a div and add style. 只需将段落捕获到div中并添加样式即可。 For example 例如

<div style="float: left; margin-right: 20px">

Here's how I did for a paragraph containing picture: https://jsfiddle.net/xomkq7dv/7/ 这是我对包含图片的段落的处理方式: https : //jsfiddle.net/xomkq7dv/7/

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

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