Reply
New User
deleyd
Posts: 2
Registered: ‎05-17-2012
0 Kudos

Center horizontal line?

Is it possible to center a horizontal line?

 

<hr style="width:30%">

 It should be centered by default, but I can't seem to get it to center.

 

<div style="text-align:center;"><hr style="display:inline-block; width=30%;" align="center" /></div>

 any tricks to get this <hr> to center?

Frequent Contributor
cale
Posts: 60
Registered: ‎05-02-2012
0 Kudos

Re: Center horizontal line?

The first code will work fine. You just forgot to add the backslash before the closing bracket.

New User
deleyd
Posts: 2
Registered: ‎05-17-2012
0 Kudos

Re: Center horizontal line?

I get a line 30% wide, but it's left justified, at least in my NOOK for PC where I'm testing it. I can't get the line to be centered.

Frequent Contributor
cale
Posts: 60
Registered: ‎05-02-2012
0 Kudos

Re: Center horizontal line?

Every e-reader has certain ways of doing things different like margins and centering. I just played around with different ways of formatting the hr and I found that while I could style it to center in a mobi file at 30%, it would left align after converting to epub when I opened it in Adobe Digital Editions. Now if I took out the 30% and just left the line at the full 100%, it would center just fine.

 

I also found that in the mobi file the old fashioned html way of doing it:

 

<hr width="30%">

 

worked better than with a style:

 

<hr style="width: 30%" />

Frequent Contributor
cale
Posts: 60
Registered: ‎05-02-2012
0 Kudos

Re: Center horizontal line?

Somebody just gave me an idea. Instead of setting the percentage of the rule, set left and right margins of the div until you get the rule down to the size you want.