使用宽度可调的背景图像编码 div 标题
我似乎无法弄清楚这一点,但请参阅下图:
有一堆不同的 div 标头具有不同的文本长度。由于模板的编码方式,它们不能有单独的类名。他们都使用同一个类。代码示例如下:
<div class="headerText"></div>
<div class="headerDots"></div>
现在,我在“headerText”div 内有标题文本,并且点图像作为背景图像在“headerDots”内重复。我似乎无法弄清楚如何使点图像变得更小和更宽,具体取决于标题旁边的宽度。如果我无权为每个标头提供自己的类名,是否可以以允许此功能的方式对 HTML/CSS 进行编码?
I can't seem to figure this out but see the image below:
There are a bunch of different div headers with varying text lengths. Because of the way the template is coded, they can't have individual class names. All of them use the same class. Code example is like this:
<div class="headerText"></div>
<div class="headerDots"></div>
Right now I have the header text inside the "headerText" div and the dots image as a background image on repeat inside "headerDots". I can't seem to figure out how to make the dots image get smaller and wider depending on how wide the header is next to it. Is it possible to code the HTML/CSS in a way that allows for this functionality if I don't have access to give each header its own classname?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
演示(有背景色,但原则适用。)更好的演示
Demo (with background color, but principle applies.)Better Demo
如果您使用类似的东西并将颜色替换为背景图像或您喜欢的任何内容会怎么样:
What if you use something like this and just replace the colors with your background image or whatever you like:
这就是我要尝试的:
如果您对单词和破折号有疑问,请将单词的背景颜色设置为等于垂直破折号更高 z-index 上的灰色。然后,破折号总是填充相同的空间,并且单词重叠,给出可变破折号的外观。
这只是一个想法。
This is what I would try:
If you have trouble with the word and the dashes, set the word with a background color equal to that grey on a higher z-index that the vertical dashes. Then the dashes are always filling the same space and the word overlays, giving the appearance of variable dashes.
It's just an idea.
仅使用 jquery,没有 HTML 更改......
将背景颜色应用于文本本身,以覆盖点。
此处的工作示例
With only jquery and no HTML changes....
Applies the background color to the text itself which will cover the dots.
Working example here