0

I use owl carousel 2 on different pages. I used the same css and js everywhere. For some reason, when I load my page, the nav-buttons (prev and next) always get the inline-style top-value of 24px. I never declared a top-value of 24px anywhere in my js or CSS..

This is my HTML:

<div class="pdf-gallery">
        <p class="headline">Lorem ipsum dolor sit amet, consectetuer</p>

        <div class="download">
            <div class="image">
                <figure>
                    <a href="lightbox-imagegallery.html?image=0">
                        <!-- image=2 als Übergabe an die Bildergalerie in der Lightbox; sorgt dafür, dass das richtige Bild geöffnet wird (beginnt mit 0) -->
                        <img src="img/content/image.jpg" alt="Alttext"/>
                    </a>
                </figure>
            </div>
            <div class="caption">
                <a href="" class="title">Lorem ipsum dolor sit amet, consectetuer</a>

                <p class="info">PDF deutsch | 123 kB</p>
            </div>
        </div>
        <div class="download">
            <div class="image">
                <figure>
                    <a href="lightbox-imagegallery.html?image=1">
                        <img src="img/content/content.jpg" alt="Alttext"/>
                    </a>
                </figure>
            </div>
            <div class="caption">
                <a href="" class="title">Lorem ipsum dolor sit</a>

                <p class="info">PDF deutsch | 123 kB</p>
            </div>
        </div>
        <div class="download">
            <div class="image">
                <figure>
                    <a href="lightbox-imagegallery.html?image=2">
                        <img src="img/content/thumbnail.jpg" alt="Alttext"/>
                    </a>
                </figure>
            </div>
            <div class="caption">
                <a href="" class="title">Lorem ipsum dolor sit amet, consectetuer adipiscing</a>

                <p class="info">PDF deutsch | 123 kB</p>
            </div>
        </div>
        <div class="download">
            <div class="image">
                <figure>
                    <a href="lightbox-imagegallery.html?image=3">
                        <img src="img/content/content.jpg" alt="Alttext"/>
                    </a>
                </figure>
            </div>
            <div class="caption">
                <a href="" class="title">Lorem ipsum dolor sit amet</a>

                <p class="info">PDF deutsch | 123 kB</p>
            </div>
        </div>
        <div class="download">
            <div class="image">
                <figure>
                    <a href="lightbox-imagegallery.html?image=4">
                        <img src="img/content/image.jpg" alt="Alttext"/>
                    </a>
                </figure>
            </div>
            <div class="caption">
                <a href="" class="title">Lorem ipsum dolor sit amet, consectetuer adipiscing</a>

                <p class="info">PDF deutsch | 123 kB</p>
            </div>
        </div>
        <div class="download">
            <div class="image">
                <figure>
                    <a href="lightbox-imagegallery.html?image=5">
                        <img src="img/content/image.jpg" alt="Alttext"/>
                    </a>
                </figure>
            </div>
            <div class="caption">
                <a href="" class="title">Lorem ipsum dolor sit amet, consectetuer</a>

                <p class="info">PDF deutsch | 123 kB</p>
            </div>
        </div>
    </div>

And this is how I load the owl-carousel in js:

$j('.pdf-gallery').each(function () {
    var $slider = $j(this),
        opts = {
            responsive: {},
            smartSpeed: 800,
            loop: false,
            nav: true,
            navRewind: false,
            navText: ['', ''],
            onInitialized: function () {
                $slider.find('.owl-dots, .owl-nav').wrapAll('<div class="owl-controls">');
            },
            onResized: function () {
                $slider.find('.download .image').setEqualHeight('auto');
                $slider.find('.download .caption').setEqualHeight('auto');
            }
        };

    //Paging-Container
    $slider.find('> div').wrapAll('<div class="wrapper owl-carousel">');

    //responsive definition
    opts.responsive[0] = {items: 1};
    opts.responsive[mediaqueries.maxMobile] = {items: 2};
    opts.responsive[mediaqueries.softTablet] = {items: 3};
    opts.responsive[890] = {items: 4};
    if ($slider.parents('.wide, #full-width').length) {
        opts.responsive[mediaqueries.maxDesktop] = {items: 6};
    }

    if ($j('html').hasClass('lt-ie9')) {
        opts.responsive = false;
        if ($slider.parents('.wide, #full-width').length) {
            opts.items = 4;
        } else {
            opts.items = 3;
        }
    }

    //init
    $slider.find('.wrapper').owlCarousel(opts);
});

And then I have a css for the prev and next button:

.owl-next,
            .owl-prev {
                color: @darkBlue;
                cursor: pointer;
                font-size: 22px;
                position: absolute;
                text-decoration: none;
                top: 2px; }

So I feel like my buttons should have the value top: 2px. But instead they always get an inline style of top: 24px which overwrites my top: 2px value. Is this an default value which is set somewhere? But why if I use the same code everywhere else?

Daniel
  • 525
  • 3
  • 10
  • Can you create a jsfiddle to show that? Have you inspected code in dev tools to see where this top:24px comes from? – robjez May 27 '15 at 08:12
  • Ye I could do that later. Thats the thing.. It comes from "nowhere". In dev tools it just says "element.style {top 24px}". It writes it inline into my HTML code. – Daniel May 27 '15 at 08:23
  • I'm not a great believer in "nowhere's" :). If it's not a browser default, and I don't think it is, it must be coming from "somewhere" - either other css, or being dynamically added by javascript. When you see your css in element.style panel of dev tools - that might mean,that it is an inline style, which is pointing to js injecting it. But it is just guessing without seeing actual code in a browser. – robjez May 27 '15 at 08:31
  • But regardless finding the answer to this puzzle - you should be able to override it by using `!important` directive on your `top: 2px` rule. – robjez May 27 '15 at 08:36
  • Well yes for sure it comes from somewhere :D. But why is ist just on that carousel? I have like 10 of them on my Site and JS never injected or generated a top value.. Sorry that I cant provide a "real" example cause this is just local at the moment. And yes, !important! solve it but I dont like to work with !important :/ Thanks anyway!! – Daniel May 27 '15 at 09:33
  • No worries. I always try to avoid !important - but I don't see the reason why you couldn't use it here. I think it's perfect scenario for its use, as this is the only css way to override inline-style. On the other hand you could modify this element's css in jQuery way as `$('.owl-prev').css('top', '2px');` – robjez May 27 '15 at 10:15

0 Answers0