看起来不可能在p个标签之间有2个空白行没有修改原始元素 [英] It seems impossible to have 2 blank lines between p tags Without modification of the original elements

查看:267
本文介绍了看起来不可能在p个标签之间有2个空白行没有修改原始元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我上一个问题的另一个:



是否不可能在p标签之间有2个空行? Markdown



在提出各种意见后,我曾经认为我可以管理它;



,我不能。



--------



br



--------

A
B

-------- < br>



p标签




--------



A



B






OK,现在,我想在A和B元素之间插入2行,而不是1,而不对原始元素进行任何修改;



我希望的结果是这样的(br emulation)




-------- < br>


A


B



--------



尝试使用p标签




--------



A



 



B



--------



哎!



因此,没有办法通过HTML和CSS来实现这一点



代码:
http://jsfiddle.net/LhDFs/9/

  --------< br> 
## br< br>
--------< br>
A< br> B
< br> --------< br>
## p tag
< br> --------
< p> A< / p>
< p> B< / p>
--------< br>
## OK,现在,我想在A和B元素之间插入2行而不是1,而不对原始元素进行任何修改;< br>
##我想要的结果是这样的(br emulation)
< br> --------< br>
< br>
A< br>< br>< br> B
< br>
< br> --------< br>
##试用p标记
< br> --------< br>
< p> A< / p>
< p style ='margin:0;'>& nbsp;< / p>
< p> B< / p>
--------< br>
##哎哟! 3行插入而不是2.
< br> ##所以,是没有办法这样做的HTML和CSS?

编辑:
有些人提到我对HTML的理解不成熟,拒绝然而,人们说的是HTML限制。



为了使事情更清楚,这是HTML + js编码,而不是静态。所以,我想在A和B元素之间插入2(或任意数字)而不是1,而不修改原始元素;



因为函数不是修改原始上下文,而是插入空白行。我打算插入东西。当我插入东西的时候,如果我需要修改原来的上下文,更复杂和东西一般不会很好。所以,如果真的不可能在原始元素之间插入精确的行,我放弃了,弄错了修改原始上下文。



如果这真的不可能,请告诉我,而不是给我一些代码。



谢谢。



编辑:



我认为这是不可能的



因此,整个上下文应该使用'noMargin'段落标签来构造。



http://jsfiddle.net/LhDFs/10/

 < p class =noMargin>无保证金< / p> 
< p class =noMargin>& nbsp;< / p>
< p class =noMargin>& nbsp;< / p>
< p class =noMargin>无保证金< / p>

css

  p.noMargin {
margin:0;
}

或简单 b

 < p>无保证金< / p> 
< p>& nbsp;< / p>
< p>& nbsp;< / p>
< p>无保证金< / p>

css

  p {
margin:0;
}

抵免额到



@ 3dgoo



是不可能在< p>标签? Markdown



感谢大家,如果有人对我的帖子有不愉快的感觉,非常抱歉。

解决方案

好的,让我们回到html基础,可能会有帮助!



首先,ap标签是一个块元素包含内联元素。

这里的简短教程: http://www.webdesignfromscratch.com/html-css/css-block-and-inline/



因此p是一个段落, br表示断线。事实上,你在段落中分割你的内容,有时你需要改换换行符。如果你想有,可以说:



text A




text B

那么你应该有两个不同的段落:

 < p style = margin-bottom:1em;>文字A< / p> 
< p>文字B< / p>

(确定,将css放在不同的文件中,而不是内联)



保证金推动另一段。对于换行符,应该如下所示:



文本A

文本B

 < p>文字A< br>文字B< / p> 

我保留段落,但在其中有一个换行符。



在CSS中应用margin-bottom到p,所有的段落将有相同的距离!有点像风格的东西与正常,标题1,标题2 ...在Word中,你可以决定前后的利润。



希望它帮助! >

编辑:



您可以使用Javascript执行,或者我更喜欢使用jQuery方式:

(在jQuery编码中)

  $('p' ){
var $ this = $(this);
if($ this.html()=='& nbsp;'){
$ this.remove();
}
});

例如,您可以使用regex。我删除了包含非破坏性空间的p标签,因为它添加了一个完整的段落。保持两个不同的段落,所以它会更容易放置一些边距和控制一切与CSS (像我说的顶部的我的答案。不要尝试添加br或p之间,但边距! )。有了br,你需要3 br才能跳过两行。



