简体   繁体   English

p标签和br标签的对齐

[英]Alignment of p tag and br tag

This is what I want.这就是我要的。 This is what I'm getting.这就是我得到的。

This is my code.这是我的代码。 I'm having trouble with the spacing.我的间距有问题。 I can't seem to align p tag with the br tag.我似乎无法将 p 标签与 br 标签对齐。 I have also tried experimenting with inline but no luck.我也尝试过内联但没有运气。

 <p class="one"><b>Field of</b> Select all that apply, hold CTRL when clicking to select multiple items <br> <b>study: </b></p><!-- This is where the issue lies. -->

You should have 2 containers, Left bold text should be in the left container with some styles.您应该有 2 个容器,左粗体文本应该在带有一些样式的左侧容器中。 There is no good way to fix your code for solving your problem, it is easier to rewrite it at all, as for me.没有好的方法可以修复您的代码以解决您的问题,对我而言,重写它更容易。

Use padding for having distance between texts and text-align:right;使用padding使文本和text-align:right;之间有距离text-align:right; for second line to be closer to the border.使第二行更接近边界。 Take a look:看一看:

 .main_text { padding-left:5px; } .left_text { text-align: right; }
 <div style="display:flex"> <div class='left_text'> <b>Field of <br> study: </b> </div> <div class='main_text'> <label> Select all that apply, hold CTRL when clicking to select multiple items</label> </div> </div>


Let's make it simple,让我们简单点,

Use float: right to align "study" correctly.使用float: right对齐“研究”。 And that's it!就是这样!

This is your code:这是你的代码:

 .one { width: 55px; height: 50px; } .span { float: right; }
 <b>Field of</b>&nbsp;&nbsp;&nbsp;Select all that apply; hold CTRL when clicking to select multiple items <p class="one"> <b><span class="span">Study:</span></b> </p>



CodePen:代码笔: https://codepen.io/marchmello/pen/abOPJzp?editors=1100 https://codepen.io/marchmello/pen/abOPJzp?editors=1100

Flexbox is perfect for this kind of placement. Flexbox 非常适合这种放置。 Use align-items:center for the first positioning使用 align-items:center 进行第一次定位

 div{ display:flex; align-items:center; font-size:19px; } #a1{ display:block; margin-right:14px; width:64px; }
 <div> <p id='a1' ><b>Field of <br/>Study </b></p> <p>Select all that apply, hold CTRL when clicking to select multiple items </p> </div>

or use align-items:flex-start if you want the placement like this:或者使用 align-items:flex-start 如果你想要这样的位置:

 div{ display:flex; align-items:flex-start; font-size:19px; } #a1{ display:block; margin-right:14px; width:64px; }
 <div> <p id='a1' ><b>Field of <br/>Study </b></p> <p>Select all that apply, hold CTRL when clicking to select multiple items </p> </div>

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

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