0

Let's say I have a Test.vue with 2 v-text-field components.

I want to apply my CSS only to the first text field.

Test.vue

<template>
  <div class="test">
    <v-text-field></v-text-field>
    <v-text-field></v-text-field>
  </div>
</template>

<script>
export default {};
</script>


<style scoped>
.v-text-field {
  width: 100px;
}

.v-text-field >>> input {
  font-size: 2em;
  color: #fff;
}

.v-text-field--outlined >>> fieldset {
  color: #000000 !important;
}
</style>>

 

2 Answers 2

1

How about to use the first-child CSS selector

<style scoped>
.test:first-child {
  width: 100px;
}

.test:first-child >>> input {
  font-size: 2em;
  color: #fff;
}

.test:first-child .v-text-field--outlined >>> fieldset {
  color: #000000 !important;
}
</style>
Sign up to request clarification or add additional context in comments.

2 Comments

Okay, but if it's meant for the second child or the 100th child?
:first-child === just the first child :nth-child(n) for nth child
1

There are a lot of ways to do this, but I think it would be best to simply give your specific text field an id and reference that.

<div class="test">
    <v-text-field id="my-text-field"></v-text-field>
    <v-text-field></v-text-field>
</div>
#my-text-field {
    //your styling
}

6 Comments

I tried that, but how does that work with the styles I mentioned above?
Can't you simply replace .v-text-field with #my-text-field? Or does that not work?
Also note that if you want to use Raeisi's solution for any nth child. There happens to be a nth child selector
If you are trying to change the text color of the text that the user writes in v-text-field, just put it in the first-level css. You don't need to use deep selectors >>>
Thanks. The n-th child solution does work, although I don't like it because you have to adjust the n when adding components above your text field.
|

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.