这是你需要的吗?如果没有,请更清楚!


Here is another for my previous question:

Is it impossible to have 2 blank lines between p tag? Markdown

After various comments given, I once thought I can manage it;

in fact, I cannot.

--------

br

--------
A
B
--------

p tag


--------

A

B

--------

OK, now, I want to insert 2 lines instead of 1 between A and B elements without any modification of the original elements;

The result I expect is like this (br emulation)


--------

A


B

--------

trying with p tag


--------

A

 

B

--------

Ouch!! 3 lines inserted instead of 2.

so, is there no way to do this by HTML and CSS??

The code: http://jsfiddle.net/LhDFs/9/

--------<br>
## br<br>
--------<br>
A<br>B
<br>--------<br>
## p tag
<br>--------
<p>A</p>
<p>B</p>
--------<br>
## OK, now, I want to insert 2 lines instead of 1 between A and B elements without any modification of the original elements;<br>
## The result I expect is like this (br emulation)
<br>--------<br>
    <br>
A<br><br><br>B
    <br>
<br>--------<br>
## trying with p tag 
<br>--------<br>
<p>A</p>
<p style = 'margin: 0;'>&nbsp;</p>
<p>B</p>
--------<br>
## Ouch!! 3 lines inserted instead of 2.
<br> ## so, is there no way to do this by HTML and CSS??

Edit: some people mention that my understanding to HTML is immature, well I won't deny it; however, what people said is about HTML restriction.

To make things clearer, this is for HTML+js coding, not static. So, again I want to insert 2 (or any number ) lines instead of 1 between A and B elements without any modification of the original elements;

Because the function is not to modify the original context but to insert blank lines. What I intend is to insert things. When I insert things, if I need to modify the original context, more complicated and things generally don't go well. So, if it is really impossible to insert exact lines between original elements, I gave up and make a mess to modify original context. What I would like to know is if it's possible or impossible.

If it's really impossible, just tell me so instead of giving me some codes.

Thank you.

Edit:

I conclude it is not possible to insert the exact lines as long as the default paragraph tag context exists.

So, instead, the whole context should be constructed with 'noMargin' paragraph tag.

http://jsfiddle.net/LhDFs/10/

<p class="noMargin">No margin</p>
<p class="noMargin">&nbsp;</p>
<p class="noMargin">&nbsp;</p>
<p class="noMargin">No margin</p>

css

p.noMargin {
    margin: 0;
} 

or simply

<p>No margin</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>No margin</p>

css

p{
    margin: 0;
} 

The credit goes to

@3dgoo

Is it impossible to have 2 blank lines between <p> tag? Markdown

Thank you everyone, and if someone had unpleasant feelings on my post, my apologies.

解决方案

Ok, let's get back to html basics, probably it'll help!

First of all, a p tag is a block element that contains inline elements.
Short tutorial here: http://www.webdesignfromscratch.com/html-css/css-block-and-inline/

So p is a paragraph, and br means a line breaks. In fact, you divides your content in paragraph, and sometimes your need to change line with line breaks. If you want to have, lets say:

text A


text B

Then you should have two different paragraphs:

<p style="margin-bottom: 1em;">text A</p>
<p>text B</p>

(ok, put you css in a different file, not inline)

The margin push the other paragraph. For line breaks, it should look like this:

text A
text B

<p>text A<br>text B</p>

I keep the paragraph around all, but a line break in it.

And applying margin-bottom to p in css, all your paragraph will have the same distance! A bit like the style thing with normal, header 1, header 2... in Word where you can decide margin before and after.

Hope it helps!

EDIT:

You can do it with Javascript, or I prefer to use jQuery that way:
(in jQuery coding)

$('p').each(function() {
    var $this = $(this);
    if ($this.html() == '&nbsp;') {
        $this.remove();   
    }
});

You can use regex, for example. I removed the p tag containing the non breaking space because it add a full paragraph between. Keep two different paragraph so it will be easier to put some margins and control everything with css (like I said a the top of my answer. Don't try to add br or p between, but margins!). With br, you need 3 br to skip two lines between.

Is that what you need? If not, please be more clear!

这篇关于看起来不可能在p个标签之间有2个空白行没有修改原始元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