Tutorials

How to handle margin

This is a demonstration of how to handle margin in native ads to make them seamlessly integrate into the layout of your page. Although this may seem like a trivial matter, it is often overlooked. Getting it right will significantly elevate the look and feel of the website. Some basic principles should be followed:

In this example we have three ad containers in between editorial content. Two containers render ads with different margin applied, while the third is disabled using the enabled setting to make it not render any ads.

Setup
adk.config()
    .addTemplate('com.advisible.native.teaser', adk.template.config()
        .url('teaser.html'))

    .addContainer('content-display', adk.container.config()
        .params({
            adapters: {
                'com.advisible.content-display': {
                    render: 'com.advisible.native.teaser',
                    target: '_blank',
                    templateValues: {
                        external: true,
                    }
                },
            },
        }))

    .addContainer('native-teaser', adk.container.config())

    .addContainer('disabled', adk.container.config()
        .enabled(false))

Here the adk-container-margin class is used to set a base bottom margin for all containers and a top margin specifically for the native-teaser container using a CSS attribute selector.

Style
.editorial-content {
    margin-bottom: 16px;
}

.adk-container-margin {
    margin-bottom: 16px;
}

[data-adk-container="native-teaser"].adk-container-margin {
    margin-top: 32px;
}
HTML
<div data-adk-container="content-display"></div> <!-- ad with bottom margin -->
<div class="editorial-content">
    Editorial content 1
</div>
<div data-adk-container="native-teaser"></div> <!-- ad with top and bottom margin -->
<div class="editorial-content">
    Editorial content 2
</div>
<div data-adk-container="disabled"></div> <!-- no ad is rendered -> no margin applied -->
<div class="editorial-content">
    Editorial content 3
</div>
Result
Editorial content 1
Editorial content 2
Editorial content 3