0

I have a couple upcoming posts where I have multiple versions of the same poem all translated. I was thinking of giving two buttons to reveal each of them. I thought of implementing this as a double spoiler, but that would mean the poem could also be completely hidden (both spoilers closed) or be shown simultaneously in both versions (both spoilers open), whereas I would like to have one version and one only displayed at all times. Something like Edcel spreadsheets, where you have the buttons at the bottom to switch between sheets but cannot view multiple sheets simultaneously or not view any of the sheets. Can that be done in HTML? And if so, how?

Update

A now-deleted answer suggested Bootstrap Panels. I tried them out, but the following code:

<div class="panel-group">
  <div class="panel panel-default">
    <div class="panel-heading">Vulgate version</div>
    <div class="panel-body">pefanthi</div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">Campbell version</div>
    <div class="panel-body">Abanthi</div>
  </div>
</div>
This is merely a test post to try out "Boostrap Panels". It is not meant to make any sense, but only to be able to click on buttons, which previews do not (or at least, spoilers and links don't work in previews, which is why I'm posting this).

produces this:

enter image description here

Is that the expected output, in which case this is not what I'm after, or is there something wrong with the code?

I cannot think of a website with this kind of thing implemented. What I want to achieve is to have a row of (in this case two) buttons at some point in the page (in this test post the point would be the top, in the actual blog posts it will be after a short introduction which is nothing more than a <div style="text-align: justify"> and a couple <br>s) which, when clicked on, will either change a part of the page below them, or, if I click the already active one, not change it. In particular, in the above code, I want two buttons, with "Vulgate version" on the leftmost one and "Cambpell version" on the other one, so that the former is automatically activated and shows "pefanthi", whereas the latter can be activated by clicking and that means "pefanthi" goes away and is replaced by "Abanthi", and then if I click on "Vulgate version" again I get pefanthi back and Abanthi leaves. Just like happens with tabs from a single window of a browser like Firefox:

enter image description here

So in this comparison, I want a "Vulgate version" tab that shows the "pefanthi" and a "Campbell version" which shows the "Abanthi", while the text about that being a test post stays below whatever is displayed, like that "It looks like you haven't started Firefox in a while […]" text in the picture, but with no X to make it disappear.

Update 2

Just figured out a way to do almost what I want. Here it is:

<button title="Vulgate version" type="button" onclick="if(document.getElementById('Vspoiler') .style.display=='none') {document.getElementById('Vspoiler') .style.display=''; document.getElementById('spoiler') .style.display='none'}">Vulgate version</button>
<button title="Campbell version" type="button" onclick="if(document.getElementById('spoiler') .style.display=='none') {document.getElementById('spoiler') .style.display=''; document.getElementById('Vspoiler') .style.display='none'}">Campbell version</button>
<div id="Vspoiler" style="display:">pefanthi</div>
<div id="spoiler" style="display:none">Abanthi</div>

This way, if I click on a button and its content is shown, nothing happens, whereas if its content is not shown, it gets shown and the other button's content is hidden. The Vulgate version button has its content shown by default, so it is now impossible to have more or less than one button's contents shown.

There are two problems with this:

  1. If the spoilers are more than two - and one of the posts I'm planning to use this on will have from 3 to 5 - the code gets pretty complex, so I'd like to know if there is a way to make the buttons hide the other buttons' contents when clicked without having to place a display:none for each of the other buttons: can the buttons "talk to each others" the way Firefox tabs to?
  2. Having buttons that seem to do nothing is not good-looking IMO, so is there a way to make the button change look when it's pressed? For example, changing its color to the background color so it becomes almost invisible?

Update 3

Just found out how to change the color of a button:

style="background-color:<insert color>"

in the button tag. Implemented at this page, which is the rendered version of the above code. Now one question remains: how do I make each button change the other button's color, along with its own?

Update 4

This is exactly what I want. Except I tried adapting the code to my needs:

<ul class="nav nav-tabs">
  <li class="active"><a data-toggle="tab" href="#vulg">Vulgate version</a></li>
  <li><a data-toggle="tab" href="#C">Campbell version</a></li>
