JSXGraph logo
JSXGraph
JSXGraph share

Share

Using CSS styles
QR code
<iframe 
    src="https://jsxgraph.org/share/iframe/using-css-styles" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Using CSS styles" 
    allowfullscreen
></iframe>
This code has to
<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>

<script type = "text/javascript"> 
    /*
    This example is licensed under a 
    Creative Commons Attribution ShareAlike 4.0 International License.
    https://creativecommons.org/licenses/by-sa/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    JXG.Options.text.cssDefaultStyle = '';
    JXG.Options.text.highlightCssDefaultStyle = '';
    JXG.Options.text.cssClass = 'myDefaultFont';
    
    var board = JXG.JSXGraph.initBoard(BOARDID, { boundingbox: [-5, 5, 5, -5], keepaspectratio: true });
    
    var txt = board.create('text', [1, 2, " <span id='par'>(</span> Hello world <span id='par'>)</span>"],
    {
        cssClass: 'myFont',
        strokeColor: 'red',
        highlightCssClass: 'myFontHigh',
        fontSize: 20
    });
    
    var p = board.create('point', [0, 0]);
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-sa/4.0/

Please note you have to mention 
The Center of Mobile Learning with Digital Technology
in the credits.
*/

const BOARDID = 'your_div_id'; // Insert your id here!

JXG.Options.text.cssDefaultStyle = '';
JXG.Options.text.highlightCssDefaultStyle = '';
JXG.Options.text.cssClass = 'myDefaultFont';

var board = JXG.JSXGraph.initBoard(BOARDID, { boundingbox: [-5, 5, 5, -5], keepaspectratio: true });

var txt = board.create('text', [1, 2, " <span id='par'>(</span> Hello world <span id='par'>)</span>"],
{
    cssClass: 'myFont',
    strokeColor: 'red',
    highlightCssClass: 'myFontHigh',
    fontSize: 20
});

var p = board.create('point', [0, 0]);
<jsxgraph width="100%" aspect-ratio="1 / 1" title="Using CSS styles" description="This construction was copied from JSXGraph examples database: BTW HERE SHOULD BE A GENERATED LINKuseGlobalJS="false">
   /*
   This example is licensed under a 
   Creative Commons Attribution ShareAlike 4.0 International License.
   https://creativecommons.org/licenses/by-sa/4.0/
   
   Please note you have to mention 
   The Center of Mobile Learning with Digital Technology
   in the credits.
   */
   
   JXG.Options.text.cssDefaultStyle = '';
   JXG.Options.text.highlightCssDefaultStyle = '';
   JXG.Options.text.cssClass = 'myDefaultFont';
   
   var board = JXG.JSXGraph.initBoard(BOARDID, { boundingbox: [-5, 5, 5, -5], keepaspectratio: true });
   
   var txt = board.create('text', [1, 2, " <span id='par'>(</span> Hello world <span id='par'>)</span>"],
   {
       cssClass: 'myFont',
       strokeColor: 'red',
       highlightCssClass: 'myFontHigh',
       fontSize: 20
   });
   
   var p = board.create('point', [0, 0]);
</jsxgraph>

Using CSS styles

It is possible to use CSS classes for texts in a JSXGraph construction. A CSS class can be used as default text style by setting before the call of initBoard(): ```javascript JXG.Options.text.cssClass = 'myDefaultFont'; ``` After initBoard() has been called the default class may be changed by calling ```javascript board.options.text.cssClass = 'myDefaultFont'; ``` Highlighted text uses the CSS class highlightCssClass. ```javascript JXG.Options.text.highlightCssClass = 'myDefaultFont'; ``` As with all JSXgraph options, CSS class can also be set while creating a text element. See the example below. **Attention:** The CSS properties color and font-size are overwritten by the JSXGraph properties strokeWidth and fontSize.
// Define the id of your board in BOARDID

JXG.Options.text.cssDefaultStyle = '';
JXG.Options.text.highlightCssDefaultStyle = '';
JXG.Options.text.cssClass = 'myDefaultFont';

var board = JXG.JSXGraph.initBoard(BOARDID, { boundingbox: [-5, 5, 5, -5], keepaspectratio: true });

var txt = board.create('text', [1, 2, " <span id='par'>(</span> Hello world <span id='par'>)</span>"],
{
    cssClass: 'myFont',
    strokeColor: 'red',
    highlightCssClass: 'myFontHigh',
    fontSize: 20
});

var p = board.create('point', [0, 0]);

license

This example is licensed under a Creative Commons Attribution ShareAlike 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.