简体   繁体   English

如何在中心背景中制作跨度文本

[英]How to make span text in the center background

It's possible moving span text like using margin? 是否有可能像使用边距那样移动跨度文本?

and provide the distance on the border so as not to touch? 并在边框上提供距离以免碰触?

i already use background-position but not working. 我已经使用background-position但无法正常工作。

i want the span text in the center background black 我想要中心background black的跨度文本

 div { color: white; } span { border-radius: 20px; position: fixed; margin-left: 8px; margin-top: 8px; background: black; height: 34px; width: max-content; border-radius: -2px; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet"/> <div> <span> <i class="fa fa-folder-open" aria-hidden="true"></i> <i class="fa fa-lg fa-angle-right" style="margin-left:7px;"></i> My Folder</span> </div> 

JSFiddle 的jsfiddle

You can use the padding & line-height to make the text center. 您可以使用paddingline-height使文本居中。 See this 看到这个

 div { color: white; } span { border-radius: 20px; position: fixed; margin-left: 8px; margin-top: 8px; background: black; height: 34px; width: max-content; line-height: 32px; padding: 0 15px; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet"/> <div> <span> <i class="fa fa-folder-open" aria-hidden="true"></i> <i class="fa fa-lg fa-angle-right" style="margin-left:7px;"></i> My Folder</span> </div> 

just set the line-height of your span to the height of the span. 只需将跨度的line-height设置为跨度的高度即可。 In your case it would be: line-height: 34px; 在您的情况下,应为: line-height: 34px;

additionally you can add some padding to the span to get some more space left and right: padding: 0 15px; 另外,您可以在跨度上添加一些填充以左右留出更多空间: padding: 0 15px;

You can also use flex (with justify-content and align-items ) and some padding like this : 您还可以使用flex(带有justify-contentalign-items )和一些填充,如下所示:

 div { color: white; } span { border-radius: 20px; position: fixed; margin-left: 8px; margin-top: 8px; background: black; height: 34px; width: max-content; border-radius: -2px; /*code addedd*/ display:inline-flex; padding:0 10px; justify-content:center; align-items:center; /**/ } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" /> <div> <span> <i class="fa fa-folder-open" aria-hidden="true"></i> <i class="fa fa-lg fa-angle-right" style="margin-left:7px;"></i> My Folder</span> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM