Apply Stylesheet to One Product Page Section

leeroyster
Excursionist
15 1 1

Good Afternoon

I've put together some code (with the support of W3) that gives me a nice and simple gallery slider with buttons on either side of the image (on the product page) that works a charm. 

However, because of the stylesheet reference to w3schools CSS file, it changes the look and feel of the entire product page - which isn't good! This line is required in order for the buttons to appear properly on the images, so is there a way I can isolate the reference to the CSS file to enable the image gallery to work, but without affecting the rest of the page? 

Code as follows:

<!DOCTYPE html>
<div class="Gallery">
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css".Gallery>
<style>
.mySlides {display:none}
.w3-left, .w3-right, .w3-badge {cursor:pointer}
.w3-badge {height:13px;width:13px;padding:0}
</style>
<body>


<div class="w3-content w3-display-container" style="max-width:800px">
  <img class="mySlides" src="https://cdn.shopify.com/s/files/1/0560/3151/0720/files/IN_HP_Essence_9523_7075_EssenceMaze_7071_001.jpg?v=1619534078" style="width:100%">
  <img class="mySlides" src="https://cdn.shopify.com/s/files/1/0560/3151/0720/files/IN_Essence_9926_EssenceMaze_9505_003.jpg?v=1619534078" style="width:100%">
  <img class="mySlides" src="https://cdn.shopify.com/s/files/1/0560/3151/0720/files/IN_Essence_8012_9504_EssenceStructure_7511_001.jpg?v=1619534078" style="width:100%">
  <img class="mySlides" src="https://cdn.shopify.com/s/files/1/0560/3151/0720/files/IN_Essence_6408_7075_2925-2915_EssenceMaze_7071_9107_001.jpg?v=1619534078" style="width:100%">
  <div class="w3-center w3-container w3-section w3-large w3-text-white w3-display-bottommiddle" style="width:100%">
    <div class="w3-left w3-hover-text-khaki" onclick="plusDivs(-1)">&#10094;</div>
    <div class="w3-right w3-hover-text-khaki" onclick="plusDivs(1)">&#10095;</div>
    <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(1)"></span>
    <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(2)"></span>
    <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(3)"></span>
	<span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(4)"></span>
  </div>
</div>
</div>
<script>
var slideIndex = 1;
showDivs(slideIndex);

function plusDivs(n) {
  showDivs(slideIndex += n);
}

function currentDiv(n) {
  showDivs(slideIndex = n);
}

function showDivs(n) {
  var i;
  var x = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("demo");
  if (n > x.length) {slideIndex = 1}
  if (n < 1) {slideIndex = x.length}
  for (i = 0; i < x.length; i++) {
    x[i].style.display = "none";  
  }
  for (i = 0; i < dots.length; i++) {
    dots[i].className = dots[i].className.replace(" w3-white", "");
  }
  x[slideIndex-1].style.display = "block";  
  dots[slideIndex-1].className += " w3-white";
}
</script>

</body>
</html> 

If I remove the line that references the CSS file, then the buttons don't render properly

I simply add this code to the very bottom of the product page, and it works nicely - just need to resolve this formatting issue!

Thanks for any help!
Lee 

0 Likes