My own CSS styles may be intefering with plugin CSS styles

Hi, I’ve finally come across a javascript code that cycles the background image of an element without needing to change the HTML (adding presentational images etc) but can’t get it to work despite reading the short readme. Where am I supposed to add “the javascript”? I’m probably missing something obvious but can’t find what, the file paths are correct.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="javascript/rewish-jquery-bgswitcher-0.4.3-0-g8d31c42/rewish-jquery-bgswitcher-8d31c42/jquery.bgswitcher.js"></script>
<script type="text/javascript">$(".box").bgswitcher({
  images: ["header.jpg", "header2.jpg", "header3.jpg"], // Background images
  effect: "fade" // fade, blind, clip, slide, drop, hide
});</script>
</head>

<body>
<div class="box" style="height:502px;">asdf
</div>
</body>
</html>

Hi,

You’ll need to put your JavaScript (all of it) at the bottom of the page, before the closing body tag.
As it is you are trying to reference elements before they have been created on the page.

Thanks for the reply. It works when I put it at the end, but for some reason it breaks the page I’ve already created. It breaks it in that it doesn’t show any background at all, and messes up the containing (and some neighboring) content; it might be deleting the whole element? The following file is in the same folder as the test one so the filepaths are good.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" media="screen,projection,tv" href="style.css">
<!--[if lte IE 9]>
<style>.wrapper{height:auto}</style>
<![endif]-->
<script src="ie10.js" type="text/javascript"></script>
<script src="analytics.js" type="text/javascript"></script>
<title>###</title>
<div class="wrapper">
		<div class="tr">
				<div class="tc header">
					<ul id="headerbar">
					<li><a href="#content" id="skip">Skip to content</a>
					<li><a href="#"><span>link</span> <span>link</span></a>
					<li><a href="#">link</a>
					<li><a href="#">link</a>
					<li><a href="#">link</a>
					<li><a href="#">link</a>
					<li><a href="#">link</a>
					<li><a href="#">link</a>
					</ul>
				</div>
		</div>
        <div class="tr">
        	<h1 class="tc" id="content">Welcome heading</h1>
        </div>
		<div class="tr">
				<div class="tc">
						<div class="inner">
								<div class="tc main"><h2>A city for all seasons</h2>
<p><img alt="" src="images/homethumbnail3.jpg" class="thumbnailleft">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sit amet mauris quis massa tincidunt vestibulum. Aenean molestie purus vel dolor interdum, et hendrerit augue placerat. Phasellus vel venenatis sem, quis interdum felis. Proin quis malesuada eros. Aliquam eget imperdiet mi. Nunc in feugiat lorem. Aenean cursus nibh vitae lacinia ultricies. Donec ac auctor sem. Curabitur eros diam, mollis non fermentum et, rhoncus nec diam.


<p><img alt="" src="images/homethumbnail2.jpg" class="thumbnailright"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sit amet mauris quis massa tincidunt vestibulum. Aenean molestie purus vel dolor interdum, et hendrerit augue placerat. Phasellus vel venenatis sem, quis interdum felis. Proin quis malesuada eros. Aliquam eget imperdiet mi. Nunc in feugiat lorem. Aenean cursus nibh vitae lacinia ultricies. Donec ac auctor sem. Curabitur eros diam, mollis non fermentum et, rhoncus nec diam.





								</div>
								<div class="tc side"><h2>side heading</h2>
                                <p>balba albalb</p>

								</div>
						</div>
				</div>
		</div>
		<div class="tr">
				<div class="tc footer">balbala</div>
		</div>
</div><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script src="javascript/rewish-jquery-bgswitcher-0.4.3-0-g8d31c42/rewish-jquery-bgswitcher-8d31c42/jquery.bgswitcher.js" type="text/javascript"></script>
                <script type="text/javascript">$(".header").bgswitcher({
  images: ["header.jpg", "header2.jpg", "header3.jpg"], // Background images
  effect: "fade" // fade, blind, clip, slide, drop, hide
});</script>
@charset "utf-8";
* {padding:0;margin:0;font-family:Arial, Helvetica, sans-serif; font-weight:normal;}
body, html {
	height:100%;
	background:#F2EEE0;
}
body {font-size:62.5%;}
.wrapper {
	height:100%;
	width:100%;
	display:table;
}
.tr {display:table-row}
.tc {
	display:table-cell;
	vertical-align:top
}
.footer {
	background:#99bddb;
	height:1px;
	padding:0 20%;
	color:#446886;
	text-align:center;
}
.header {
	background:url(images/header.jpg) top no-repeat;
	padding:135px 0 0;
	height:366px;
}
.inner {
	height:100%;
	background:#FEFEFE;
	display:table;
	width:60%;
	margin:0 auto;
}
.side {
	background:#CCE4F3;
	width:35.2em;
	padding:0 1.4em 4em;
	text-align:center;
}
.main {
	padding:0 1.4em 4em;
}
.thumbnailright {float:right;margin-left:0.5em;}
.thumbnailleft {float:left;margin-right:0.5em;}

