Pseudo Class in CSS Does Not Apply Rule

Asked

Viewed 57 times

2

I’m making a CSS to control the printing of a page.

The only thing I’m going to show in print is an image that’s on the page.

So in CSS I did like this:

*:not(#imagem-draw){
   display: none;
}

But the result is that it shows nothing. How can I do this with CSS ?


<div id="content" class="colorir">
    <div class="main">
        <div id="draw-action">
            <div id="desenho">
                <img src="img/imagem.png" alt="" class="desenho" id="sketch-draw">
            </div>
        </div>
    </div>
</div>
  • Try body *:not(#imagem-draw).

  • Then I switched to this, but the screen went blank.

  • Post the HTML code in the body of the question.

  • Very large. Not necessary... has a lot of element and an image in the middle. <img src="img/imagem.png" alt="Seu Desenho" class="desenho" id="sketch-draw">

  • Because then, do not post the whole code, but I need to see the hierarchy until you get to the image, there is no way to mount a CSS without knowing the structure of HTML.

  • I posted the hierarchy.

Show 1 more comment

1 answer

3


This happens because you are also hiding the parent elements of the image, you have to create a rule for each to not hide them:

body > :not(#content),
body > #content > :not(.main),
body > #content > .main > :not(#draw-action),
body > #content > .main > #draw-action > :not(#desenho),
body > #content > .main > #draw-action > #desenho > :not(#imagem-draw){
   display:none;
}
<div id="content" class="colorir">
    <div class="main">
        <div id="draw-action">
            <div id="desenho">
                <img src="//placeholdit.imgix.net/~text?txtsize=33&txt=Sketch+Draw&w=200&h=200" alt="" class="desenho" id="sketch-draw" />
                <img src="//placeholdit.imgix.net/~text?txtsize=33&txt=Imagem+Draw&w=200&h=200" alt="" class="desenho" id="imagem-draw" />
                <p>Teste</p>
            </div>
            <p>Teste</p>
        </div>
        <p>Teste</p>
    </div>
    <p>Teste</p>
</div>
<p>Teste</p>

  • Got it. It’s true. I put it in my CSS file, but at the time of printing, white screen. Rs

  • Check that the image ID is correct, because in the code of your question, the ID in CSS is one and in HTML is another. Also check that there is no other element in the middle of the hierarchy that is being hidden. Test by changing the background colors to see how far it’s showing @Diegosouza

  • The ID was right, is that I typed in the hand instead of copy and paste, so I do not put the ID that is in the HTML. I will try again soon.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.