使用换行符时删除 HTML 元素之间的空格 [英] Removing whitespace between HTML elements when using line breaks

查看:34
本文介绍了使用换行符时删除 HTML 元素之间的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中一行大约有 10 个 img.为了 HTML 的可读性,我想在每个 img 标记之间放置一个换行符,但这样做会在图像之间呈现空白,这是我不想要的.除了在标签中间而不是在它们之间打断之外,我还能做些什么吗?

I have a page with a row of about 10 imgs. For readability of the HTML, I want to put a linebreak in between each img tag, but doing so renders whitespace between the images, which I do not want. Is there anything I can do other than break in the middle of the tags rather than between them?

这是我目前所拥有的截图.我希望使用 PHP 以随机组合显示书脊图像.这就是为什么我需要单独的 img 标签.

Here is a screenshot of what I have so far. I would like the book spine images to display in random combinations, using PHP. This is why I need separate img tags.

推荐答案

您可以使用 CSS.在图像上设置 display:block 或 float:left 将使您可以定义自己的间距并根据需要设置 HTML 格式,但会以可能或可能不合适的方式影响布局.

You could use CSS. Setting display:block, or float:left on the images will let you have define your own spacing and format the HTML however you want but will affect the layout in ways that might or might not be appropriate.

否则,您正在处理内嵌内容,因此 HTML 格式很重要 - 因为图像会像文字一样有效.

Otherwise you are dealing with inline content so the HTML formatting is important - as the images will effectively act like words.

这篇关于使用换行符时删除 HTML 元素之间的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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