Back to Mjml

README

packages/mjml-hero/README.md

5.1.06.0 KB
Original Source

mj-hero

Displays a hero image and behaves like an mj-section tag with a single mj-column tag.

The background-height and background-width attributes are mandatory and it's best to use an image with width the same as the mj-body (width="600px" by default) and height the same or larger than the height of mj-hero.

Use background-color to provide a fallback color in case an email client doesn't support background-url.

<div class="alert alert-note" role="alert"> <p>Note</p> <p>The <code>height</code> attribute is only required for <code>mode="fixed-height"</code>.</p> </div> <figure> <figcaption>Fixed height</figcaption> </figure>
xml
<mjml>
  <mj-body>
    <mj-hero
      mode="fixed-height"
      height="469px"
      background-width="600px"
      background-height="469px"
      background-url=
          "https://static.mailjet.com/mjml-website/documentation/hero.jpg"
      background-color="#2a3448"
      padding="100px 0px">
      <mj-text
        padding="20px"
        color="#ffffff"
        font-family="Helvetica"
        align="center"
        font-size="45px"
        line-height="45px"
        font-weight="900">
        GO TO SPACE
      </mj-text>
      <mj-button href="https://mjml.io/" align="center">
        ORDER YOUR TICKET NOW
      </mj-button>
    </mj-hero>
  </mj-body>
</mjml>
<figure> <figcaption>Fluid height</figcaption> </figure>
xml
<mjml>
  <mj-body>
    <mj-hero
      mode="fluid-height"
      background-width="600px"
      background-height="469px"
      background-url=
          "https://static.mailjet.com/mjml-website/documentation/hero.jpg"
      background-color="#2a3448"
      padding="100px 0px">
      <mj-text
        padding="20px"
        color="#ffffff"
        font-family="Helvetica"
        align="center"
        font-size="45px"
        line-height="45px"
        font-weight="900">
        GO TO SPACE
      </mj-text>
      <mj-button href="https://mjml.io/" align="center">
        ORDER YOUR TICKET NOW
      </mj-button>
    </mj-hero>
  </mj-body>
</mjml>

Attributes

attributeacceptsdescriptiondefault value
background-colorCSS color formatshero background color#ffffff
background-heightpx %height of the image used, mandatory
background-positionstringCSS values, i.e. left center right + top center bottomcenter center
background-urlstringabsolute background in URL formatnull
background-widthpx %width of the image used, mandatoryinherits parent element width
border-radiusstringborder radius
css-classstringclass name, added to the root HTML element created
heightpx %hero section height, (required for fixed-height mode)0px
inner-background-colorCSS color formatscontent background color
inner-paddingpx %hero inner padding, supports up to 4 parameters
inner-padding-bottompx %hero bottom inner padding
inner-padding-leftpx %hero left inner padding
inner-padding-rightpx %hero right inner padding
inner-padding-toppx %hero top inner padding
modestringfluid-height or fixed-heightfluid-height
paddingpx %hero padding, supports up to 4 parameters0px
padding-bottompx %hero bottom paddingnull
padding-leftpx %hero left paddingnull
padding-rightpx %hero right paddingnull
padding-toppx %hero top paddingnull
vertical-aligntop middle bottomcontent vertical alignmenttop
<ul class="cta-container"> <li>Fixed height: <a class="cta" href="https://mjml.io/try-it-live/components/hero">Try it live</a></li> <li>Fluid height: <a class="cta" href="https://mjml.io/try-it-live/components/hero/1">Try it live</a></li> </ul>