</ul>

<div class="tab-content">
  <div id="vulg" class="tab-pane fade in active">
    <p>pefanthi.</p>
  </div>
  <div id="C" class="tab-pane fade">
    <p>Abanthi.</p>
  </div>
</div>

and the result is this, which is just not right. What am I doing wrong?

Update 5

Just tried copy-pasting the whole part over here, and the result can be seen here, and is not what the page says it should be, so is the page misguided or is there a problem of HTML versions that makes the code work on that page but not on my Blogger blog?

Update 6

Following @crapier' comment, I looked at "BS get started" (what an unfortunate initialism :) ), and found the code:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

I added it to my page, and something happened. The tabs appeared, but they do not work. What is going on? Should I add another one of the code lines here?

Update 7

Apparently it only works when all three of the lines here are added, but why?

Update 8

Moved the matter over to here, so this question merits a closure.

MickG
  • 3,216
  • 2
  • 14
  • 22
  • Could you provide a visual reference for what you are trying to achieve? Also; this site is not for asking people to write code for you, but we will try to point you in the right direction and help debug code you've already attempted and are having problems with. – daddygames Dec 21 '17 at 17:20
  • @daddygames I don't remember any site with what I'm thinking of, but Excel spreadsheets seem like a good comparison. I would have googled before asking but wasn't sure what to google for. There was an answer which pointed me to Bootstrap Panels and that might be the thing, I'll try them right now. – MickG Dec 21 '17 at 17:35
  • @daddygames I updated my post with a near-solution and what is left to solve. The code in the post produces [this page](http://michelegorini.blogspot.it/2017/12/vulgate-version-pefanthi-campbell.html). – MickG Dec 21 '17 at 18:12
  • @daddygames I found code that should produce what I want but doesn't. See Update 4. What is going on? Why is that code not working? – MickG Dec 21 '17 at 21:38
  • 1
    If you want it to look like the example you posted in Update 4 you will need to include the css and js from the example that styles and provides interactivity you want (the bootstrap files). You can then apply further styling to get it to look exactly as you want. – crapier Dec 21 '17 at 21:50
  • @crapier Tried to figure out how to add "the bootstrap files", added ``, the tabs appeared, but clicking on non-active ones does nothing, and clicking on the active one scrolls down. What is going on? Just tried ``, and the tabs disappeared. Same goes for ``. Why do I need all three of these? – MickG Dec 21 '17 at 22:06
  • [**Do not post images of code, output or errors!**](https://meta.stackoverflow.com/q/303812/995714) – Rob Dec 21 '17 at 22:16
  • @Rob Why should I not post an image of the output? The question you link to doesn't seem to discourage that… It discourages posting screenshots of code or errors, which I haven't done, but not output… – MickG Dec 21 '17 at 22:21
  • Images are not searchable or accessible to those who need that. You can keep the image, if you want to, but only if you also include text. – Rob Dec 21 '17 at 22:23
  • @Rob Yeah but you wouldn't search for the output, and besides, the code is just above it so the text is there. Recreating the output doesn't seem useful to me: who would land here by googling for "Vulgate version" or "Campbell version" or that notice at the end of the image? – MickG Dec 21 '17 at 22:27
  • Your question asks if this can be done in HTML and the answer is no. But you moved the goalposts by adding CSS into the mix. You need to re-do your question and tags to reflect that but the question is far too broad for SO anyway as shown by this long running comment section with no answers. You should ask a specific question that will return one specific answer. https://stackoverflow.com/help/how-to-ask – Rob Dec 21 '17 at 22:27
  • 1
    Our visually impaired programmers are unable to read your images. I've been seeing waaaay too many copy/paste of images of code lately. – Rob Dec 21 '17 at 22:29
  • Moved the matter over to [this](https://stackoverflow.com/questions/47933659/a-couple-questions-about-bootstrap). @Rob good point but now that I've moved the matters away I guess it's pointless to recreate the output here. – MickG Dec 21 '17 at 22:40

0 Answers0