/* NAVIGATION */
#headerbar{
list-style:none;
background:#B29562;
height:4.5em;
width:80%;
padding:0 0 0 20%;
}
#headerbar li{
line-height:4.5em;
text-transform:uppercase;
text-align:center;
float:left;
}
#headerbar li a{
display:block;
color:#F1F8E0;
text-decoration:none;
padding:0 1.6em;
font-size:1.4em;
}
#headerbar li a:hover{
background:#988054;
}
#headerbar li:nth-child(3)
{
margin-left:6em;
}
a#skip{position:absolute;top:-50em;}
a#skip:focus{position:static;}
#headerbar li:nth-child(2){
height:17.5em;
line-height:normal;
margin-top:-13em;
}
#headerbar li:nth-child(2) a{
background:url(images/grb.png) top no-repeat;
background-size:8em 13em;
height:17.5em;
font-size:1em;
display:table-cell;
vertical-align:bottom
}
#headerbar li:nth-child(2) a span:first-child {
display:table-row;
font-size:2.2em;
}
#headerbar li:nth-child(2) a span:nth-child(2) {
font-size:1.6em;
display:table-row
}

/* END NAVIGATION */
h1{
background:#988054;
color:#FFDFA6;
font-size:2.6em;
padding-left:20%;
line-height:2em;
height:1px;
}
.roadmap {
	background:#FFDFA6;
	color:#747474;
	font-size:1.4em;
	line-height:1.4em;
	padding-left:20%;
	text-indent:1.4em;
	height:1px;
	text-transform:uppercase;
}
.main h2{
background:rgba(199,225,242,0.8);
width:15em;
position:relative;
right:74px;
padding:0 0 0 74px;
font-size:2em;
line-height:1.8em;
color:#668AA8;
}
.main h2+p {
margin-top:0.9em;
}
.main p {
color:#747474;
font-size:1.6em;
line-height:1.5em;
margin:2em 0 1em;
}
.side h2 {
text-align:center;
color:#668aa8;
font-size:2em;
line-height:1.8em;
text-transform:uppercase;
}
.side h2+p {
margin-top:0.9em;
}
.side p {
color:#747474;
font-size:1.6em;
line-height:1.5em;
margin:2em 0 1em;
text-align:left;
}
table,th,td
{
border:1px solid black;
}
table{}
/* RESPONSIVE */
/* IE 10 FIX */
html[data-useragent*='MSIE 10.0'] .wrapper {height:auto}


@media only screen and (max-width: 1630px) {
.inner {
width:80%;
}
#headerbar {
width:90%;
padding:0 0 0 10%;
}
h1, .roadmap{
padding-left:10%;
}
}

@media only screen and (max-width: 1200px) {
.inner {
width:91%;
}
#headerbar {
width:95.5%;
padding:0 0 0 4.5%;
}
h1, .roadmap{
padding-left:4.5%;
}
}

@media only screen and (max-width: 980px) {
.inner {
width:100%;
}
#headerbar {
width:100%;
padding:0;
}
h1, .roadmap{
padding-left:0.5em;
}
}

For example, in IE11 I open the page and it’s good (but no slideshow background) and I get a warning before it executes any scripts, I click ok and then the background on the header disappears and the other elements at the top get screwed up.

I don’t know javascript but scanning the plugin file it looks like my own CSS may be screwing with the CSS that it adds, probably with the positioning.

/*!
 * jQuery.BgSwitcher
 *
 * @version  0.4.3
 * @author   rewish <rewish.org@gmail.com>
 * @license  MIT License (https://github.com/rewish/jquery-bgswitcher/blob/master/LICENSE.md)
 * @link     https://github.com/rewish/jquery-bgswitcher
 */
