0

I am trying to create a linear gradient css style for a button and for some reason it's not working. I think it may be a react issue, not really sure.

Code:

import React from "react";

var bg = {
  background: "#FFFFFF"
}

var btnFill = {
  background: 'linear-gradient(to right, #E040FB, #00BCD4)'
}


class ConsolePage extends React.Component {

  render() {
    return <div style={bg}>
      <div class="uk-sticky-placeholder"></div>
        <div class="uk-width-1-1">
          <div className="uk-grid">
            <div className="uk-margin-left uk-margin-top uk-margin-bottom uk-width-1-3@m">
              <div className="uk-margin-xlarge-top">
                    <div className="my-3" align="center">
                    <h3 className="mb-1">placeholder text</h3>
                        <div className="uk-grid">
                          <div>
                            <button href="/docs">
                              Learn More
                              <div className="btn"></div>
                            </button>
                          </div>
                          <div>
                            <button href="/tracker/nwa/lab/add">
                              Let's get started!
                              <div className="" style={btnFill}></div>
                            </button>
                          </div>
                        </div>
                    </div> 
                </div>
            </div>


          </div>

              </div>
      </div>
  }
}

export default ConsolePage;

It just renders as a button that has no styles to it. If I leave out the ''s like so:

var btnFill = {
  background: linear-gradient(to right, #E040FB, #00BCD4)
}

react says this: Unexpected token, expected "," between to right.

Regards

1

2 Answers 2

2

Try this, it's working

const mystyle={
  background: 'linear-gradient(to right, #430089, #82ffa1)'
}

<div style={mystyle}>
    Linear Gradient
</div>

It seems you have not used text or something inside your div to which you are applying styling.

Sign up to request clarification or add additional context in comments.

1 Comment

-_-, totally looked over the div without anything there... Thanks this works!
1

You can't put a div inside a button, but you can put an image.

<img src="...." />

Or instead of a button, you can use a link

const btnFill = {
  backgroundImage: 'linear-gradient(to right, #E040FB, #00BCD4)';
}
<a style={btnFill} href="/tracker/nwa/lab/add">Let's get started!</a>

1 Comment

Thanks for this, I removed the div from the button and applied the style directly to the button itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.