What is the reason my CSS formatting isn't being applied in Vue.js?

As a newcomer to web development and vue.js, I've been struggling to style my code effectively. Below is an example of my vue.js code where I have created markup for a profile description using figure, figcaption, and image elements. Could you please guide me on how to apply CSS styles to this code?

<!DOCTYPE HTML>
<html>
    <head>
        <title>v-if If Statements</title>
        <meta charset="UTF-8">
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <style>
            .special {background:yellow; border: 1px dotted #fe0000; padding:30px; display:block; text-align:center;}
            .important {font-weight:bold; font-size:30px;}

        </style>
    </head>
    <body>
        <div id="app">

<figure>
                <img v-if="profile.pic" :src="profile.pic">

                <div v-if="profile.fname && profile.lname">
                    Profile: {{profile.fname}} {{profile.lname}}
                </div>
                <div v-else>
                    No First or Last name found.
                </div>
                <figcaption>
                    <div v-if="profile.desc">
                        Desc: {{profile.desc}}
                    </div>
                    <div v-else>
                        No description found.
                    </div>

                    <div v-if="profile.bio">
                        Bio: {{profile.bio}}
                    </div>
                    <div v-else>
                        No bio found.
                    </div>
                </figcaption>
            </figure>
        </div>   
        <script>
            var app = new Vue({
                el: '#app',    
                data: {   
                    profile: {
                        fname: "Chris",
                        lname: "Picasso",
                        desc: "Student",
                        bio: "Web developer",
                        pic: "https://i.pinimg.com/custom_covers/222x/85498161615209203_1636332751.jpg"
                    }               
                }  
            });
        </script>

Answer №1

Where have you implemented the CSS? I seem to be missing something.

In order to style elements, you need to add classes like shown below. Alternatively, you can also do this programmatically. However, my knowledge of Vue is limited. I recommend checking the documentation for guidance.

<div v-if="profile.fname && profile.lname" class="important" >
    Profile: {{profile.fname}} {{profile.lname}}
</div>

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

In Bootstrap 5, the anchor tag is causing a shift in the background color of surrounding tags upon being clicked

Why does clicking on an anchor tag temporarily change the background of other tags that weren't clicked? What am I doing wrong? https://i.stack.imgur.com/ZKlUT.png Check out the code below: <nav class="navbar navbar-expand-lg navbar-light bg- ...

How to apply custom styling to a specific element within an Angular Material 2 component using CSS based on its Id or

My EntryComponent features a material button menu where I attempted to customize the default style using ::ng-deep. However, the changes affected all button components in the parent Component as well. <style> ::ng-deep .mat-button{ max-width: 50 ...

In the production and development environments, the interpretation of CSS classnames is being rearranged

Currently utilizing create-react-app v2. I've encountered an issue with a component that has multiple classnames: "x15 x14 login-form__field". Strangely, in the production build, the order of '.x14' and 'login-form__field' seems t ...

Styling with CSS Variables and Transforming Elements

After conducting thorough research both on this platform and via Google, I have yet to find a solution to my query: "how can CSS variables be utilized in a CSS transform?" Within the HTML header, three CSS variables and their fallback values are declared: ...

Express-minify is having trouble loading the CSS file. If we remove a portion of the file, it should be able

After implementing the express-minify middleware, I encountered an issue with loading the attached CSS file. Even after validating the CSS using an online service, no errors were detected. I attempted to debug by gradually removing elements, and the prob ...

Menu changes when hovering

I want to create an effect where hovering over the .hoverarea class will toggle the visibility of .sociallink1, .sociallink2, and so on, with a drover effect. However, my code isn't working as expected. Additionally, an extra margin is automatically ...

Discovering more about this topic

Looking for a way to create an expandable box that enlarges when "read more" is clicked, revealing text below it. And also looking to add a button that closes the expanded text back up. Experimented with the toggletext JavaScript command, as found on this ...

The jQuery script designed to verify the page height doesn't appear to be functioning as intended

Below is a snippet of jQuery code that I'm working with: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> hasVBar=""; hasHBar=""; $(docume ...

Maximizing Bootstrap's Potential: Achieving Right Alignment for Divs

I am facing a challenge with aligning my div in the layout_cshtml. Currently, it is aligned to the left and the search bar and dropdownlist are not displaying properly. This negatively impacts the user experience. Additionally, my navigation menu is not ...

Leverage scope variables and dynamic CSS properties when using ngClass

Is there a way to manipulate the CSS dynamically in HTML using a scope variable? <div ng-class="myClassScope, { 'dynamic-class': !ifIsNot }"> ...

The @media feature is not functioning properly

I am struggling with getting my media query to function properly on a school project. Despite carefully checking my code, I cannot figure out why it is not making the desired changes when viewed on a mobile device. If anyone has any suggestions or insigh ...

Experiment with a drag-and-drop interaction using vue-test-utils

I am interested in testing user interaction with drag and drop functionality on a DOM element. While Vue test utils offers the trigger method for events like click, such as wrapper.find('#someId').trigger('click'), I am having trouble ...

Dynamic data display issue in Vue with Chart.js

Seeking to utilize the reactive data mixin for vue-chartjs The mounted function for setting the initial data is functioning properly, and I can visualize the chart accurately with the API response: fetchSessionTrends() { axios.get(endpoint) .then ...

Is it possible to host static files alongside running an API on the server?

As a newcomer to web development, I find myself in unfamiliar territory as my friend and I delve into a project involving Vuejs, jade, stylus, and jeet. The combination of all these frameworks is overwhelming, especially since there seems to be no clear ex ...

What is the best way to position elements with CSS?

I need help aligning the arrows and images on the same line. Can anyone guide me on how to do this? (I'm using html5boilerplate). Desired Layout: Current Layout: Existing Code: HTML: <div id="linkbar"> <a><img src="./img/ar ...

Social media comments widget

Currently, I am incorporating the Facebook XML to implement a Facebook comments plugin within my MVC 3 application in the following manner: <fb:comments href="@Request.Url.AbsoluteUri" num_posts="15" width="900"></fb:comments> The issue lies ...

Exploring methods to test the use of custom CSS variables in VueJS

I am currently working on a VUEJS test and I need to access the style information. The component is being utilized in this manner: :style="background-color: var(--color)" The following methods are being used: wrapper.find('.avatar'). ...

JavaScript popup cannot be shown at this time

I'm encountering an issue with displaying popups using JavaScript. Currently, only the div with class "popup" is being shown. When a user takes action, both popup and popup2 should be displayed but for some reason, it's not working as expected. ...

Is there a way to horizontally navigate a pallet using Next and Prev buttons?

As someone new to development, I am looking for a way to scroll my question pallet up and down based on the question number when I click next and previous buttons. In my pallet div, there are over 200 questions which are dynamically generated. However, th ...

Enhance the appearance of div elements in GWT/HTML with custom styling

I am relatively new to GWT and have been exploring various options, but I have not yet found a solution to my issue. The challenge at hand involves developing a function schedule system in GWT, where I am working on designing the frontend. We currently ha ...