2
It’s a Newbie question, but I’m having a hard time.
I have 3 tabs that are like this:
But I’d like you to stay in the center like this:
Also instead of text, I would like to place images.
My CSS for tabs are like this:
/* Style the tab */
div.tab {
overflow: hidden;
border: none;
margin-top: -4px;
background-color: #36D100;
position:sticky;
height: 102px;
width: 100%;
}
/* Style the buttons inside the tab */
div.tab button {
background-color: inherit;
margin-top: 7px;
border: none;
margin-bottom: center;
cursor: pointer;
transition: 0.3s;
font-size: 17px;
height: 95px;
width: 186px;
}
/* Change background color of buttons on hover */
div.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
div.tab button.active {
background-color: #fff;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 0px solid #ddd;
border-top: none;
}
And my HTML this way:
<content>
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" active>London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent" data-ng-click="London">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</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";
}
</script>
</content>
How can I do?
It worked out! Thank you!
– Ramos
@Ramos I updated the answer giving hint of how to put image instead of text.
– Sam
You know how I can put images in place of texts?
– Ramos
@Ramos the
background-size:cover;
is optional. Serves only in my example for image to fit on button.– Sam