简体   繁体   中英

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. Preferably in pure CSS (3?), how would set the width of the horizontal rules to auto minus X number of pixels?

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

Or you could use Javascript for something more specific. For eg:

CSS:

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

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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