简体   繁体   English

如何设置宽度 <hr/> 在CSS中X的像素数小于宽度:auto?

[英]How to set width of a <hr/> in CSS to X number of pixels less than the width:auto?

I have a nav with some <hr/> elements. 我有一些带有<hr/>元素的导航。 Preferably in pure CSS (3?), how would set the width of the horizontal rules to auto minus X number of pixels? 优选地,在纯CSS(3?)中,如何将水平规则的宽度设置为自动减去X个像素数?

This does not duplicate this question , because it is for what would equate to negative padding, which is impossible. 这并不重复这个问题 ,因为它等于负填充,这是不可能的。

You could use the below. 你可以使用下面的内容。

hr {
    width: auto;
    margin: 0 10px; /* This leaves 10px margin on left and right. If only right margin is needed try margin-right: 10px; */
}

Try using margin-right 尝试使用margin-right

Or you could use Javascript for something more specific. 或者你可以使用Javascript更具体的东西。 For eg: 例如:

CSS: CSS:

hr {
   margin-right:20px;
   width:auto;    
}

Demo 演示

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

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