Troubleshooting alignment problems with CSS DIVs within VUE Components

I have a Vue application with 2 components, each housed in their own div. My CSS skills are not strong, so I found a CSS template that works well and is responsive. However, I've noticed that the top and bottom divs do not align properly and their widths do not stay consistent when the page resizes. I'm using Vuetify's grid system. How can I resolve this alignment issue?

<div id="app">
 <div class="row">
  <div class="col-xs-6"><sp_card></sp_card></div>
  <div class="col-xs-6"><sp-card2></sp-card2></div>
 </div>
</div>

Vue.component('sp_card',{
  data: function(){
    return {
      num: 3
    }
  },
  template: `
<div>
  <div class="card" v-for="n in num">
    <div class="container">
      <h4><b>Card Title</b></h4> 
      <p>By | date</p> 
      <p>Text</p>
    </div>
  </div>
</div>
`
})

Vue.component('sp-card2',{
  data: function(){
    return {

    }
  },
  template: `<div>
<div class="card2">
    <div class="container">
      <h4><b>Horizontal Card Title</b></h4> 
      <p>By | date</p> 
      <p>Text</p>
    </div>
  </div>
  </div>`
})
new Vue({
  el:"#app",
  data: {

  }
})
.card {
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  transition: 0.3s;
  width: 15%;
  border-radius: 5px;
  display:inline-block;
  margin: 5px;
}

.card:hover {
  box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}

img {
  border-radius: 5px 5px 0 0;
}

.container {
  padding: 2px 16px;
}

.card2 {
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  transition: 0.3s;
  width: 49%;
  border-radius: 5px;
  display:inline-block;
  margin: 5px;
}

.card2:hover {
  box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}

Check it out on CodePen

Answer №1

When utilizing percentage width in CSS, it's important to calculate the appropriate values yourself. The key CSS elements to consider are:

.panel {
  width: 18.25%;
  margin: 1%;
}

.panel2 {
  width: 58%;
  margin: 1%;
}

With this structure, the lower panel will occupy 60% with its margin included, while the upper panels will share the same width with a 1% margin. Note that when margins are specified in percent, they are calculated relative to the parent's width in both directions.

18.25% is derived from: (59% - 1% * 4) / 3 where 4 represents the number of left and right margins, and 3 is the number of panels in the top row.

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

"Recently, I included a function called 'test' in the code, but I encountered an error stating that it was not recognized as a function. Can someone provide assistance

Issue Detected A 'TypeError' has been thrown: ".goal_test".click is not defined as a function Feel free to collaborate on the code by clicking this link: Please note that my modified code is enclosed within asterisk symbols. ...

Leveraging jQuery's .animate method to create engaging search box animations

Greetings esteemed individuals... I am currently working on enhancing the search component for my application... http://jsfiddle.net/SkyKOG/K8utq/24/ input{ display:none; width:0px; color:#999; } Initially, I only had a simple search box so ...

Is the VueJs and ChartJs combination causing the chart to be width-responsive, but not height-responsive?

I've exhausted all options, but I can't seem to make the height of my chart respond effectively. The width is behaving as expected, adjusting responsively, but the height stubbornly remains fixed at 400px. Within my primary Vue application, I i ...

Is there a way to have incoming messages automatically align to the left or right based on the sender, without using the float property?

I am currently working on a webpage where I want the messages sent by different users to appear in a yellow conversation window based on who sent them - user 1 or user 2. I want it to mimic the messaging layout commonly seen on phones, distinguishing betwe ...

Vertical alignment in material-ui's Grid component is not functioning as expected

I have been working on this code snippet to center a button both vertically and horizontally. However, it seems like the button is not positioned correctly along the vertical axis. Any advice or guidance would be greatly appreciated! Could someone assist ...

The Calibri Light font is not supported by Chrome version 37

Yesterday my website was working fine, but today when I checked it, some strange issues appeared. The Calibri Light font that I used extensively has been replaced with the default font, and the width of input fields has changed. How can I resolve this issu ...

Is there a way to integrate my splash screen in Vue?

Quick note: The splash screen code below is from my Vue app, presented as a view file rather than a component. I am also using the Vue router. Below you will find the code for a splash screen utilizing Gsap animation with a callback function that can lat ...

Styling ReactJS Components with CSS Styling

I am a complete beginner to React and I seem to be facing an issue with rendering CSS properly. The react class, App, that I have should display a Card with a progress tracker on it. var App = React.createClass({ render: function () { var pushNotific ...

Prevent horizontal scrolling on mobile devices

To prevent vertical scrolling on mobile devices, I attempted using the CSS code: body {overflow-x:hidden} This successfully disables vertical scrolling in regular browsers. However, if there is an element wider than the screen on mobile, it still allows ...

Having trouble loading image on web application

Currently, I am facing an issue while attempting to add a background image to an element within my Angular web application. Strangely enough, the relative path leading to the image seems to be causing my entire app to break. https://i.stack.imgur.com/b9qJ ...

Modifying CSS using jQuery in a PHP While Loop

I've been racking my brain trying to solve this issue, experimenting with different approaches but so far, no luck. Question: How can I dynamically change the color of a specific div within a PHP while loop using jQuery after receiving an AJAX respon ...

Modifying the image height in a column using Bootstrap and JSON data

My webpage is dynamically generating images from a JSON file through a JavaScript file. However, the images are displaying at different heights, and I want each column to adjust to the height of the image to eliminate any gaps. Particularly, data with the ...

What's the best way to combine cells using HTML, CSS, and PHP?

Can anyone assist me with merging cells containing identical values in specific columns? <td style="text-align: center; font-size: 9.5px;">{{$endereco->quadra}}</td> <td style="text-align: center; font-s ...

The background image is cropped at both the top and bottom edges

Check out this JSFiddle link: http://jsfiddle.net/SoSoDef/uhx3o62f/1/. The code seems to be running fine, but I'm facing an issue where the image is being slightly cut off at the top and bottom for some reason. -webkit-background-size: cover; Can an ...

Adjust the size and alignment of columns within a Bootstrap table by incorporating a nested table

My goal is to adjust the size and alignment of the header components within the thead section of an HTML table to match those of a nested table. The main table handles the alternating row colors, while the nested table enables me to organize the fields ac ...

Utilizing Bootstrap for aligning a span element beneath a div container

I'm working on enhancing a project by integrating more Bootstrap elements. In one part, I have a circular div with the text "Go to Homepage" below it. My goal is to center the span under the div and have it appear on a single line. How can I achieve t ...

Discover the steps for accessing and incorporating polylines into numerous maps with vue2leaflet

I'm currently working on a project that involves displaying multiple maps with polylines by using v-for. I attempted to utilize the leaflet:load event to trigger a method after the map has loaded, but it appears that the event does not exist. While I ...

Fixing a div at the top post scroll - bug on iOS mobile device

I am looking to achieve a similar effect as demonstrated in the example below: https://css-tricks.com/scroll-fix-content/ Essentially, the goal is to have a div become fixed at the top of the page after scrolling to a certain point. Initially, the div wil ...

Inspecting the Nuxt.js application, retrieve the build version using console.log

Currently, my Nuxt site is being hosted on AWS S3 with Cloudfront. Whenever I deploy a new version, I have to invalidate the CloudFront CDN which causes a delay in the deployment process. I want to display the build hash by using console.log(buildHash) wh ...

javascript strange behavior

I am facing an issue with my code that is attempting to display images based on their height. Strangely, the code seems to work fine when I test it with 2 images, but fails when trying with 3 or more. Check out the site: Upon clicking a menu button, the ...