0

I am very new to coding. I can code in html and css and am currently learning javascript. I am building a website, and i am quite satisfied with the result so far, but i can't figure out how to make my website responsive. The page that i am talking about is .... I want to make this page so if one of the buttons is clicked a new page will come up with info off the clicked subject and a video about the subject.

My question is: What is the best way of making something like that?

I thought about making every page a seperate .html file, but figured out that i would have hundreds off .html files that way and there should be a more effective way off making this.

Sorry for my bad grammer, i'm not that good at english.

*edit

Just an example of what i want to make:

http://i61.tinypic.com/j67i2v.jpg

This would be my main page, and if (in this case) de cecco is clicked i would want this page to show up:

http://i60.tinypic.com/2lo0r50.jpg

  • Do you want to create a responsive site or dynamic site or both ? I don't quite understand you... – Milan and Friends Apr 05 '14 at 21:19
  • I am not quite sure what the difference is, my apologies.. – user3502218 Apr 05 '14 at 21:25
  • I don't really care if it is reponsice or dynamic, i would like to have information appear on my site that is not always visible, so if a link is clicked, some information appears on that same page – user3502218 Apr 05 '14 at 21:26
  • Look at my answer on [this](http://stackoverflow.com/questions/22886941/changing-content-on-the-same-html-file-page/22887278#22887278) question. You can use tabbed content. – Milan and Friends Apr 05 '14 at 21:58
  • If you are new to coding, I would look into [bootstrap](http://getbootstrap.com) for making your website. It removes the headache of learning CSS while making webpages, which really allows you to quickly understand the core concepts of good HTML and JavaScript coding. – royhowie Apr 05 '14 at 22:12

1 Answers1

2

Just for your own edification, the term "responsive" usually refers to a site that responds to changes in screen size (for example, using CSS media queries to change the appearance of site based on whether the user is browsing on a mobile device or desktop.)

Going on, there are many solutions to your problem. One easy way (while avoiding any additional requests to the server), is to create hidden elements, and when a link is clicked, the element is shown.

See this jsbin example.

HTML

<button value="#box" id="box-button">Show info</button>

<div id="box">Some info is in this box<button class="x">x</button></div>

CSS

button {
    cursor: pointer;
}

#box {
    display: none;
    position: absolute;
    margin: auto;
    left: 0; right: 0; top: 0; bottom: 0;
    width: 50%; height: 50%;
    padding: 1em;
    box-shadow: 0 0 20px 0 #555;
    border-radius: 10px;
    background: #fff;
}

.x {
    color: red;
    position: absolute;
    top: 0; right: 0;
    padding: 10px;
    border: none;
    background: #fff;
}

jQuery

$('#box-button').on('click',function() {
   $($(this).attr('value')).css('display','block');
});

$('.x').on('click', function() {
  $(this).parent().css('display','none');
});

The downside of doing it like this is that, depending on how many pop-up boxes you have, the browser will have to load a lot more DOM elements, when maybe all of them won't be used.

Another way to do this is with AJAX calls, sort of like you referenced in your original question (but yes, there could be a hundred .html files, like you said).

The upside of this is that the DOM only contains what it needs at any given time. The downside is that you have to send a request to the server.

It'll be hard for me to make a jsbin example for this, so I'll provide you with a little code showing an example:

HTML

<button id="someButton" value="http://www.yourwebsite/someresource.html">show info</button>
<div id="popup"></div>

CSS

#popup {
    display: none;
    position: absolute; /* etc. */
}

jQuery

$('#someButton').on('click',function() {
    $('#popup').load($(this).attr('value'));
});
Josh Beam
  • 19,292
  • 3
  • 45
  • 68
  • Is there also a way so i can delete the information already on the page? Is it an option to make everything out of hidden elements? – user3502218 Apr 05 '14 at 21:43
  • @user3502218, If you mean delete the information in the popup box, then yes, there are many ways to do that. In the jsbin I provided, you can exit out of the popup. And then, when you click another button, it can show another hidden element with different information. – Josh Beam Apr 05 '14 at 21:47
  • @user3502218, if you go with the AJAX way of doing it, then the content will be deleted and re-populated every time you click a new button. There will only be one popup element. – Josh Beam Apr 05 '14 at 21:47
  • I edited my question with two pictures to try and make my question more clear, but i think the AJAX way will work for me! Thanks again! – user3502218 Apr 05 '14 at 22:01
  • @user3502218, see the updated [jsbin](http://jsbin.com/laganaba/1/) – Josh Beam Apr 06 '14 at 00:22