What impact does including lang=less in a Vue component's style have on its behavior?

Exploring ways to scope the CSS of my Vue component, I initially considered using less to encapsulate my styles. However, after discovering the scoped attribute as the recommended method, I realized that my approach needed adjustment.

In my original setup, the CSS section looked like this:

<style>
    #weather {
        display: grid;
        grid-template-columns: repeat(8, 1fr);
        grid-template-rows: auto auto auto;
        text-align: center;
        grid-column-gap: 5px;
    }

    .hour {
        font-family: 'Open Sans', sans-serif;
        font-size: 20px;
        font-weight: bold;
        justify-self: start;
        padding: 0 5px 0 5px;
        color: white !important;
    }
    .date {
        font-family: 'Open Sans', sans-serif;
        font-size: 30px;
    }
    .today {
        grid-column: 1 / 5;
        font-weight: bold;
    }
    .tomorrow {
        grid-column: 5 / 9;
    }
</style>

Updating the first line to <style lang=less>, I expected no visible changes at first. I assumed less would be compatible enough with CSS that using it without specific features would leave the styles unchanged.

However, this was not the case, as my page layout became disturbed. DevTools revealed a discrepancy:

https://i.sstatic.net/6H8JE.png

It appeared that the display property was no longer recognized as grid, causing unexpected behavior with grid-column.

What exactly changed by adding lang=less to <style>? And why did the CSS behavior alter without any modifications to the code?

Answer №1

To avoid Less from compiling 1 / 5 to 0.2, it is recommended to utilize the e function for the grid-column value.

.today {
        grid-column: e("1 / 5");
        font-weight: bold;
    }
    .tomorrow {
        grid-column: e("5 / 9");
    }

Alternatively, you can achieve the same result with the following code:

.today {
    grid-column: ~"1 / 5";
    font-weight: bold;
}
.tomorrow {
    grid-column: ~"5 / 9";
}

For further details, please refer to the Escaping section in Less.

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

The MarkCompactCollector was unsuccessful in promoting the young object due to a failed allocation process

After successfully cloning a Git repository that houses a Vue project using the command git clone, I proceeded to run npm install in order to install all necessary dependencies, resulting in the creation of the node_modules folder. However, upon executing ...

Is it possible to use CSS transitions to animate an absolute positioned element?

I am having trouble getting a CSS transition to work for animating an element's position change. I have tried using the all properties in the transition declaration like in this example: http://jsfiddle.net/yFy5n/3/ However, my goal is to only apply ...

Looking for solutions to manage mouseenter, mouseleave events and ensuring content dropdowns stay visible in Vue.js 2?

Hey there, I'm trying to figure out how to keep dropdown content from disappearing when using @mouseenter and @mouseleave. Here's what I have so far: <div class="wrapper"> <div class="link" @mouseenter="show = ...

Hide the element once the CSS animation has finished

I have successfully implemented an animation using pure CSS that starts on load. However, I am facing an issue with both opacity and visibility as the div continues to take up space even when hidden. Question Is there a way to make the div disappear comp ...

Tips on building a blog using solely index.html, style.css, and script.js files

Looking for inspiration for blog listing pages? Check out some examples like: HubSpot's marketing blog or iGoMoon's blog. I'm trying to figure out where I should start. Should I begin with the first line of code? Or can I import sample code ...

Using Vue.js to dynamically append a bound URL

Within my Vue template, I currently have the following code: <img class="workimg" v-bind:src="item.imagemobile"> I am considering appending it to: <img class="workimg" v-bind:src="/featured/item.imagemobile"> However, this syntax seems to b ...

Implement a vertical scrolling animation in datatables

I am trying to utilize datatables to display all data. My goal is to have the data automatically scroll row by row every 3 seconds. This is my code, and you can also check it out on jsfiddle The intention is to showcase this data on a large screen. < ...

Utilizing props to define the background-color of the '&:hover' state

I'm adapting Material UI's Chip component to accept custom values for the colors prop, rather than being limited to "primary" and "secondary". Additionally, I want the chip to exhibit a hover effect when clicked, transitioning to a different colo ...

Display an icon before an active v-list-item in Vuetify 3's v-list

I need help figuring out how to add an icon to a v-list-item only if it is active. <v-list class="px-15 pt-5" border density="compact"> <v-list-item v-for="(item,i) in items"> <!-- Need assistance putting ...

Issue with drop-down menu functionality on mobile-friendly website

After deciding to revamp my website for responsiveness, I encountered an issue with the menu not displaying on smaller screens. Everything else is functioning correctly except for the drop-down menu! Here is the HTML code: <!doctype html> <html ...

Eliminating the standard padding on a Vuetify v-app-bar

When using Vuetify's v-app-bar, there are default css classes named v-toolbar__content and v-toolbar__extension that apply padding of 16px on the x-axis and 4px on the y-axis, which I aim to eliminate. I attempted to override these classes in my CSS ...

Modifying the color scheme of the table background and text

After finding a code example online to assist with creating a table in my project, I am faced with the challenge of changing the background color of the white rows to match the dark blue used for others. Additionally, I cannot figure out how to change the ...

Guide on positioning an SVG button within a form

I am attempting to design a form with two input fields and a button. Rather than using a plain text button, I prefer to utilize an SVG graphic for the button; however, it is not aligning correctly. Consider the following HTML and CSS: body { backg ...

Tips for maintaining the fixed size of a table header and preventing it from resizing in width

My goal was to create a table using divs with fixed headers while scrolling vertically. However, I encountered an issue where the header width seemed to shrink and became misaligned with the rows. Even setting the width to 100% did not resolve this probl ...

Both Fluid and Fixed layouts offer different advantages and disadvantages for website

Is there a way to position two divs side by side, where one div is 75% width and the other is 25% width? Additionally, can we place another div on top with margin:0 auto; to center the content of the page with a width of 986px? Here is an example code sni ...

Unique and responsive grid styling with CSS

Is it possible to create a responsive grid like the one shown in the image below? I attempted to use absolute positioning for all blocks, but I'm having trouble making it responsive... I should note that the styling will be generated dynamically usi ...

Tips for keeping Sub Menu visible at all times

Is there a way to keep the sub menu always visible on the homepage of my website's navigation? Thank you for your help! Check out my website here ...

Nuxt3: sending a user's submitted value from a registration form

I'm facing an issue in my Nuxt3 application where I need to pass the input value from an email field in a child component (SignForm.vue) to the parent component (signup.vue) for user registration. signup.vue <script setup> const props = { ...

Guide on creating a darkening effect for lights

Seeking assistance on how to create a light-off effect when clicking on any of my textboxes. I discovered this concept on the following website: What I aim to achieve is that upon clicking a specific textbox, it will be highlighted. Upon clicking the sam ...

Is there a way for a component to remove itself in Vue 2.0?

Can someone help me with this issue? The official documentation only mentions that $delete can use arguments 'object' and 'key' However, I am trying to delete a component by itself using the following code this.$delete(this) ...