Introducing the amazing Magnific Popup feature: Elevate your images with captivating

I am looking to incorporate Magnific Popup with the title displayed above the image.

After going through the documentation and checking out the Image Type section, I found a property called markup that allowed me to position the title above the image using this code snippet:

This yielded the following result:

https://i.sstatic.net/QLWjB.png

However, I noticed that the title was stretching wider than the actual image. Here is how it appeared without modifying the markup:

https://i.sstatic.net/pvKsn.png

Is there a way to ensure that the title does not dictate the width of the window? My goal is for the window to adjust its width based on the image size.

$('.grid').magnificPopup({
  delegate: 'a',
  type: 'image',
  image: {
    markup: '<div class="mfp-figure">' +
      '<div class="mfp-close"></div>' +
      '<div class="mfp-title"></div>' +
      '<div class="mfp-img"></div>' +
      '<div class="mfp-bottom-bar">' +
      '<div class="mfp-counter"></div>' +
      '</div>' +
      '</div>'
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="grid">
  <a class="popup-link" href="ENTE-611.jpg" data-effect="mfp-zoom-in" title='A lot of text - A lot of text - - A lot of textext -  - A lot of text -  - A lot of text -  - A lot of text -  - A lot of text -  - A lot of text -  - A lot of text -  '>
    <img class='link img-link' src="ENTE-611s.jpg">
  </a>
</div>

Answer №1

Utilize the HTML5 <figcaption> tag by enclosing the mfp-title within it, then wrap the entire mfp-img container div using the <figure> tag in this manner

image: {
   markup: '<div class="mfp-figure">' +
             '<div class="mfp-close"></div>' +
             '<figure>'+
             '<div class="mfp-img"></div>' +  
             '<figcaption>'+
               '<div class="mfp-bottom-bar">' +
                 '<div class="mfp-title"></div>' +
                 '<div class="mfp-counter"></div>' +
               '</div>'+
             '</figcaption>'+
             '</figure>' +
           '</div>'
}

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

I'm having trouble getting Bootstrap CDN to work, as I keep encountering a CORS policy error when I debug in Webstorm

I'm encountering a CORS Policy Error while attempting to implement Bootstrap for my project. The site is only showing plain HTML without any styling, and clicking the "Add to table" button does not trigger the modal window. I am also unsure why the st ...

Attempting to wait for the completion of all AJAX calls using $.when is proving to be ineffective

I want to execute a function only once all ajax calls are complete. However, the $.when method is being triggered prematurely with an empty array of promises. Could this be due to the fact that the searchRecommendations() function is being called multiple ...

Is there a way to sort the columns of my table based on a specific keyword?

Currently, my column is {article, formation , tous article , tous formation, notif, offre}. I would like to rearrange it in this order {article, tous articles , espace&nbsp, formation , tous formation , &nbsp, notif , offre} This snippet of code r ...

What is the process for retrieving a single element from a JSON array within an object and displaying this information on the X-axis using Ionic 6 and Chart.js?

While following a tutorial on utilizing ChartJS in Ionic 6, I encountered a JSON response that looks like this: [ { "id": "1", "name": "Fruit", "last_updated": "2022- ...

Having trouble executing JavaScript upon form submission

Attempting to implement form validation on an email reset page. Here is the code I have written: <!DOCTYPE html> <html> <head> <title> form validation </title> <script> function validateForm ...

Resolving a MySQL database problem between mentors and mentees

I have a scenario where a mentor has 10 different mentees. Is there a way to streamline the data storage in my database instead of creating separate fields for each mentee? Currently, I have tables for mentors and students in my database. Could this be a ...

Using -moz-transform CSS does not effectively prevent unwanted page breaks when printing in Firefox

I am facing a challenge with printing two tables, named header and details, on separate pages. The structure of the tables is as follows: <table id="header"> <!-- multiple rows here --> </table> <table id="details&quo ...

Transferring the offset of jQuery from one element to another results in their positions being misaligned

In the quest for aligning content vertically between two divs, I have encountered a challenge. Despite my efforts to adjust offsets and heights, the new element in the second div still does not align perfectly with the first one. This is evident in the cod ...

I encountered an issue with my shopping cart while using ReactJS

this is the App.js file import React from "react"; import ListProduct from "./listProduct"; import ListOrder from "./listOrder"; import pizza from "./pizza.jpg"; import './style.css' import { Container,Row,Col,Button } from 'react-boo ...

Is there a way to retrieve the hand-drawn lines at no cost in the form of a list, with each line represented as a collection of coordinates

I am currently contemplating the idea of utilizing fabric.js for an online handwriting recognition system. In order to make this system work, I need to transmit the sketched lines as a collection of lines, where each line consists of several points. If a ...

Having trouble with jQuery show/hide not functioning properly?

My website has a sub-menu section with a shopping cart icon. When a user hovers over the icon, it reveals a hidden cart section. The user can then move the mouse into the cart section to remove items. The problem I'm facing is that if a user displays ...

Tips for arranging buttons horizontally in Angular

After adding a third button, I noticed that the buttons were now displaying in a column instead of a row. html: <div class="creator-button-container" *ngIf="isCurrentUserTheChannelCreator"> <div *ngIf="isChannelE ...

Implementing link submission with jQuery AJAX that sends empty values

I want to implement a functionality where, upon clicking the like button, data will be submitted using ajax in jquery and instead of displaying "Like", it should show "Dislike". However, I am encountering the following issues: 1) After submission, it red ...

Make an element in jQuery draggable but always within the viewport

My issue is that when I resize the window, the element stays in its position until I start dragging it. Once I drag it and then resize the window again, it doesn't stay within its container. To better illustrate my problem, you can view a demo on Fid ...

What steps do I need to take to activate this JQuery plugin successfully?

I stumbled upon this amazing silky smooth marquee jQuery plugin online @: Smooth marquee After downloading the latest JQuery and the JQuery marquee plugin as directed on the site above, I am still unable to make it work like they showcased in their demo: ...

Initiate activity when link is clicked

I am currently in the process of developing a website that includes 5 divs. <div class="one"></div> <div class="two"></div> <div class="three"></div> <div class="four"></div> <div class="five"></div ...

jQuery function not executing after subsequent AJAX request

Can anyone provide some assistance with my AJAX/jQuery setup? I'm attempting to dynamically load code into a jQuery Dialog. There is some jQuery code within the content that initializes buttons and loads tabs. The issue I'm facing is that the c ...

Prevent fields from being edited until the main field is filled out

Currently, I am in the process of designing a form with three primary fields at the top – Organization Name, Department, and Address. The other fields are not relevant for now. It is imperative that the user inputs data into the Organization field before ...

Update the CSS styling for elements that are dynamically added to the page using the

Just started using jQuery for the first time and I'm encountering an issue. I'm trying to load content from an external element onto my page, and while it loads correctly, I'm having trouble using normal traversal methods on the loaded eleme ...

jQuery disrupts the functionality of other scripts

Let me start by saying that I have very little knowledge about scripting and HTML. Recently, I came across the following code: <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script> < ...