简体   繁体   English

如何在CSS中内联显示标题和段落元素?

[英]How to display heading and paragraph elements inline in css?

I have a HTML code which contains one heading and 2 paragraph elements: 我有一个HTML代码,其中包含一个标题和2个段落元素:

<div class="inter">

<h4>Note</h4>

<p>To add/remove a dependent or to modify your spouse's insurer information,  go to the My Life Events section and follow the instructions.</p>

<p>To modify your beneficiaries, please complete and sign the Beneficiary designation form and return it to your plan administrator.</p>

</div>

I want the above code to be displayed in the following way: 我希望以上代码以以下方式显示: 在此处输入图片说明

I tried using div.inter>p,h4 { display: inline;} but by using this I am not able to create a line break between 2 paragraphs(as shown below). 我尝试使用div.inter>p,h4 { display: inline;}但是使用此方法我无法在2个段落之间创建换行符(如下所示)。

Note: To add/remove a dependent or to modify your spouse's insurer information, go to the My Life Events section and follow the instructions.To modify your beneficiaries, please complete and sign the Beneficiary designation form and return it to your plan administrator. 注意:要添加/删除受抚养人或修改配偶的保险人信息,请转到“我的人生事件”部分并按照说明进行操作。要修改收款人,请填写并签署“收款人指定表”并将其退还给计划管理员。

Float the heading <h4> . 浮动标题<h4>

 * { margin: 0; padding: 0; } .inter > h4 { float: left; padding-right: .5em; } p { margin-bottom: 1em; } 
 <div class="inter"> <h4>Note</h4> <p>To add/remove a dependent or to modify your spouse's insurer information, go to the My Life Events section and follow the instructions.</p> <p>To modify your beneficiaries, please complete and sign the Beneficiary designation form and return it to your plan administrator.</p> </div> 

H2.... are block level element. H2 ....是块级元素。

Better use H4 instead of span tag . 最好使用H4代替span标签。 Because if use span tag means no need to write code for same line 因为如果使用span标签意味着无需为同一行编写代码

"span tag is default inline element only" “ span标签仅是默认的嵌入式元素”

then what ever style write in span. 然后将样式写成跨度。 Try to make code for easily. 尝试轻松编写代码。

Simply add the following css and your good to go. 只需添加以下CSS和您的好东西。

.inter h4, p:nth-of-type(1) { display: inline !important;}

Sample: http://codepen.io/Nasir_T/pen/edwqZz 范例: http//codepen.io/Nasir_T/pen/edwqZz

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

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