What is the best way to remove the box-model from an element?

Within my VueJS project, I am faced with nested elements that are generated dynamically like this:

<container>
  <outerElement class="outer" v-for="obj in objects">
    <innerElement class="inner" v-for="element in obj"/>
  </outerElement>
</container>

The issue arises when styling these elements using CSS. As the innerElements need to be movable, they require the outer element to match the size/position of the container.

Is there a way in CSS to eliminate the box-model from the 'outer' class while still being within the container?

Here's an illustration of what I am attempting to accomplish. https://i.stack.imgur.com/MGlD4.png


UPDATE:

To address the mentioned XY-Problem, here is a simplified version of the template, utilizing the same implementation techniques as in my application.

... (omitted for brevity) ...

However, the current issue in this code is that the innerElements cannot be moved inside the container because the outerElement serves as their container.

As changing the parent selector to utilize the container instead of the outerElement seems challenging, I am struggling to find a solution.

Therefore, I considered removing the borders of the outerElements to allow the innerElement to use the container as its parent.

But upon reflection, my approach may seem unconventional, especially considering that the vue-draggable-resizable component will naturally consider the outerElement as the parent.

Take a look at this snapshot showcasing the dilemma: https://i.stack.imgur.com/59AqF.png

The draggable boxes remain restricted from moving inside the container due to the outerElement not inheriting the position and size of the container.

Answer №1

To enhance your design, consider utilizing the CSS property display:contents on the outer component. This approach effectively conceals the element from the browser interface, providing a seamless user experience.


Alternatively, optimizing your Vue template by eliminating the unnecessary outer component may yield better results. One strategy could involve consolidating child elements within the objects array before iterating through them.

Answer №2

To simplify your example, you can flatten the nested array before iterating over it:

<container>
  <innerElement class="inner" v-for="element in objects.flat(1)" />
</container>

The more complex example you provided requires a bit more work since the inner loop also needs access to obj. However, you can achieve this by creating a custom method that wraps each state within a wrapper containing both the state and a reference to its object:

<div class="container">
  <div class="label" v-for="obj in nestedObj.data" :key="obj.name">
    <button @click="nestedXOR(obj.name)">XOR -> {{ obj.name }}</button>
    {{ obj.states }}
  </div>

  <vue-draggable-resizable
    class="inner"
    v-for="wrapper in flattenStates(nestedObj.data)"
    :key="wrapper.key"
    :resizable="false"
    :w="100"
    :h="50"
    :parent="true"
  >
    <div v-if="wrapper.obj.contentType === 'TypeA'">
      <b>{{ `Bit-${wrapper.index} of ${wrapper.obj.name}` }}</b>
      <br />
      <status-indicator :status="wrapper.state ? 'positive' : 'negative'" />
    </div>
    <div v-else>
      <b>{{ `Bit-${wrapper.index} of ${wrapper.obj.name}` }}</b>
      <br />
      <status-indicator :status="wrapper.state ? 'active' : 'intermediary'" />
    </div>
  </vue-draggable-resizable>
</div>

In order for the code above to function properly on browsers that do not support .flat() or .flatMap(), consider using a polyfill. Alternatively, you can streamline the template by incorporating some logic into the flattenStates method.

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 tailwind, the position transition does not work as expected

I have a React component that I'm working on: function DivModal() { const [isOpen, setIsOpen] = useState(true) return ( <div> <button onClick={() => setIsOpen(prev => !prev)} className={buttonStyle}>Open</button> ...

The flexbox layout is not properly stacking div rows in a column

Objective: Creating a flexbox layout with a responsive background image that adjusts in height when the screen size changes, causing elements to wrap; In addition, there is a fixed header bar at the top of the page. The layout consists of a full-screen co ...

Sending information from a parent component to a nested child component in Vue.js

Currently, I am facing a challenge in passing data from a parent component all the way down to a child of the child component. I have tried using props to achieve this as discussed in this helpful thread Vue JS Pass Data From Parent To Child Of Child Of Ch ...

Why is my client program not receiving a response from this socket.io server?

