如何在不使用 ap 标签的情况下使文本从右到左方向?
我在页面上有一个动态显示的 div。我希望能够使用 div 右上角的按钮隐藏 div。我发现执行此操作的一种方法是使用 ap 标记,如下所示:
<p dir="RTL">button</p>
如果这是 div 中 HTML 的第一行,它会将按钮放在 div 的右上角。然而,它给了我一个上面的新行和一个下面的新行,所以,按钮并不是我真正想要的位置。 “dir”属性似乎不适用于 span 标签,如果我使用 css 内联显示 p 标签,
p {
display:inline;
}
按钮将不再右对齐。相反,它留在左手角。有没有办法让这个按钮位于右上角,而没有两个不必要的新行,也没有一堆 ?
I have a dynamically appearing div on a page. I would like to be able to hide the div with a button at the top right corner of the div. One way I have found to do this is to use a p tag, like so:
<p dir="RTL">button</p>
If this is the first line of HTML within the div, it will put the button in the upper right hand corner of the div. However, it gives me a new line above and a new line below, so, the button isn't really where I want it to be. The "dir" attribute doesn't seem to work with a span tag, and if I display the p tag inline using css
p {
display:inline;
}
the button is no longer right aligned. Instead it stays in the left hand corner. Is there a way to get this button in the upper right hand corner without two unnecessary new lines and without a bunch of ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有两个选择:
p
标记上的边距:p { margin: 0; }
div
而不是p
大多数浏览器以 1em 的顶部和底部边距呈现段落标签。
至于您的
rtl
属性问题,您使用的是什么浏览器?据我所知,只要元素是内联的并且您使用正确的 unicode 字符,它就应该可以正常工作。You have two options here:
p
tag:p { margin: 0; }
div
instead of ap
Most browsers render paragraph tags with a 1em top and bottom margin.
As for your problems with the
rtl
property, what browser are you using? As far as I'm aware it should work fine with as long as the element is inline and you're using the correct unicode characters.HTML
dir="rtl"
和 CSSdirection:rtl
适用于需要它的语言,如果您不打算添加希伯来语和阿拉伯语,最好不要使用它支持您的网站。至于你的问题,我猜你想将文本向右对齐,这可以使用text-align:right
轻松实现。HTML
dir="rtl"
and CSSdirection:rtl
meant for languages that require it, and it's better not to use it in case you are not planning to add Hebrew and Arabic support to your website. As for your question, I guess you want to align text to the right, which can be made easily usingtext-align:right
.