How can I draw a horizontal line (hr) in a react component using dynamic color?
Here's what I have so far:
render {
let color = 'red';
return (
<div>
There is a red HR
<hr />
<div>
)
}
Use the <hr /> tag and set the style prop on it. Set the height of the line and optionally set backGroundColor and color .
To create a horizontal line in React, you can add an hr element to the React component. The object style has the color, background-color and height . The color will give the line a solid color and the background-color for other properties.
One way to set up the component:
const ColoredLine = ({ color }) => (
<hr
style={{
color: color,
backgroundColor: color,
height: 5
}}
/>
);
And then use it with:
<ColoredLine color="red" />
For a full breakdown on how to style <hr />
, see http://www.sovavsiti.cz/css/hr.html
<hr style={{
color: '#000000',
backgroundColor: '#000000',
height: .5,
borderColor : '#000000'
}}/>
Only adding the borderColor
, to change the exact full-color change of <hr />
tag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With