SASS only recognizes classes with an ampersand symbol, the root class is not included

Can a sass/css class with an ampersand be used in conjunction with VueJS effectively? I've noticed that the CSS attribute assigned on the ampersand works, but the root element itself isn't detected by the browser.

<style lang="scss" scoped>
.curved-input {
  border-radius: 5px;
  height: 50px;
  margin-right: 1rem;

  &__lg {
    width: 300px;
  }

  &__sm {
    width: 150px;
  }
}
</style>

The browser appears to detect the width: 300px or width: 150px, but not the

border-radius, height, margin-right
attributes.

<input name="city" class="curved-input__lg" type="text" placeholder="Palau Ujong, Singapore"/>

The textbox width changes, but other attributes are not displayed when inspecting them in the browser tools. Am I overlooking something here?

My objective is to avoid coding it as

class="curved-input curved-input__lg
and instead only utilize curved-input__lg or curved-input__sm while inheriting the parent attributes (curved-input).

Answer №1

If you want to avoid cluttering your markup with additional classes or redundant code, you can utilize the @extend feature.

.curved-input {
  border-radius: 5px;
  height: 50px;
  margin-right: 1rem;
}

.curved-input {
  &__lg {
    @extend .curved-input;
    width: 300px;
  }

  &__sm {
    @extend .curved-input;
    width: 150px;
  }
}

This approach would result in the following CSS output:

.curved-input,
.curved-input__sm,
.curved-input__lg {
  border-radius: 5px;
  height: 50px;
  margin-right: 1rem;
}

.curved-input__lg {
  width: 300px;
}
.curved-input__sm {
  width: 150px;
}

Answer №2

The reason for this is that you must also define the curved-input class. Therefore, your class attribute should appear as

class="curved-input curved-input__lg"
.

If you were to write your CSS code in full, it would look something like this:

.curved-input {
   border-radius: 5px;
   height: 50px;
   margin-right: 1rem;
}

.curved-input__lg {
   width: 300px;
}

.curved-input__sm {
   width: 150px;
}

Keeping this in mind, it becomes clear that you need to include the curved-input class as well.

Answer №3

When attempting to format it in that manner, one suggestion is to modify the initial line as follows:

[class*="curved-input"]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Use JavaScript to jumble up each individual letter

Is there a way to scramble words letter by letter instead of the whole word at once in Vue.js? I'm new to Vue.js and struggling to make this change in my code. I'm currently using Vue.js for this task. const sampleText1 = 'インバウント ...

Tips for retrieving element height using Vue.js

I am attempting to retrieve the offsetHeight of an element but I keep getting undefined. When I use this code, it returns an HTML collection and everything works correctly: document.getElementsByClassName("plyr--full-ui"); https://i.sstatic.net/xurBa.pn ...

Explore a unique navigation bar using CSS hover effects

I am trying to create a navigation bar that displays a big block when hovered over, but unfortunately, it's not working as expected. Below is the HTML code I have written: <div id="outerContainer"> <div id="header"> ...

Using Vue to display a Div inside a TD element of a table does not result in a reactive behavior

I am encountering an issue with a table where the last column contains a div with three options (View, Edit, and Delete). This submenu is initially hidden, but when clicking on the options button in the last column of the table, the array used to control i ...

Ingress-nginx rewriting destination target

I have set up an nginx ingress for my front-end built in vuejs. apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: vuejs-ingress namespace: default annotations: cert-manager.io/cluster-issuer: letsencrypt-prod nginx.ingress.kubern ...

Body overflow appears horizontal in Windows Operating System while it works fine in macOS

After implementing the code below from a helpful CSS Tricks article, my element spanned across the full width of the page, stretching beyond its parent's boundaries: width: 100vw; position: relative; left: 50%; right: 50%; margin-left: -50vw; margin- ...

Steps to automatically show the keyboard when the page is loaded

Currently, I am working on a mobile application using NativeScript-Vue. One issue I encountered is that the keyboard does not automatically display when the page or screen loads. My goal is to have the keyboard show up without the user having to tap on the ...

I am eager to utilize emit in order to toggle between various page components

I currently have a Header and a Main page displayed on the Top page, along with three Tab functions in the Header component. My goal is to switch between displays A, B, and C on the Main page when I click on each corresponding Tab (A, B, C). I've been ...

Using PHPs nth-child in media queries

There are multiple images on MyPage, typically displayed in rows of 6. However, the number of images per row adjusts based on browser size using media queries. The issue arises with the margin set for the last image in each row, as the nth-child property r ...

Add a JSON file containing an image path as a value into a CSS background property

I currently have a MongoDB database containing documents with 'img' values structured as follows: "img": "../folder/img.jpg" Would it be feasible to utilize this string in my CSS for modifying the background image? This is essential because I n ...

Issue with background image positioning in IE 7 while scrolling

I am struggling with creating nested divs where the middle one has a fixed background image that remains static while the rest of the content scrolls. My solution works in Firefox, Chrome, and Opera but I'm encountering issues in IE7. Despite knowing ...

Ways to decrease the saturation of a background image within a div using CSS

I've come across many plugins that can desaturate an image within the tag. However, I haven't been able to find a solution for desaturating a background image that is used for an element (div). Is there a way to desaturate the background image ...

Issue encountered when utilizing properties in a Vue.js instance with vue-class-components and TypeScript

I am looking to create a global variable for my server's URL. In my main.ts file, I added the following line: Vue.prototype.$apiUrl = "http://localhost:3000"; Then, when trying to use it in my App.vue file: console.log(this.$apiUrl) The URL is disp ...

Having difficulties with the Sort() function

Having trouble with the sort() function when ranking data from the coinmarketcap api. It works fine with an ajax call, but not with axios as shown below. Check out my code using axios and vue.js: let coinMarket = 'https://api.coinmarketcap.com/v2/t ...

The font remains the same despite the <Div style=> tag

I have a script that loads external HTML files, but I am facing an issue with changing the font to Arial. The script is as follows: <script type="text/javascript"> $(document).ready(function(){ $("#page1").click(function(){ ...

In Laravel Blade, you can dynamically add rows and columns based on a certain condition

I'm working on creating a user interface for cinema seats in Laravel Blade. The database includes seat rows and columns, and the rows will be the same for two consecutive rows. For example, the first row could have an id of 1 with seat_row:1 and seat_ ...

Ways to eliminate the leading bullet point from an unordered list

I am currently working on creating a gallery of images using php and css. The images are placed in an unordered list as shown below: <ul style="list-style-type:none;"> <? while($data=mysql_fetch_row($result)) { $pic=$data[2]; if ($pic) { $ ...

Styling for elements containing any class or id in Css

Struggling with applying different styles to two image tags within one div tag? I attempted to use CSS to target the images individually, but it didn't work. Can someone help me correct my CSS code? This is how I tried to apply the CSS: div img { pa ...

Using CSS or Javascript, you can eliminate the (textnode) from Github Gist lists

My goal is to extract the username and / values from a series of gists on Github Gists. The challenge lies in the fact that there are no identifiable classes or IDs for the / value. https://i.stack.imgur.com/9d0kl.png Below is the HTML snippet with a lin ...

Develop a dynamic animation using gradient and opacity properties

I'm still getting the hang of HTML, JavaScript, and CSS but I recently made some changes to someone else's code to animate a gradient. The original code used background: rgb, but I switched it to background: rgba. It seems to be working fine, but ...