Placing Gaps on a Background Graphic (CSS)

Last modified by Anna Paul-Hasenfuss on 30.10.2024

ONYX allows you to customise the question design with CSS. Using CSS, you can also place elements on the screen. This makes it possible to place gaps on a background graphic.

Note: Placing gaps on a graphic only works in the browser. The export views (PDF export, exam overview page, etc.) do not allow for a correct question display. A prerequisite for placing individual gaps on a graphic is basic knowledge of HTML and CSS.

The graphic match interaction question type is also suitable for implementing many scenarios.

The procedure for placing gaps on a background graphic is explained using the example of a question about Saxony. A map of the Free State of Saxony serves as a background graphic. Three gaps are placed on the map so that the names of the cities can be entered directly in the correct place on the map.

Beispiel Anwendung1png

STEP 1: Create new question in text entry format

The ONYX Editor supports various text entry formats (e. g. text entry, numerical input, calculation, formula comparison). Placing the gaps on a background graphic works the same for all formats. In the following, instructions on how to place gaps are provided for a simple text entry interaction. To create a new question, click on the "New question” button. Then select the "text entry interaction" question type and enter a title for your question.

STEP 2: Edit question and add content

All question content can be added via the HTML input field in the Text entry interaction section. Start by entering your question text, e. g. "Name the three independent cities of the state of Saxony".

Now add the background graphic on which the gaps should be placed later.

Then add any number of gaps directly below the graphic. Define the correct solution and the maximum score for each gap. You can also configure additional settings.

Note: The gaps need to be placed directly below the graphic.

STEP 3: Place gaps on graphic I (HTML)

Placing the gaps on the background graphic is achieved by CSS positioning. The only prerequisite is the definition of CSS classes in the HTML source code. You can view and edit the HTML source code of your question using the "Source code” option of the HTML editor.

Note: To make it easier for you to edit the HTML code, you should insert line breaks so that each element (<p>, <span>, <img />, etc.) is on a separate line.

Aufgabe - Quelltext öffnen_de.png
Aufgabe - sourcecode_de.png

You can identify your graphic by the following HTML code:

<img  data-cke-saved-src="media?r=mMjc2MzQ1MzI src="media?r=mMjc2MzQ1MzI ... />

The gaps are marked in the HTML as follows:

<img id="RESPONSE_1" class="mce_onyx_gap"  data-cke-saved-src="img/icons/gap-placeholder.png" src="img/icons/gap-placeholder.png" alt="" />

You need to set a container (<div>) with the class "gap-container" around the graphic and your gaps.

<div class="gap-container">
[graphic]
[gaps]
</div>

If you require CSS placement on the background graphic for several questions in the test, add [TITLEofQUESTION] to the class name. Insert an identifier for “TITLEofQUESTION” that is unique throughout the test.

<div class="gap-container [TITLEofQUESTION]">
[graphic]
[gaps]
</div>

Make sure that <div> encloses your graphic and all gaps. Do not forget the closing tag (</div>) following the last gap.

Aufgbe - HTML mit Container_de.png

Now add another container around each individual gap. For all containers (<span>), the class "gap” should be assigned. Another class should be assigned to identify each gap individually. We recommend to number your gaps in order, starting with class "gap1” for the first gap, "gap2" for the second gap and so on.

<span class="gap [gapID]"> </span>
Important

Please ensure not to alter the existing HTML code when editing the gaps. An incorrect adjustment in the HTML can render the whole question unusable.

Examples

<span class="gap gap1"> </span>
<span class="gap gap2"> </span>

Aufgabe - sourcecode2_de.png

STEP 4: Place gaps on graphic II (CSS)

To place your gaps on the background graphic, you now need to specify the exact position. This is done in a separate CSS file that can be uploaded to each question.

You can use the following CSS statements as a template for individual questions in the test:

.gap-container {position: relative;}
.gap {position: absolute;}

.[gapID] {top: [x]px; left: [y]px;} 

If you place gaps for several questions in the test using CSS and have thus used the class name "gap-container [TITLEofQUESTION]" in the HTML of the question, then deploy this template:

Note: Ensure there is a space between the question and the gap name.

Now insert your values for top and left in the statements related to the individual gaps (.gap1, .gap2, etc.) to determine their position. Add as many statements as there are gaps defined in your question. 

Save your file to a CSS file (.css) and add it to your question on the Options tab in the ONYX Editor.

Use the preview in the ONYX Editor to verify whether the question is properly displayed.

.gap-container {position: relative;}
.gap {position: absolute;}

.[TITLEofQUESTION] .[gapID] {top: [x]px; left: [y]px;}

Examples

.gap-container {position: relative;}
.gap {position: absolute;}

.Application1 .gap1 {top: 100px; left: 255px;}
.Application1 .gap2 {top: 50px; left: 75px;}
.Application1 .gap3 {top: 180px; left: 90px;}

Step 5: Add the CSS file

Save your statement in a CSS file (.css). Now you can upload this file in the Options tab under Layout settings. Detailed instructions on this can be found here Set Options or Test configuration.

Please note:

  • If the CSS file is uploaded to a question, it will affect the layout of such.
  • If the CSS file is uploaded to a test, all selection tasks of the entire test are designed accordingly.
  • If the Show all questions of a section per page option is activated on the test, a CSS file on an individual question affects all questions in the same section.