Vue JS does not properly display grid-template-areas

Feeling a bit lost as I copied the style from a previous project that worked flawlessly. Currently using VueJS and encountering issues with the grid-area template not displaying properly in the initial app. Despite searching through similar questions, I haven't found any helpful results. Any assistance would be greatly appreciated!

<template>
  <div id="app">
    <search-bar></search-bar>
    <history-cont></history-cont>
    <video-view></video-view>
    <bookmarks-cont></bookmarks-cont>
  </div>
</template>

<script>
import Bookmarks from './components/Bookmarks'
import History from './components/History'
import SearchBar from './components/SearchBar'
import VideoView from './components/VideoView'

export default {
  name: 'App',
  components: {
    'bookmarks-cont': Bookmarks,
    'history-cont': History,
    'search-bar': SearchBar,
    'video-view': VideoView
  }
}
</script>

<style>
#app {
  display: grid;
  grid-template-rows: 55px 1fr;
  grid-template-columns: 240px 1fr 240px;
  grid-template-areas: "history-cont search-bar bookmarks-cont"
                       "history-cont video-view bookmarks-cont";
}
</style>

Attempting to replace the grid-template-areas names with the imported component names didn't yield the desired result:

grid-template-areas: 
"History SearchBar Bookmarks"
"History VideoView Bookmarks"

In my previous app, this solution worked, but following the suggestions below, I tried:

#app {
  display: grid;
  grid-template-rows: 55px 1fr;
  grid-template-columns: 240px 1fr 240px;
  grid-template-areas: "history-cont search-bar bookmarks-cont"
                       "history-cont video-view bookmarks-cont";
}

#app > #search-bar{
  grid-area: search-bar;
}

#app > #history-cont{
  grid-area: history-cont;
}
#app > #video-view{
  grid-area: video-view;
}
#app > #bookmarks-cont{
  grid-area: bookmarks-cont;
}

Despite all attempts, the issue persists. The following approach also did not work:

#app > bookmarks-cont{
  grid-area: bookmarks-cont;
}

Answer №1

Using ids as selectors for grid areas requires assigning those ids to each individual component.

Once you correctly place each id on every element, the functionality starts working:

<template>
  <div id="app">
    <search-bar id="search-bar"/>
    <history-cont id="history-cont" />
    <video-view id="video-view" />
    <bookmarks-cont id="bookmarks-cont" />
  </div>
</template>

View the implementation here: https://codesandbox.io/s/fancy-cookies-p68ei?file=/src/App.vue

Alternatively, you can adjust your selectors to match the elements you want to style.
That's a fundamental principle of CSS :)


Important: The strings used in the parent's grid-template-areas property must precisely match those in the children's grid-area property exactly. Vue does not automatically convert them from camelCase to kebab-case, unlike attributes or component names.

To clarify, this particular issue is independent of Vue and would behave consistently in plain HTML + CSS, React, Angular, or any other framework.

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

Revamp the website to create a more streamlined and compact version that mirrors the functionality of the desktop website

My goal is to make my website responsive on all mobile devices. I want the mobile version to look exactly like the desktop version, just smaller in size. I attempted using transform but it didn't have the desired effect. I aim to achieve the same con ...

Is it possible to create rounded or curved top corners for a box using HTML?

I'm looking to create a card with rounded top corners and wondering if there is a way to achieve this. Currently, here is the code I have: <div id="card1"> <div id="card1i"></div> </div& ...

New line displaying pagination for Bootstrap datatable

I am currently utilizing the datatable feature with bootstrap version 4.3.1. The necessary CSS and JS files have been integrated as shown below: <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script> <script ...

Encountering an unforeseen issue with my code

I am currently developing a web application in advanced Java and incorporating various external libraries such as choosen.js, summernote.js, Bootstrap, BootstrapValidator, etc. I have encountered some errors and am struggling to pinpoint the root cause of ...

Arrange the menu items in a column layout based on a given condition

Can someone assist me with displaying the menu subitems? I have created a plunker. Take a look at it to understand what I need (open plunker in full screen) https://plnkr.co/edit/IMEJFPfl5kavKvnUYaRy?p=preview In the plunker above, there are two dropdown ...

