Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw red horizontal line in React

Tags:

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>
    )
}
like image 274
sleatrou Avatar asked Jan 08 '18 19:01

sleatrou


People also ask

How do you draw a horizontal line in React?

Use the <hr /> tag and set the style prop on it. Set the height of the line and optionally set backGroundColor and color .

How do you make a straight line in React JS?

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.


2 Answers

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

like image 76
Luke Willis Avatar answered Sep 21 '22 19:09

Luke Willis


<hr  style={{
    color: '#000000',
    backgroundColor: '#000000',
    height: .5,
    borderColor : '#000000'
}}/>

Only adding the borderColor, to change the exact full-color change of <hr /> tag

like image 24
Jojo Joseph Avatar answered Sep 22 '22 19:09

Jojo Joseph