生成的 HTML 元素之间的空格
我遇到了一个问题,简单但愚蠢的阻塞。
我构建了一个 GWT(Google Web Toolkit)Web HMI。 在面板中,我创建了一堆CheckBoxes
。其中每个都给我一个 span
元素,其中包含 input
复选框及其 label
。到目前为止,一切都很好。
所以我得到了这个:
<span class="blablabla keepUnited">blabliblu1</span><span class="blablabla keepUnited">blabliblu2</span><span class="blablabla keepUnited">blabliblu3</span><span class="blablabla keepUnited">blabliblu4</span>
在生成的 HTML 代码中,span
元素粘在一起。这搞乱了我所有美丽的布局!如果我用空格分隔 span
元素,布局就很好:
<span class="blablabla keepUnited">blabliblu1</span> <span class="blablabla keepUnited">blabliblu2</span> <span class="blablabla keepUnited">blabliblu3</span> <span class="blablabla keepUnited">blabliblu4</span>
如何插入这些空格?
I encountered a problem, simple but stupidly blocking.
I build a GWT (Google Web Toolkit) Web HMI.
In a panel, I create a bunch of CheckBoxes
. Each of these gives me a span
element which contains the input
checkbox and its label
. So far, so good.
So I get this :
<span class="blablabla keepUnited">blabliblu1</span><span class="blablabla keepUnited">blabliblu2</span><span class="blablabla keepUnited">blabliblu3</span><span class="blablabla keepUnited">blabliblu4</span>
In the generated HTML code, the span
elements are stuck together. This messes up all my beautiful layout! The layout is fine if I separate the span
elements with spaces:
<span class="blablabla keepUnited">blabliblu1</span> <span class="blablabla keepUnited">blabliblu2</span> <span class="blablabla keepUnited">blabliblu3</span> <span class="blablabla keepUnited">blabliblu4</span>
How to insert these spaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
扩展 FlowPanel,以便在小部件之间添加内联空格:
以与旧 FlowPanel 相同的方式使用新 FlowPanel:
结果有空格(为了测试,我使用竖线“|”而不是空格“”):
不确定空格位于跨度内的事实是否会破坏您的交易。真正的版本也应该修改 insert() 方法。另请注意,使用此方法时,在检查小部件计数或迭代小部件列表时必须小心,因为 MyFlowPanel 正在秘密注入 InlineHTML 小部件。例如,添加两个复选框后,流程面板中就会出现三个小部件。
如果您确实想要变得更奇特,您可以向 MyFlowPanel 添加构造函数,在其中指定要在主要元素之间添加的“插页式”字符串、SafeHtml 或 Widget。
Extend FlowPanel so that it adds an inline space between widgets:
Use the new FlowPanel in the same way as the old FlowPanel:
Result has spaces (to test, I used a vertical bar '|' instead of a space ' '):
Not sure if the fact that the spaces are inside spans is a deal-breaker for you. The real version ought to rework the method insert() as well. Also note that with this approach, you have to be careful when checking widget counts or iterating through widget lists, since MyFlowPanel is secretly injecting InlineHTML widgets. So after you've added two checkboxes, for example, there are three widgets in the flow panel.
If you really wanted to get fancy, you could add constructors to MyFlowPanel in which you specify what "interstitial" string, SafeHtml, or Widget you wanted added between your main elements.
HTML(和 GWT)不关心元素的配置。这是 CSS 的作用。
解决方案是使用 setStyleName 或 addStyleName 方法在每个 span 元素上放置一个简单的 CSS 类
之后,在您的 css 中:
当然,您可以将 4px 替换为您想要的值。
The HTML (and GWT) does not care about the disposition of your element. It's the role of the CSS.
A solution will be to put a simple CSS class on each span element with the setStyleName or the addStyleName method
After that, in your css :
Of course, you can replace 4px by the value you want.
您可以做的是在 span 元素上设置
float:left;
,如以下 stackoverflow 答案中所建议:将 span 标签包裹在 div 内它可能并不完美,并且不要忘记在跨度后面的标记中添加
clear:both
,否则布局将会中断。What you can do is set
float:left;
on the span elements, as suggested in this stackoverflow answer: Wrapping span tags inside a divIt's maybe not perfect and don't forget to add
clear:both
in the tag after the spans, otherwise you layout will break.你可以尝试运行这个简单的搜索&替换正则表达式
搜索:
替换:
you could try to run this simple search & replace regex
search:
replace: