Html css - 向右移动文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12244525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:36:52  来源:igfitidea点击:

css - move text to right

csshtml

提问by 11684

This is something that annoys me very often.
If you create a <div>and style the border (for example, border-radius: 3px;) the text is almost on top of the border, which looks very bad.
The only solution I could come up with was wrapping the contents of that div in another div, and move the wrapping div ±3px to the right. This creates a lot extra mark-up, and it somehow doesn't feel right, as if there is a bettr solution.

这是经常让我烦恼的事情。
如果您创建一个<div>并设置边框样式(例如,border-radius: 3px;),文本几乎位于边框的顶部,这看起来很糟糕。
我能想到的唯一解决方案是将该 div 的内容包装在另一个 div 中,并将包装 div 向右移动 ±3px。这会产生很多额外的加价,而且不知何故感觉不对,好像有一个更好的解决方案。

So here's my question:
Is it possible to move the contents of a div three pixels to the right as described above with css-only?

所以这是我的问题:
是否可以使用 css-only 将 div 的内容向右移动三个像素,如上所述?

Of course I'd like a cross-browser solution, but I don't mind 1 css rule per browser, I can throw that somewhere at the bottom of my stylesheet and never look at it again, that won't complicate the markup.

当然,我想要一个跨浏览器的解决方案,但我不介意每个浏览器有 1 个 css 规则,我可以将它扔到我的样式表底部的某个地方,然后再也不看它,这不会使标记复杂化。

回答by Ryan McDonough

padding-left:3px;

Add that to your div which has the text in it.

将其添加到您的 div 中,其中包含文本。

Read more about padding: http://www.w3schools.com/css/css_padding.asp

阅读有关填充的更多信息:http: //www.w3schools.com/css/css_padding.asp

回答by Kyle

Easy, you can either use padding: 0 3px;(horizontal padding only), padding-left: 3px;..

很简单,您可以使用padding: 0 3px;(仅限水平填充),padding-left: 3px;..

http://jsfiddle.net/Kyle_Sevenoaks/D3BSL/4/

http://jsfiddle.net/Kyle_Sevenoaks/D3BSL/4/

回答by Shailender Arora

i hope you are looking like this :- http://tinkerbin.com/q4cVJ0FF

我希望你看起来像这样:- http://tinkerbin.com/q4cVJ0FF

HTML

HTML

<div>stack</div>

CSS

CSS

div {
background:red;
border-radius:3px;
    padding-left:3px;
}

you can easily get your desired through paddingand you can adjust the padding from all four sides left,right,top,bottom...

您可以轻松获得所需的内容,padding并且可以从所有四个方面调整填充left,right,top,bottom...