Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the width of a <hr> element in one direction?

I am trying to change the width of a <hr> element with jQuery but it changes the width in 2 directions. I only want it to stretch to the right side. the variable food.runningDistance changes when I do some actions on my application. Code :

html :

<hr id="runningLine">

javascript :

$("#runningLine").animate({width: food.runningDistance}, 500);
like image 787
Jim Peeters Avatar asked Apr 18 '15 08:04

Jim Peeters


People also ask

How do I change the width of HR in CSS?

The thickness of the hr tag can be set using the height property in CSS. The minimum height can be 1px since the smallest unit available is 1 pixel. Images can be added to make the hr tag more beautiful in appearance. It is an empty tag, and it does not require an end tag.

How do you change the width of a horizontal line in HTML?

The HTML <hr> width attribute is used to specify the width of the horizontal line in terms of pixels or percent. Attribute Values: pixels: It sets the width of <hr> attribute in terms of pixels. %: It sets the width of <hr> attribute in terms of percentage (%).

How do I make my HR tag lighter?

But the way horizontal rules that blend in are usually done using colours. So if your background is for instance white ( #fff ) you can always make your HR very light. Like #eee . And use a CSS file instead of in-line styles.


1 Answers

An hr element behaves like margin: 0 auto is set to it. As I stated in my comment to your question, I would use a div since hr is supposed to mark a thematic break, but you're using it for a different purpose.

If you still want to get it work the way you want, you have to set margin-left: 0; margin-right: 0;:

$("#runningLine").css("margin", 0).animate({width: "10%"}, 3000);
<hr id="runningLine">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
like image 127
malifa Avatar answered Oct 27 '22 09:10

malifa