The reason why setting height to 0 is ineffective in a CSS definition

Within my current project, I am utilizing vue.js 2 and have implemented an img component.

Below is the code for this component:

<template>
<div class="banner">
  <img class="banner-img" :src="bannerImg"/>
</div>
</template>

<script>
export default {
  name: 'DetailBanner',
  props: {
    sightName: String,
    bannerImg: String,
    gallaryImgs: Array
  }
}
</script>

<style lang="stylus" scoped>
.banner
  position: relative
  overflow: hidden
  height: 0
  padding-bottom: 55%
  .banner-img
    width: 100%

The URL of the image used is :

In this case, I do not wish to display the image on the page, hence why I have set the height to 0 in the CSS.

Unfortunately, the attempt was unsuccessful. I even tested removing the height: 0, but it did not change anything.

Can anyone explain why setting the height to 0 is not working as expected?

Answer №1

To showcase or hide your image, Vue.js offers a handy solution with the v-if directive:

<template>
 <div class="banner" v-if="showImg">
     <img class="banner-img" :src="bannerImg"/>
    </div>
 </template>

<script>
   export default {
      name: 'DetailBanner',
      props: {
         sightName: String,
        bannerImg: String,
         galleryImgs: Array
      },
      data(){
         return{
            showImg:false
             }
       }

  }
</script>

Incorporate showImg into your props, enabling you to easily toggle the visibility of the image using solely Vue.js and bypass any CSS headaches.

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

Customize the default getstream component styles in a NextJS Component

Is there a way to customize the CSS of getStream.io components using custom CSS? I have created a component as shown below and now I want to override the styles for various classes of its components. Following the instructions in this README file, I impor ...

Issue: Unable to locate module '/node_modulesprogressbar/package.json'

Currently, I am facing an issue with the generation of a progress bar using Browserify and progressbar.js. When I try to var ProgressBar = require('node_modules/progressbar');, an error pops up saying Error: Cannot find module '/node_modules ...

Retrieving input field values in JS/Ajax without needing to refresh the page or click a button

Currently, I have set up a JavaScript function that submits data without refreshing the page or requiring a button click. The input field is located within tab #2 and triggers the JS function when the user stops typing. However, the issue arises when the ...

Simply modifying a custom attribute source using jQuery does not result in it being refreshed

Introduction: Utilizing jQuery.elevateZoom-3.0.8 to display zoomed-in images. The SRC attribute contains the path to the smaller/normal image The DATA-ZOOM-IMAGE attribute holds the path to the larger image used for zooming. Here is the HTML Code: ...

Some devices experiencing website update issues while others are successful

My website is functioning properly on my laptop and phone, but not on my school iPad (managed by the district). I have already cleared the cache, but the site does not update. It was working fine earlier, and I need to present it next Monday. Please help a ...

When incorporating multiple BoxGeometries, THREE.js ensures that each box maintains a consistent color throughout. The uniformity remains unchanged

Looking to create a simple program using Three.js to display bars at specific locations with varying heights and colors. As a beginner in Three.js, I am currently exploring the framework. When running my script to set up the bar positions, colors, lights, ...

retrieve the key:value pairs contained within sub-blocks

After receiving the following output from Postman or hitting an endpoint, the challenge is to extract "id" and "name" from the values. The key-value pairs are nested within sub-blocks, so how can this be achieved using JavaScript and then implemented in ...

When implementing v-for on a table in VueJS and Laravel, all I see are rows with no content

I'm attempting to connect a JSON array to a table by utilizing v-for on a <tr> tag. <tr v-for="file in files"> <td>@{{ file.name }}</td> <td>@{{ file.hash }}</td> <td>@{{ file.size }}</td> ...

Unable to use .click function to choose image within container

Apologies for the lengthy post, but I believe providing all details is essential to understanding the issue at hand. The following code snippet is intended to display the first image in a pop-up box when a user clicks on any of the images shown: <div ...

Discover the steps to showcasing product images within Shopware 6's user-friendly administration interface

Working on a specialized Shopware 6 Administrative plugin, integrating product images has proven to be quite challenging. After thorough investigation of the Shopware repositories such as 'product_media' and 'media', along with other re ...

Tips on how to ensure that an onClick JS function only runs when radio buttons are selected

I have implemented the formslider library for a form on my website. In the demo, the slide transitions to the next set of questions based on a click event triggered by radio buttons (answers). However, when I attempted to include checkboxes for users to s ...

Implementing automatic page breaks in Laravel using the mpdf libraryLet me know

I am attempting to automatically add a page break if the data exceeds 10. I am using mpdf in conjunction with Laravel and Vue. Below is my CSS code: <style> div.breakNow { page-break-inside:avoid; page-break-after:always; } </style> This is t ...

Express 4.13.4 appears to be disregarding the cookie's expiration date when the moment.toDate() function is used

I've been encountering an issue where I am attempting to set a cookie with a specific expiry date of 3 months, but the expiration is not setting correctly. Using momentJS, I created a date object for the desired time. The console confirms that the co ...

Using react-input-mask together with a child component in React is not compatible

I've been exploring ways to mask a Material UI TextField, and after researching some solutions online, I came across this code snippet: <InputMask mask="(0)999 999 99 99" value={phone} disabled={false} ...

Limiting the number of promises in AngularJS

My web application allows users to select multiple files using a file input. After the user selects the files, I upload them one by one through my REST API. However, in Internet Explorer, if the user selects more than 10 files at once, some of the requests ...

The sticky HTML table header feature is functional, however, the header's border disappears while scrolling

Utilizing the react-bootstrap-table2 library in my React project, I added custom CSS to create a sticky top row effect: .table-container { overflow-y: auto; max-height: 500px; } .react-bootstrap-table th { position: sticky; top: -1px; background- ...

The surprising twist of hasOwnProperty's behavior

I am currently working on a function that is designed to check whether an object contains keys such as 'id' or 'serif:id'. However, I have encountered some issues with its functionality. function returnIdPreferSerifId(object) { if ...

Stop the div from expanding because of oversize text in Bootstrap

I have the following HTML source code for a Bootstrap card: <div class="card shadow-none card-fluid mb-3 mb-md-5"> <div class="row"> <div class="col-md-3 col-lg-3 mb-3 mb-sm-0"> <img class="img-fluid rounded" ...

Combining URLs in Angular 6 - A Step-by-Step Guide

How can I concatenate the commonUrl from CommonClass in Angular 6 for category.service.ts? common-class.ts export class CommonClass { constructor(public commonUrl : string = 'http://localhost:3000'){}; } category.service.ts import { CommonC ...

Transferring data between modules in nodejs

Within my custom module, there is a method designed to query the database and check if a given username exists. I need certain values to be returned in order to determine the query result at a higher level. var findUserbyUsername=function(username) { ...