-5

Have created a button in HTML and then added some style on it by CSS with some border effects and some others, but when i tried to change background color or the color of text it didn't worked and I had to do it by adding some style on HTML file. Does anyone knows why background and color couldn't be changed but other effects as border etc worked?

.button1 {
  float: none;
  height:20px;
  width:50px;
  background-color:blue;
  color:black;
  border-style: outset;
}
<hr>
<div class="button1">
  <button type="button" style="height:70px; width:230px; color:red; background-color: yellow">Click Here</button>
</div>

Button

enter image description here

adam08
  • 3
  • 5
  • 3
    Please post code, not screenshots... – Kevin Kopf Nov 06 '18 at 01:10
  • It's likely a caching issue. Try `CTRL + SHIFT + R`. Posting the code would help us debug it further. – Obsidian Age Nov 06 '18 at 01:12
  • Please explain what is it that you're trying to achieve? What color you want the background-color and text to be? – josephting Nov 06 '18 at 01:35
  • Show what you tried that didn't work, not the code that works. – Barmar Nov 06 '18 at 01:42
  • @josephting I want to change background color of button and text color by adding some styles on Style.Css and not have to do add style on html file where's button, – adam08 Nov 06 '18 at 13:16
  • Another update:: The problem was that another background is created and that's why effect didn't worked because have added some border-radious on CSS yesterday but then removed it and now when I update background color on CSS file it updates the border not the background of button and I have no idea how to remove it because there's not any border style on CSS file to get rid of it. Images below show CSS file and button preview with background color http://prntscr.com/lf1d70 http://prntscr.com/lf1e1l – adam08 Nov 06 '18 at 13:46

2 Answers2

0

In your code you set the color of the test to be red. Because it is "inline" on in the line of HTML it will override any css

<button type="button" style="height:70px; width:230px; color:red; background-color: yellow">Click Here</button>

if you remove the inline color: red you can now cast a color from your css. This is also why some effects worked and others did not - they are not predefined inline and only in your css class.

In short the order of casting goes inline > css

Nick
  • 138,499
  • 22
  • 57
  • 95
MrBabbels
  • 29
  • 6
  • I had to add a color in html file because when I added background-color on CSS it didn't had any effect and it worked by html file and now removed background-color in html file and added background-color; on CSS but it's again the same that background color doesn't update? – adam08 Nov 06 '18 at 13:26
  • Another update:: The problem was that another background is created and that's why effect didn't worked because have added some border-radious on CSS yesterday but then removed it and now when I update background color on CSS file it updates the border not the background of button and I have no idea how to remove it because there's not any border style on CSS file to get rid of it. Images below show CSS file and button preview with background color http://prntscr.com/lf1d70 http://prntscr.com/lf1e1l – adam08 Nov 06 '18 at 13:44
0

Target the button and style it.

//one out of many solutions: you can give the button an id
<button id="whatever">click here</button>

//then style it using the id

#whatever {
   background-color: yellow;
   color: red;
}
  • yes i've added an id class to the button but still color and background of button cannot be changed but other styles as border radius etc works.
    – adam08 Nov 06 '18 at 13:18
  • Another update:: The problem was that another background is created and that's why effect didn't worked because have added some border-radious on CSS yesterday but then removed it and now when I update background color on CSS file it updates the border not the background of button and I have no idea how to remove it because there's not any border style on CSS file to get rid of it. Images below show CSS file and button preview with background color http://prntscr.com/lf1d70 http://prntscr.com/lf1e1l – adam08 Nov 06 '18 at 13:46
  • Your button is inside a div with class set to button1. So you are giving the div the background-color, not the button. – Abubakar Sambo Nov 07 '18 at 05:45
  • how to give the div to the button not the background ? – adam08 Nov 07 '18 at 12:22
  • okay remove the background you set on the .button1 class, then declare another style: `.button1 > button {background: yellow;}` . That should do it for you. You could also add some padding if you want the button to appear larger. – Abubakar Sambo Nov 07 '18 at 13:01
  • Submit this one worked as i searched in google and the problem was as you said that i was giving the background the class, thank you – adam08 Nov 07 '18 at 14:09