Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I haven't been able to find anything that will cause the images to adjust their vertical margins or to center vertically within the divs.

A photo of the current setup

XML
var to_add = "<div style='width:600px;width:100%'>"

//far left stims
to_add += "<div style='height:450px; width:200px; text-align:center;display:inline-block;border: 2px solid black;vertical-align:middle;'>";

to_add+="<br>"

var wrapper = $("<div id='jspsych-single-stim-upper-left' style='vertical-align:middle;'> </div>");
wrapper.html(trial.a_path_upper_left_stim);
to_add+= wrapper.html();

to_add+="<br>" //because I couldn't get top and bottom margins to work
to_add+="<br>"
to_add+="<br>"
to_add+="<br>"


var wrapper = $("<div id='jspsych-single-stim-lower-left' style='vertical-align:middle'> </div>");
wrapper.html(trial.a_path_lower_left_stim);
to_add+= wrapper.html();

to_add+="</div>"

//middle stim
to_add += "<div style='height:450px; width:200px;border: 2px solid black;display:inline-block;text-align:center;vertical-align:middle;'>";

to_add+="<br>"
// display stimulus

var wrapper = $("<div id='jspsych-single-stim-middle' style=' vertical-align: middle'> </div>");
wrapper.html(trial.a_path_middle_stim);
to_add+= wrapper.html();


to_add+="</div>"

//far right stims

to_add += "<div style='height:450px; width:200px; text-align:center;display:inline-block;border: 2px solid black;vertical-align:middle'>";

var wrapper = $("<div id='jspsych-single-stim-upper-right style='vertical-align:middle' > </div>");
wrapper.html(trial.a_path_upper_right_stim);
to_add+= wrapper.html();

to_add+="<br>"
to_add+="<br>"
to_add+="<br>"
to_add+="<br>"

var wrapper = $("<div id='jspsych-single-stim-lower-right' style='vertical-align:middle'> </div>");
wrapper.html(trial.a_path_lower_right_stim);
to_add+= wrapper.html();

to_add+="</div>"
to_add+="</div>"


display_element.append(to_add);
Posted
Comments
Sergey Alexandrovich Kryukov 6-Aug-15 18:30pm    
Just few notes: vertical centering is conceptually very different from horizontal. Vertical and horizontal directions are not equivalent. The page has fixed (at the time of rendering) width and free height. Likewise, the div height depends on its inner HTML, so, if the height is not fixed, there is nothing to center, but if you try to fix the height, it's dangerous, because the inner content may not fit at all (also nothing to center :-). You need to decide what you want. It could be as simple as automatic div height (the most usual thing) with fixed padding on top and bottom. Why not?

It's not wonderful that you could not find any code samples doing anything else, if you wanted something else. Almost all Web pages work as I explained above.

From the other hand, you can develop technique similar to desktop application: all content is laid out to precisely fit the inner page space. Say, you can have some footer exactly at the lower edge. If the size of page is greater than some sufficient minimum, you never see scroll bar. Then you would need JavaScript. You can see how such techniques work from my two JavaScript articles...

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900