How to create tabs in a section of homepage to connect 3 different blogs contents?

Tourist
4 0 0

Hi,

I had three different topics of blogs (categorize with them as news, media, campaign) and I would like to put them in a section by switching tabs.

I tried to write the following simple code but no idea how to connect blog contents.

Note: I am using Expression theme which has a section can be added with customer HTML. Appreciate for any suggestion. Thanks.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial;}

/* Style the tab */
.tab {
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
.tab button {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
  font-size: 17px;
}

/* Change background color of buttons on hover */
.tab button:hover {
  background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
  background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
  display: none;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-top: none;
}
</style>
</head>
<body>

<h2>Tabs</h2>
<p>Click on the buttons inside the tabbed menu:</p>

<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'News')" id="defaultOpen">News</button>
  <button class="tablinks" onclick="openCity(event, 'Media')">Media</button>
  <button class="tablinks" onclick="openCity(event, 'Campaign')">Campaign</button>
</div>

<div id="News" class="tabcontent">
  <h3>News</h3>
  <p>connect to blog category news</p>
</div>

<div id="Media" class="tabcontent">
  <h3>media</h3>
  <p>connect to blog category media</p> 
</div>

<div id="Campaign" class="tabcontent">
  <h3>campaign</h3>
  <p>connect to blog category campaign</p>
</div>

<script>
function openCity(evt, cityName) {
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
   
</body>
</html> 

 

0 Likes