(function($) {
  'use strict';

  var loadedImages = {},

      slice = Array.prototype.slice,
      toString = Object.prototype.toString,

      corners = ['Top', 'Right', 'Bottom', 'Left'],
      backgroundProperties = [
        'Attachment', 'Color', 'Image', 'Repeat',
        'Position', 'Size', 'Clip', 'Origin'
      ];

  $.fn.bgswitcher = function() {
    var args = arguments,
        instanceKey = BgSwitcher.keys.instance;

    return this.each(function() {
      var instance = $.data(this, instanceKey);

      if (!instance) {
        instance = new BgSwitcher(this);
        $.data(this, instanceKey, instance);
      }

      instance.dispatch.apply(instance, args);
    });
  };

  // Backward Compatibility
  $.fn.bgSwitcher = $.fn.bgswitcher;

  /**
   * BgSwitcher
   *
   * @param {HTMLElement} el
   * @constructor
   */
  function BgSwitcher(el) {
    this.$el = $(el);
    this.index = 0;
    this.config = $.extend({}, BgSwitcher.defaultConfig);

    this._setupBackgroundElement();
    this._listenToResize();
  }

  $.extend(BgSwitcher.prototype, {
    /**
     * Dispatch
     *
     * @param {string|Array} one
     */
    dispatch: function(one) {
      switch (toString.call(one)) {
        case '[object Object]':
          this.setConfig(one);
          break;
        case '[object String]':
          this[one].apply(this, slice.call(arguments, 1));
          break;
        default:
          throw new Error('Please specify a Object or String');
      }
    },

    /**
     * Set config
     *
     * @param {Object} config
     */
    setConfig: function(config) {
      this.config = $.extend(this.config, config);

      if (typeof this.config.random !== 'undefined') {
        this.config.shuffle = this.config.random;
      }

      this.refresh();
    },

    /**
     * Set images
     *
     * @param {Array} images
     */
    setImages: function(images) {
      this.imageList = new this.constructor.ImageList(images);

      if (this.config.shuffle) {
        this.imageList.shuffle();
      }
    },

    /**
     * Set switch handler
     *
     * @param {Function} fn
     */
    setSwitchHandler: function(fn) {
      this.switchHandler = $.proxy(fn, this);
    },

    /**
     * Default switch handler
     *
     * @param {string} type
     * @returns {Function}
     */
    getBuiltInSwitchHandler: function(type) {
      return this.constructor.switchHandlers[type || this.config.effect];
    },

    /**
     * Refresh
     */
    refresh: function() {
      this.setImages(this.config.images);
      this.setSwitchHandler(this.getBuiltInSwitchHandler());
      this._prepareSwitching();

      if (this.config.start) {
        this.start();
      }
    },

    /**
     * Start switching
     */
    start: function() {
      if (!this._timerID) {
        this._timerID = setTimeout($.proxy(this, 'next'), this.config.interval);
      }
    },

    /**
     * Stop switching
     */
    stop: function() {
      if (this._timerID) {
        clearTimeout(this._timerID);
        this._timerID = null;
      }
    },

    /**
     * Toggle between start/stop
     */
    toggle: function() {
      if (this._timerID) {
        this.stop();
      } else {
        this.start();
      }
    },

    /**
     * Reset switching
     */
    reset: function() {
      this.index = 0;
      this._prepareSwitching();
    },

    /**
     * Go to next switching
     */
    next: function() {
      var max = this.imageList.count();

      if (!this.config.loop && this.index + 1 === max) {
        return;
      }

      if (++this.index === max) {
        this.index = 0;
      }

      this.switching();
    },

    /**
     * Go to previous switching
     */
    prev: function() {
      if (!this.config.loop && this.index === 0) {
        return;
      }

      if (--this.index === -1) {
        this.index = this.imageList.count() - 1;
      }

      this.switching();
    },

    /**
     * Select the switching at index
     *
     * @param {number} index
     */
    select: function(index) {
      if (index === -1) {
        index = this.imageList.count() - 1;
      }

      this.index = index;
      this.switching();
    },

    /**
     * Switching the background image
     */
    switching: function() {
      var started = !!this._timerID;

      if (started) {
        this.stop();
      }

      this._createSwitchableElement();
      this._prepareSwitching();
      this.switchHandler(this.$switchable);

      if (started) {
        this.start();
      }
    },

    /**
     * Destroy...
     */
    destroy: function() {
      this.stop();
      this._stopListeningToResize();

      if (this.$switchable) {
        this.$switchable.stop();
        this.$switchable.remove();
        this.$switchable = null;
      }

      if (this.$bg) {
        this.$bg.remove();
        this.$bg = null;
      }

      this.$el.removeAttr('style');
      this.$el.removeData(this.constructor.keys.instance);
      this.$el = null;
    },

    /**
     * Adjust rectangle
     */
    _adjustRectangle: function() {
      var corner,
          i = 0,
          length = corners.length,
          offset = this.$el.position(),
          copiedStyles = {
            top: offset.top,
            left: offset.left,
            width: this.$el.innerWidth(),
            height: this.$el.innerHeight()
          };

      for (; i < length; i++) {
        corner = corners[i];
        copiedStyles['margin' + corner] = this.$el.css('margin' + corner);
        copiedStyles['border' + corner] = this.$el.css('border' + corner);
      }

      this.$bg.css(copiedStyles);
    },

    /**
     * Setup background element
     */
    _setupBackgroundElement: function() {
      this.$bg = $(document.createElement('div'));
      this.$bg.css({
        position: 'absolute',
        zIndex: (parseInt(this.$el.css('zIndex'), 10) || 0) - 1,
        overflow: 'hidden'
      });

      this._copyBackgroundStyles();
      this._adjustRectangle();

      if (this.$el[0].tagName === 'BODY') {
        this.$el.prepend(this.$bg);
      } else {
        this.$el.before(this.$bg);
        this.$el.css('background', 'none');
      }
    },

    /**
     * Create switchable element
     */
    _createSwitchableElement: function() {
      if (this.$switchable) {
        this.$switchable.remove();
      }

      this.$switchable = this.$bg.clone();
      this.$switchable.css({top: 0, left: 0, margin: 0, border: 'none'});
      this.$switchable.appendTo(this.$bg);
    },

    /**
     * Copy background styles
     */
    _copyBackgroundStyles: function () {
      var prop,
          copiedStyle = {},
          i = 0,
          length = backgroundProperties.length,
          backgroundPosition = 'backgroundPosition';

      for (; i < length; i++) {
        prop = 'background' + backgroundProperties[i];
        copiedStyle[prop] = this.$el.css(prop);
      }

      // For IE<=9
      if (copiedStyle[backgroundPosition] === undefined) {
        copiedStyle[backgroundPosition] = [
          this.$el.css(backgroundPosition + 'X'),
          this.$el.css(backgroundPosition + 'Y')
        ].join(' ');
      }

      this.$bg.css(copiedStyle);
    },

    /**
     * Listen to the resize event
     */
    _listenToResize: function() {
      var that = this;
      this._resizeHandler = function() {
        that._adjustRectangle();
      };
      $(window).on('resize', this._resizeHandler);
    },

    /**
     * Stop listening to the resize event
     */
    _stopListeningToResize: function() {
      $(window).off('resize', this._resizeHandler);
      this._resizeHandler = null;
    },

    /**
     * Prepare the Switching
     */
    _prepareSwitching: function() {
      this.$bg.css('backgroundImage', this.imageList.url(this.index));
    }
  });

  /**
   * Data Keys
   * @type {Object}
   */
  BgSwitcher.keys = {
    instance: 'bgSwitcher'
  };

  /**
   * Default Config
   * @type {Object}
   */
  BgSwitcher.defaultConfig = {
    images: [],
    interval: 5000,
    start: true,
    loop: true,
    shuffle: false,
    effect: 'fade',
    duration: 1000,
    easing: 'swing'
  };

  /**
   * Built-In switch handlers (effects)
   * @type {Object}
   */
  BgSwitcher.switchHandlers = {
    fade: function($el) {
      $el.animate({opacity: 0}, this.config.duration, this.config.easing);
    },

    blind: function($el) {
      $el.animate({height: 0}, this.config.duration, this.config.easing);
    },

    clip: function($el) {
      $el.animate({
        top: parseInt($el.css('top'), 10) + $el.height() / 2,
        height: 0
      }, this.config.duration, this.config.easing);
    },

    slide: function($el) {
      $el.animate({top: -$el.height()}, this.config.duration, this.config.easing);
    },

    drop: function($el) {
      $el.animate({
        left: -$el.width(),
        opacity: 0
      }, this.config.duration, this.config.easing);
    },

    hide: function($el) {
      $el.hide();
    }
  };

  /**
   * Define effect
   *
   * @param {String} name
   * @param {Function} fn
   */
  BgSwitcher.defineEffect = function(name, fn) {
    this.switchHandlers[name] = fn;
  };

  /**
   * BgSwitcher.ImageList
   *
   * @param {Array} images
   * @constructor
   */
  BgSwitcher.ImageList = function(images) {
    this.images = images;
    this.createImagesBySequence();
    this.preload();
  };

  $.extend(BgSwitcher.ImageList.prototype, {
    /**
     * Images is sequenceable
     *
     * @returns {boolean}
     */
    isSequenceable: function() {
      return typeof this.images[0] === 'string' &&
          typeof this.images[1] === 'number' &&
          typeof this.images[2] === 'number';
    },

    /**
     * Create an images by sequence
     */
    createImagesBySequence: function() {
      if (!this.isSequenceable()) {
        return;
      }

      var images = [],
          base = this.images[0],
          min = this.images[1],
          max = this.images[2];

      do {
        images.push(base.replace(/\\.\\w+$/, min + '$&'));
      } while (++min <= max);

      this.images = images;
    },

    /**
     * Preload an images
     */
    preload: function() {
      var path,
          length = this.images.length,
          i = 0;

      for (; i < length; i++) {
        path = this.images[i];
        if (!loadedImages[path]) {
          loadedImages[path] = new Image();
          loadedImages[path].src = path;
        }
      }
    },

    /**
     * Shuffle an images
     */
    shuffle: function() {
      var j, t,
          i = this.images.length,
          original = this.images.join();

      if (!i) {
        return;
      }

      while (i) {
        j = Math.floor(Math.random() * i);
        t = this.images[--i];
        this.images[i] = this.images[j];
        this.images[j] = t;
      }

      if (this.images.join() === original) {
        this.shuffle();
      }
    },

    /**
     * Get the image from index
     *
     * @param {number} index
     * @returns {string}
     */
    get: function(index) {
      return this.images[index];
    },

    /**
     * Get the URL with function of CSS
     *
     * @param {number} index
     * @returns {string}
     */
    url: function(index) {
      return 'url(' + this.get(index) + ')';
    },

    /**
     * Count of images
     *
     * @returns {number}
     */
    count: function() {
      return this.images.length;
    }
  });

  $.BgSwitcher = BgSwitcher;
}(jQuery));

