6

I'm having problems defining body's background color, using Angular 2. I've tried change html, body, container-fluid colors, but it does not change. I also changed html and body in my app.component.css, but it did not work.

The rest of my css is ok, so the browser got the stylesheet

app.component.html:

<jogo></jogo>

app.component.css:

html, body{
    background-color: pink;
}

jogo.component

<div class="container-fluid" *ngIf="showPlay">
    <div class="row">      
     <div class="col-xs-8 col-md-8 col-lg-8c">
            <p align="center">
                Qual é<br/>a<br/>Música?
        </p>
     </div>
    </div>
  <div class="row">
    <div class="col-xs-4 col-md-4 col-lg-4"></div>
        <div align="center">
            <button type="button" class="rounded-circle">Play</button>
        </div>
  </div>    
</div> 
<div class="container-fluid" *ngIf="showJogo">
  <div class="row">
   <div class="col-xs-3 col-md-3 col-lg-3" id="tocador">
        Segunda
        <audio controls>
            <!-- caminho devera ser trocado pelo do firebase? -->
            <source src="/assets/Queen - Love of My Life.mp3" type="audio/mpeg">
            Your browser does not support the audio element.
        </audio>
   </div>
</div>
<div class="row">
    <div class="col-xs-3 col-md-3 col-lg-3" id="pontos">Pontos</div>
</div>
<div class="row">
    <div class="col-xs-3 col-md-3 col-lg-3" id="tempo">Tempo</div>
</div>
<div class="row">
   <div class="col-xs-3 col-md-3 col-lg-3" id="pergunta">Pergunta</div>
</div>  
</div>

jogo.component.css:

body{
    background-color: pink;
}
p {
    font-family: 'Lobster', cursive;
    font-size: 3.0em;
    color: #990000;
    /* Rotate div */
    -ms-transform: rotate(7deg); /* IE 9 */
    -webkit-transform: rotate(7deg); /* Safari 3-8 */
    transform: rotate(-12deg);

}
button {
    background-color: #990000;
    color: #F0D1B7;
    font-size: 1.5em;
    border: none;
    border-radius: 35px;
    width: 10%;
}

CSS NOT APPLIED AT BODY TAG: CSS NOT APPLIED AT BODY TAG

STYLESHEET LOADED: enter image description here

4 Answers 4

16

Angular creates Shadow Dom for applying styling to different components.

To apply styling to root elements, we can use style.css in the root folder.

style.css

html, body{
    background-color: pink;
}
Sign up to request clarification or add additional context in comments.

Comments

0

You're using Bootstrap, so the container-fluid fills the whole screen. Try to give the element background-color with !important , you just create a new class for the main container, gives background-color with !important to override the container fluid. I think it should work

Comments

0

Bootstrap has a style for body so depending on your loading order.

Your style might be getting overridden by the Bootstrap default background-color of #fff (white);

You can load your local CSS after the bootstrap CSS.

Or add !important to your style (usual not a good practice).

Comments

0

Angular scopes component styles to the target components, so any selector targeting elements outside the component will not get applied. For instance, .tout {color: yellow} will get translated to something like .tout[_ngcontent-kls-c1] {color: yellow}. In the same way, body {background-color: pink} will get translated to something like body[_ngcontent-kls-c1] {background-color: pink} So you need to put your global styles in a global stylesheet like src/styles.css

Comments

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.