Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Foundation Modals

Foundation Modals

A modal is a popup displayed at the top of the page.

We can, on a container element (such as

) use a unique ID and add .reveal-modal class and data-reveal attribute to add a modal. You can use the data-reveal-id="id" attribute to open the modal. id must match the container id (in this example "myModal").

If you want to close the modal by clicking on an area outside the modal. You can add it to the modal's close button Add on the tag .close-reveal-modal class.

Note: The slider requires JavaScript. So you need to initialize Foundation JS:

Example

<

button

type=

"button"

class=

"button"

data-reveal-id=

"myModal"

Click To Open Modal

<

/button

<

div

id=

"myModal"

class=

"reveal-modal"

data-reveal

<

h2

Heading in Modal.

<

/h2

<

p

Some text in the modal.

<

/p

<

p

Some text in the modal.

<

/p

<

a

class=

"close-reveal-modal"

×

<

/a

<

/div

<

script

$(document).ready(function() {

    $(document).foundation();

})

<

/script

Try it »


Modal Size

You can add the following classes to the modal container to set the size of the modal:

  • .tiny: 30% width
  • .small: 40% width
  • .medium: 60% width
  • .large: 70% width
  • .xlarge: 95% width
  • .full: 100% width and height

Note: Defaults to 80% width on tablets, laptops, and PCs, and 100% width on small-screen devices.

Example

<

div

id=

"myModal"

class=

"reveal-modal tiny|small|medium|large|xlarge|full"

data-reveal

Try it »


Embedded modal

You can embed a modal within a modal by adding a new trigger button on the first modal. You must set a unique id for the embedded modal:

Example

<

a

href=

"#"

class=

"button"

data-reveal-id=

"myModal"

Click To Open Modal

<

/a

<

div

id=

"myModal"

class=

"reveal-modal"

data-reveal

<

h2

First Modal

<

/h2

<

p

Some text..

<

/p

<

p

<

a

href=

"#"

data-reveal-id=

"secondModal"

class=

"button"

Open Second Modal

<

/a

<

/p

<

a

class=

"close-reveal-modal"

×

<

/a

<

/div

<

div

id=

"secondModal"

class=

"reveal-modal"

data-reveal

<

h2

Tada! Second Modal

<

/h2

<

p

Some text..

<

/p

<

a

class=

"close-reveal-modal"

×

<

/a

<

/div

Try it »

The second modal will replace the first modal. If you want to keep the first modal open when opening the second modal, you can add on the second modal data-options="multiple_opened:true;" property through the following steps:

Example

<

div

id=

"secondModal"

class=

"reveal-modal"

data-reveal data-options=

"multiple_opened:true;"

Try it »