That sounds plausible, although I’m nopt sure where you’re seeing that.
I’ll move this thread to the CSS forum as there are people over there that’ll be able to help you better.

Hi,

The problem is twofold and has to do with positioning inside tables and table-cells and z-index.

Absolute positioning doesn’t work in relation to elements that are display:table or row or cell and so your slider absolute places the elements in respect of the body instead and the z-index:-1 puts the slider images behind the body’s background.

The only thing you can do in this case is to nest an inner element in your table cell and apply the routine to that inner element instead.

e.g.


<div class="tr">
		<div class="tc header">
				[B]<div class="header-inner">[/B]
						<ul id="headerbar">
								<li><a href="#content" id="skip">Skip to content</a>
								<li><a href="#"><span>link</span> <span>link</span></a>
								<li><a href="#">link</a>
								<li><a href="#">link</a>
								<li><a href="#">link</a>
								<li><a href="#">link</a>
								<li><a href="#">link</a>
								<li><a href="#">link</a>
						</ul>
				</div>
		</div>
</div>



.header-inner{
	height:100%;
	position:relative;
	z-index:1;	
}

It is likely though that some browsers will not honour the height:100% when based on a table-cells height and may collapse to zero. However as your header has a fixed height then you should be ok which begs the question as to why you used a table-row for it when its a fixed size anyway.