Steps to position the dropdown scrollbar to the top every time it is opened

I am working with a unique drag-and-drop multi-select dropdown that only has a unique control ID. The issue I am facing is that when the dropdown is initially opened, the scroll bar is at the top. However, after scrolling down and closing the dropdown, the ...

Hover and Click Card Turning

My card can both hover and click, but there seems to be a small glitch. After clicking on the card and then moving the cursor away from the front, the hover effect doesn't work correctly. It immediately flips back to the front side. The hover effect ...

List on the Left Side with Scroll Capability

In my ASP.NET web application that targets .NET 3.5 and utilizes an AJAX asp:UpdatePanel, I have structured the page layout using multiple div elements to divide the vertical space into sections - header, first content, second content, third content, and f ...

VUE 3 inexplicably failing to display the custom component's template, console remains error-free

I am utilizing flask, html, js for building a web application. I am currently facing an issue where the template defined in the component <add-movie> within movies.js is not being rendered into add_movies.html. The add_movies.html extends base_admin ...

Tips for organizing the contents of nested items in alignment

Here's a layout I've created, you can view it on CodePen. .parent { display: flex; justify-content: space-between; } .left { flex-grow: 1; flex-basis: 0; background-color: blue; } .right { background-color: red; flex-grow ...

Obtain the rotational value in 3D CSS using JavaScript by extracting it from the matrix3d()

My element has been 3D transformed in the following way: .foo { transform: rotateX(-30deg) rotateY(35deg); } Now, I am looking to retrieve these values using JavaScript. Extracting the 3D matrix is simple: var matrix = $('.foo').css('tr ...

I am having trouble with my custom-button class not successfully overriding the btn background color property. Can anyone provide insight

Utilizing the bootstrap5 variant-button mixin, I aim to create a custom-colored button. While I have successfully altered the default hover effect color, I am encountering difficulty in setting the background color of the button itself. Upon inspecting the ...

What steps can be taken to create a curved bottom for the header section?

While I've seen this question asked before, I'm not satisfied with how the design has been implemented. Here is my desired look for the curved header I've experimented with border radius left and right, but the edges are excessively rounde ...

Dynamic content cannot have classes added to them using jQuery

When adding content dynamically, it is necessary to use an event handler for a parent element using on(). However, I am facing an issue where the class added with addClass on dynamically generated content disappears immediately. Let's take a look at ...

"I can't figure out why my footer keeps showing up at the top of the page unexpectedly

Currently, my footer is showing up at the top of the page but I really want it to be at the bottom. I'm new to HTML so apologies if this is a simple fix. Here is my file with internal CSS: .middle { position: fixed; top: 50%; left: 50%; tr ...

The view named 'HelloWorld' could not be found within the servlet named 'dispatcherServlet'

I have recently started learning Spring Boot. My goal is to display an HTML page, but unfortunately I am facing some issues. When I change HelloWorld.html to HelloWorld.ftl, I am able to display the FTL page. However, the vue.js file is not being resolve ...

Using a function that is passed down from a parent component into a child component

One of my components has a parent-child relationship: <select-school-type placeholder="Filter by school type" @selected="getSchools"></select-school-type> I want the "getSchools" method to be triggered when the user changes ...

Reorganizing DIV elements on-the-fly

I've recently delved into the world of html, css, and javascript with the hopes of creating my very own news website. However, I've come across a puzzling problem: My vision is to have 10 div blocks on the homepage, each containing a headline wi ...

Tips for stopping variables from leaking in JavaScript

I'm currently working on a JavaScript code for my task manager website. Each page has its own JS file, but I've noticed that the data saved in one file seems to leak over to the others. How can I contain these variables so that tasks don't s ...

Gradually conceal the final column of an HTML table with the combination of CSS and JavaScript

My challenge involves modifying a table on Sharepoint with responsive design in mind. The goal is to hide the last visible column in the table based on the screen's width. For instance, if a user creates a 10-column table and the screen size is 1200p ...