Currently, I am in the process of developing a trivia game where two users engage in answering questions with the winner being declared at the end. As part of this project, I have integrated socket.io to facilitate the exchange of answers. However, I have ...

What's the issue with the addClass function not working as expected?

I am currently integrating the website's navbar using PHP, which is why I am unable to use class="active" to highlight the active tab on my navigation bar individually. To solve this issue, I attempted to add the active class to the corresponding tab ...

What is the best way to access a component's value from a different component in Vue script?

I have two Vue components in my PHP file: "application" and "vn" component. I am trying to fetch {{obj.vacancies_left}} from the "vn" component and use it in the "application" component. However, I keep getting an undefined variable error. I attempted to r ...

the absence of any content being shown when using v-else

I'm currently delving into Vue.js and stumbled upon an unusual behavior that I couldn't find any information about on the Internet. For some reason, the DIV with v-else isn't rendering any content that I place inside it. I tried to underst ...

Dealing with a checkbox click event in Vuejs when there is no parent element involvement

In the table below, you can see checkboxes displayed as images: example image of a table with checkboxes Here is an example code snippet: <tbody> <tr @click="goDetail"> <th scope="row><input type="checkbox" /></th> <t ...

Is there a way to remain on the current page in WordPress after submitting a contact form?

I recently developed a personalized contact form within WordPress, utilizing PHP. The completed form successfully sends emails, but I am encountering an issue when users hit submit; instead of staying on the original page, they are redirected to a post pag ...

How to perfectly align a full-width div with a div of specific width

Consider this scenario: .d1 { width: 100px; float: left; } .d2 { width: auto; float: left; } <div class="d1">Fixed Content</div> <div class="d2">This content should expand to fill the rest of the page vertically.</div> This setu ...

Ways to compel links to open in Internet Explorer

In one of my chatbot messages, I have included a link to a web app that is only compatible with Internet Explorer. My chatbot runs on Google Chrome, so when the user clicks on the link, it opens in a new Chrome tab instead of in IE, where it should open f ...

Is it possible to retrieve information from a child component within a parent component in Vue?

I'm facing a challenge in accessing data from a single-file component in Vue. I've attempted using $emit, but have been unsuccessful so far. The data string needs to start as blank since it will be modified by an input field. I've looked at ...

Encountering issues with Firebase messaging in VueJS application

Hey, I'm currently working on implementing push notifications for my application. However, I'm facing difficulties getting it to work with my Vue App. Whenever I try to run it, I encounter the following error: Messaging: We are unable to regi ...

Troubleshooting: Unable to Display Collapsing Navbar in Bootstrap 5 When Toggler is Pressed

My attempt at creating a collapsing navbar isn't working as expected, and I'm struggling to identify the issue. I have set up a collapse toggler that should target #navbar1. However, when I shrink the page, the Navbar collapses, the .navbar-togg ...

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 ...

Slow CSS :hover animations in the most recent release of Chrome

I recently upgraded my browser from chromium version 67 to the latest Chrome version 79. However, I noticed that after the upgrade, the CSS transitions on my website have become very laggy and unresponsive. Surprisingly, everything works perfectly fine on ...

Update the less mixin

I attempted to eliminate the border radius from all Bootstrap elements by creating a custom-mixins.less file with the following lines in it. My intention was for these lines to overwrite the original .border-radius mixin, but unfortunately, it did not work ...

Why won't the sound play on the button with the picture?

I am currently working on a website project that requires buttons with pictures and sound. Despite my efforts, the sound feature is not functioning properly in Chrome and Firefox. I am still learning and would like to know how to toggle the sound on and of ...

Does CSS media query "@media only screen" only work when I am resizing the window?

I recently encountered an issue with the code found on this website (the repository can be viewed on Github here): @media only screen and (max-width: 600px) { img {width: 100%; height: 100%; margin: 0; padding: 0; } a.box { width: 100%; pa ...

What is the best way to close the space between a box-shadow and a div background when incorporating semi-transparent rgba() values?

There seems to be an issue arising when applying partially transparent rgba() background-color and box-shadow color values to an element with a non-fixed (percent-based) border-radius. This combination results in a minuscule transparent gap appearing at th ...