Find html element in css

Asked

Viewed 577 times

3

I need to find a specific element of what is in my html code only in css, exemplifying:

It’s like:

meuElemento [type=input]{
    color: #FFFFFF;
}

Only the doubt is on how I find an element like id="textoUm" of my html by ID, not just to pick up and do [id=textoUm].

How can I do that? I’ve searched several websites and I haven’t been able to.

2 answers

4


Using the attr css would look like this: (note the attr construction [id="textOne"])

[id="textoUm"] {
 border: 2px solid red;
}

input { 
 border: 2px solid black;
}
<input type="text" id="textoUm" value="com ID">
<input type="text" value="sem id">

OBS: But if you will put the css using the ID you don’t have to use the attr[] directly create the class #textoUm {seu css}

When you put the style on ID has to start the name by #textoUm {} and when it creates a style to class has to start the name by .textoUm {}

Mozilla documentation link about css attr https://developer.mozilla.org/en-US/docs/Web/CSS/attr is in PT and will help you worth reading

  • Thanks, that’s right, but I guess I wasn’t hitting the syntax, like I was trying to put in a p there was so p [id=textoUm]{ you can’t make this kind of selection?

  • Yes! But that would be right p[id="textoUm"] with P with no [ space and ID value between quotation marks id="textOne"

  • 1

    Pow, thanks for the help That’s what I wanted.

  • @Groot dmr tmj!

3

When you want to use with id or class is simpler

Example with id:

#textoUm{
    color: #FFFFFF;
}

Example with class:

.textoUm{
    color: #FFFFFF;
}

Or if you want something like, an input with class 'textUm' for example, you can do so:

input.textoUm{
    color: #FFFFFF;
}

Or with some id:

input#textoUm{
    color: #FFFFFF;
}

A small example:

.texto{
  color: #f00;
}
#texto{
  color: #00f;
}
input.texto{
  color: #0f0;
}
input#texto{
  color: #ff0;
}
<input type="text" value="teste" class="texto" />
<input type="text" value="teste" id="texto" />
<div class="texto">teste</div>
<div id="texto">teste</div>

  • Yeah, but there’s no way to do it the way I put it?

  • 1

    Our hugocsl friend, posted an answer the way you wish

  • 1

    Vlw the young consideration!

Browser other questions tagged

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