Html 如何通过css禁用<div>内的<br>标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17588953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable <br> tags inside <div> by css?
提问by Polo Pakina
<br>
won't let me to display 3 buttons inline, so i need to disable it inside div, and I can't just delete them, they are automatically there.
<br>
不会让我内联显示 3 个按钮,所以我需要在 div 中禁用它,我不能只是删除它们,它们会自动存在。
I have:
我有:
<div style="display:block">
<p>Some text</p>
<br>
<p>Some text</p>
<br>
</div>
and I want:
而且我要:
<div style="display:block">
Some text Some text
</div>
More info
更多信息
I do not want to have mystyle.css file. Of course I know that way of disabling it.
我不想有 mystyle.css 文件。我当然知道禁用它的方法。
I asked how to add to divs style this br { display: none; }
if it is possible.
br { display: none; }
如果可能的话,我问如何将其添加到 div 样式中。
Solution:
解决方案:
- It is not possible to remove just
<p>
tags without removing content inside. - It is not possible to hide
<br>
directly by divs style, so I make it this way:
- 不可能只删除
<p>
标签而不删除里面的内容。 - 无法
<br>
通过 divs 样式直接隐藏,所以我这样做:
<style type="text/css"> .mydiv { display: block; width: 100%; height: 10px; } .mydiv br { display: none; } </style> <div class="mydiv"> Some text Some text </div>
<style type="text/css"> .mydiv { display: block; width: 100%; height: 10px; } .mydiv br { display: none; } </style> <div class="mydiv"> Some text Some text </div>
回答by Tim
You could alter your CSS to render them less obtrusively, e.g.
你可以改变你的 CSS 来让它们不那么突兀,例如
div p,
div br {
display: inline;
}
or - as my commenter points out:
或 - 正如我的评论者指出的那样:
div br {
display: none;
}
but then to achieve the example of what you want, you'll need to trim the p
down, so:
但是为了实现你想要的例子,你需要修剪p
下来,所以:
div br {
display: none;
}
div p {
padding: 0;
margin: 0;
}
回答by 2046
or hide any br that follows the p tag, which are obviously not wanted
或者隐藏 p 标签后面的任何 br,这显然是不需要的
p + br {
display: none;
}
回答by nirali
<p style="color:black">Shop our collection of beautiful women's <br> <span> wedding ring in classic & modern design.</span></p>
Remove <br>
effect using CSS.
<br>
使用 CSS移除效果。
<style> p br{ display:none; } </style>
回答by jrgd
I used it like this:
我是这样用的:
@media (max-width: 450px) {
br {
display: none;
}
}
nb: media query via Foundation
nb2: this is useful if one of the editor intend to use
tags in his/her copy and you need to deal with it specifically under some conditions—on mobile for example.
nb:通过 Foundation 进行媒体查询 nb2:如果其中一位编辑打算
在他/她的副本中使用标签,并且您需要在某些条件下专门处理它(例如在移动设备上),这将非常有用。