Difficulty encountered while using CSS to customize a vue template

I'm currently working on a login page and experiencing difficulty styling Vue templates using CSS.

Here is the code that works without Vue:

HTML

<body class="text-center">
    <form class="form-signin">
        <h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
        <div class="checkbox mb-3">
            <label>
                <input type="checkbox" value="remember-me"> Remember me
            </label>
        </div>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
        <p class="mt-5 mb-3 text-muted">&copy; 2017-2018</p>
    </form>
</body>

CSS

html,
body {
  height: 100%;
}

body {
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: center;
  align-items: center;
  padding-top: 40px;
  padding-bottom: 40px;
  background-color: #f5f5f5;
}

However, when I attempt to replicate this in a Vue template, it doesn't work as expected. This is due to the use of HTML and body tags in the CSS. How can I achieve the same styling result in a Vue template without referencing the html and body tags?

After following the recommended solution:

with vue

without vue

Although the styling has improved compared to before, it is still not fully functional. I have encountered similar issues in the past. Do you have any suggestions on how to resolve this?

Answer №1

We strongly recommend thoroughly reviewing the documentation on how Vue operates. In most cases, Vue is connected to div#app, meaning that when styling components, you cannot directly access the body and html tags. If it is necessary to apply styles to these tags, it is recommended to use an external CSS file linked to the HTML document. Avoid adding CSS directly in the index.html file as it may lead to confusion and difficulty locating specific styles later on.

In this scenario, there seems to be no compelling reason for modifying the HTML and body elements, as achieving the desired outcome can typically be accomplished within Vue without direct manipulation of these tags.

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

What is the most creative way you can think of to create a CSS/JS animated

Is using an animated SVG the best way to create these wavy blobs for mobile compatibility? What approach would you take? Here is a similar example I found var wave = document.createElement("div"); wave.className += " wave"; docFrag.appendChil ...

Determining the Size and Color of Squares in a Treemap Based on Content with D3.js

I encountered an issue with a treemap visualization. I came across an example that is similar to my situation, which can be viewed here: In the demo, you can see that the size of each square in the treemap is determined by the content size. However, all s ...

Removing the Bootstrap-container is a task that can be specifically targeted for larger screens

I need assistance with removing the container from my large screen while keeping it on small and medium screens. I have tried searching for a class like container-lg-none, but to no avail. Any help would be greatly appreciated. Here is the code snippet i ...

Converting text/plain form data to JSON using Node.js - step by step guide

I am currently working on a Node.js application to execute a POST call to an API for placing an order. However, the data I receive in our app is in text/plain format and not JSON. This is the current format of the data: TypeOrder=buy Coin=BTC AmountCoin= ...

Another option to replace the file_get_contents function

I am attempting to retrieve JSON data from the following URL: . When using the file_get_contents() function, I encountered the following error message: Error Message: require(): https:// wrapper is disabled in the server configuration by allow_url_fope ...

Troubleshooting Alignment Problem of Maximize and Close Icons in RadWindow Using ASP.Net

Currently, I am utilizing telerik radwindow to showcase a PDF document. The window seems to be functioning correctly, but there is an issue with the alignment of the maximize and close icons. Ideally, they should appear in the same row, however, they are b ...

Arranging progress bars between various nodes using HTML and CSS

I am currently facing a challenge in creating a stepping wizard form layout that features a bar at the top of the page. This bar displays a dynamic number of steps (nodes) and progress bars that connect these nodes. However, I am encountering difficulties ...

sent a data entry through ajax and performed validation using jquery

Is there a solution to validating the existence of an email value using ajax after validation work is completed? Despite attempting to check for the email value and display an alert if it exists, the form continues to submit regardless. See below for the ...

Tips on solving the "net::ERR_SSL_SERVER_CERT_BAD_FORMAT" issue while working with Vue.js and Node.js using HTTPS and Express

I encountered an issue while trying to send HTTPS requests in Vue.js using actions methods in Vuex. The console displayed the following error: GET https://localhost/api/getpeople net::ERR_SSL_SERVER_CERT_BAD_FORMAT Here is a snippet of my code: vue ...

Certain Android devices may experience compatibility issues with the web app

I am facing an issue with my webapp on Raspberry Pi, as it is not being recognized properly by all my Android devices. The server hosting the website is a Raspberry Pi 3 running Apache and everything is up to date. To protect privacy and security, all IP ...

Make the height of the input element equal to 100% of its parent

I am struggling with setting the height of input (type text) to fit 100% of its parent element (td). I attempted to individually adjust the height of each input using jQuery, but this method is time-consuming, especially since the site I am working on ha ...

What is the best way to turn off autocorrect in a textarea on IE11 without turning off spellcheck?

In my experience, disabling the spellcheck attribute seems to solve the auto-correct issue, but it also eliminates the underlining of misspelled words. <textarea id="TextArea1" spellcheck="false"></textarea> I prefer to keep spellcheck enabl ...

mobile-friendly sticky footer

Currently working on a website project utilizing Bootstrap 3 (http://www.patrickmanser.ch/fnws) and I am trying to implement a sticky footer. After adapting the code snippets from Bootstrap 3 examples according to my specifications, everything seems to fun ...

Modify PHP script to extract the Document Object Model (DOM) from a specified URL

Hey there, I'm currently using this code to extract and display the HREFs of all "A" tags from a URL. However, my output includes the entire link when I only want the name portion after http://twitter.com/namehere So, I'm looking to clean up my ...

creating a table displaying data in a horizontal format sourced from ajax/json transformation

I am currently working on a piece of code that retrieves a list of IDs from local storage and compares them to IDs in a JSON file. If there is a match, the corresponding data is displayed in a table. However, I am facing an issue with my table layout as i ...

I haven't quite mastered the art of styling and JavaScript, but I'm currently focused on creating an HTML form with

I attempted to create a button, but it's not functioning correctly. It should display 'Submit', but instead, it just shows a square. Since I haven't learned CSS yet and my online video instructor hasn't covered it either, I need as ...

Creating consistently sized rows of Bootstrap columns - with either equal heights or equal spacing between each row

It would be great if bootstrap had a built-in feature where it automatically assigns the wrapper div of any item with a height based on the height of the largest div. In this example on JSFiddle, you can see that I have different heights for the video-ite ...

Observing nested data changes in Vue.JS?

In my Vue.js components, I have a group of checkboxes that are sending data to the parent element. My goal is to monitor this data for changes and use it to filter information in an API call. When certain checkboxes are selected, the data stored on the pa ...

Inconsistent behavior between Vue.JS and Rails-UJS / Jquery-UJS causing issues with Vuex mutations

During a tutorial, I noticed that two of my view mutations (addCard and addList) are working fine, but the third mutation (editCard) is not functioning properly in Vue. When I attempt to edit a card, the changes are saved correctly in Rails but do not upda ...

The Bootstrap Modal will still appear even in the presence of a validation error

Recently, I created a sign-up page using HTML and Bootstrap 5. To ensure data validation on the form, I integrated Bootstrap's validation feature. However, after completing the registration process, a modal pops up as intended. The only issue is that ...