All these sliders fail when basing their context on a display:table-cell because of the way that absolute (and relative) positioning is handling on table-cells so it is best to only use them on normal elements.

I originally put the height so that the margin on #headerbar (navigation) wouldn’t collapse with its container, so instead I gave a height on its container and used padding to place the headerbar vertically. Going to have another look at that aspect along with your ideas. The thing is I want the picture to be shown in whole vertically, thinking I’d later implement scale-down and percentage versions for responsiveness. On the other hand I want text/height scalability on the #headerbar so I can’t use margins on it do determine the height of its container.

I guess when I have an element display:table I reflexively make all its children display:table-something.

If you have a live demo it would be easier for us to offer specific code and to understand your requirements more easily.:slight_smile:

If you are placing a background image then it has to be placed over the background of an element and that element needs to have height by its content, its height or by some other placeholder or there is nothing to paint the background on.

Here’s a live demo. If you’re interested, go to the /images/ directory to browse some of the other header photos. The way I have it now is setting a height and padding on the element with the background photo so that the link bar has the effect of being pushed down by the shield above the first (or second if you count “skip to content”) link. In a [URL=“http://tinyurl.com/nk9paf4”]second test I removed the tr container of the header and the tc class off the header (so only display block) and but then there’s a gap between the header and the next (or first rather) TR.

Are you messing with the site live? I refreshed the page after messing with it to get a clean slate and then I saw changes.

Also, I’m not entirely sure what you want - I’m not seeing any gap on FF/IE11 on either link. Perhaps I’m missing something?

I haven’t touched it since my last post in which I have 2 links, on the second link I have a gap in Chrome between the bottom of the photo and the following heading (h1). I want to implement a javascript background changer that will change the photo that is the background of the .header element. Paul thinks (and so do I) that the way the script works is adding an element with absolute positioning, which is messed up by the fact that .header in indextest.html is displayed as a table cell. So in indextest2.html I removed its parent (which is a div with class tr) and removed the tc (tablecell) class from .header, meaning it’s at its default display (block), but then I see a gap, which I assume is caused by the following table-rows attempting to be evenly spaced or something.

indextest.html has the right look but breaks when I add the javascript, indextest.html is trying another approach (not using display:table-cell since the element has a defined height anyway) but I get the gap, still haven’t added the javascript in either test on the live site.

Edit: confirming I also see a gap in firefox on indextest2.html but oddly not in IE11.
Edit2: Actually a gap in IE too, just not when there’s a scrollbar. Meaning when you remove the scrollbar and expand the window vertically a gap is created under the photograph.

That gap is only because of the line height and font size you have set on h1{}. Setting line-height:1; on that specific h1 would remove all spacing.

I don’t think you know what gap I’m seeing, the lineheight only affects the height of the H1 and the background color expands with it. I’m saying that between the bottom of the photo and the top of the h1 brown background a gap (only see body background color) manifests when the viewport is expanded vertically eliminating the scrollbar (if there is one to start).

Ah ok I see it now. Removing the display:table-row would fix this although that’s not really an option.

I didn’t see the issue before since I had a big monitor. On .header could you set display:table-cell? Would that mess with anything? I’m resizing my screen and the gap is gone now no matter what it gets resized to.

Edit-was testing on index2. You say you have tried…one minute please…

Can you make a 3rd page replicating the live site WITH the Javascript added in? Hard to test when knowing JS could screw it up.

At the url, indextest3 is indextest with the added script which breaks the layout considerably. indextest4 is indextest2 with the script, no photo shows, gap appears (though it’s connected to the no photo so you can’t see it as a gap), layout positioning isn’t broken (except for the gap appearing). indextest5 is just the script on a div which works correctly.

Working with indextest4.html.

Give .header position:relative. Now in the JS you will need to make it so the z-index is changed.

This line of code

        zIndex: (parseInt(this.$el.css('zIndex'), 10) || 0) -1,

It’s in this

<script src="javascript/rewish-jquery-bgswitcher-0.4.3-0-g8d31c42/rewish-jquery-bgswitcher-8d31c42/jquery.bgswitcher.js"></script>

Go into that file and go find that line. Now make the line this

zIndex: (parseInt(this.$el.css('zIndex'), 10) || 1) -1,

Make that 0, 1

Edit-Still have a gap. Give me a moment.

Finally, give .header also display:table-row and remove that padding on it, and instead add that to the height of .header. So .header has height:501px (height of the image) and padding:0;

It’s working I created a testing directory, here is indextest4.html with that fix and [URL=“http://tinyurl.com/nw7pnvt”]here I added a surrounding tr with specified height to fix the gap, and I will work forward from that. Thank you all for the help, especially Ryan. From what I figured out the javascript makes a background element to get the fade effect (probably by changing opacity), and your modification allows it to work with that CSS setup.

Please see my updated post. But yes it does that by opacity.

Changing the height and display:table-row on .header{} will remove the gap.