使用 CSS 在两个宽度变化的 div 之间放置一条线
我正在 CSS 布局,并且该设计在两个可以更改大小的元素之间使用了很多 | 。 IE
John | Logout
其中 John 位于相关 div 的左侧,Logout 位于右侧。由于名称是动态且可变的,有什么方法可以保证该线位于每个名称的中间?我是否应该放弃 CSS 方法而只使用一点 JavaScript 函数?
<div class="top">
<p class="name">Welcome Jeremy Louelen-Boxen</p>
<p>|</p>
<p class="logout"><a href="#">Logout</a></p>
</div>
编辑: 对于更多细节,因此该线将出现在两个元素的中间,其中一个(或两个元素都在更改大小)
p | logout
john | logout
david | logout
jonathonan | logout
reallylongname | logout
右侧边框不起作用,因为它是距元素的静态距离,即元素之前的填充边框需要根据包含的字符数进行更改。
感谢大家的帮助,戴夫
I'm CSSing a layout, and the design has used lots of |'s in between two elements that can change size. I.E.
John | Logout
Where John is on the left of the div in question, and Logout is on the right. With the name being dynamic and changeable, is there any way I can guarantee the line will position in the middle of each? Should I perhaps quit the CSS approach and just use a little JavaScript function?
<div class="top">
<p class="name">Welcome Jeremy Louelen-Boxen</p>
<p>|</p>
<p class="logout"><a href="#">Logout</a></p>
</div>
Edit:
For some more detail, so the line will appear in the middle of the two elements, one (or both are changing size)
p | logout
john | logout
david | logout
jonathonan | logout
reallylongname | logout
Border right doesn't work as it is a static distance from the element, i.e. the padding on the element before the border needs to change depending on the number of characters included.
Thanks for your help all, Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为什么不只使用:
Why don`t use just:
在纯CSS中:
当然,这在旧浏览器中可能不起作用。
In pure css:
Of course, this may not work in old browsers.
一个黑客,但它有效:
现场演示: http://jsfiddle.net/DrJyd /2/
(您不再需要该
|
元素)
A hack, but it works:
Live demo: http://jsfiddle.net/DrJyd/2/
( you don't need that
<p>|</p>
element anymore )就可以了
that will do it