Home
Random example
Search
Applications
Chemistry
Economy
Famous theorems
Geography
Physics
Sports
Test
Assessment
Calculus
3D
Applied calculus
Basic calculus
Differential equations
Function plotting
Implicit plotting
Sequences and series
Charts and data
Charts
Statistics
Curves
Interpolation
Intersection, Union, Difference
Lindenmayer Systems
Splines
Geometry
3D
Analytic
Euclidean
Basic constructions
Mappings
Non-Euclidean
Projective
Symmetry
Technical
Accessibility
Animation
Roulettes
Board options
First steps
Images
JSXGraph objects
Arcs and angles
Axes
Circles
Glider
Groups
Lines and arrows
Point
Polygons
Slider
Turtle
Vectors
JessieCode
Texts
Transformations
Video
jsxgraph.org
JSXGraph logo
JSXGraph
JSXGraph share

Share

Using CSS classes and styles
Show plain example
QR code
<iframe 
    src="https://www.jsxgraph.uni-bayreuth.de/share/iframe/using-css-styles" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Using CSS classes and styles" 
    allowfullscreen
></iframe>
This code has to
<style>
    .myFont {
        text-decoration: underline;
    }

    .myDefaultFont: {
        font-family: monospace;
    }

    .myFontHigh {
        font-weight: bold;
        border: 1px solid black;
    }

    .myFontHigh span {
        font-size: 150%;
    }
</style>

<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: [-3, 3, 3, -3]
    });
    
    var txt = board.create('text', [0, 1, " <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], {
        name: 'AiX'
    });
 </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: [-3, 3, 3, -3]
});

var txt = board.create('text', [0, 1, " <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], {
    name: 'AiX'
});

Using CSS classes and styles

JSXGraph objects
Technical
Texts
It is possible to supply CSS classes to JSXGrap elements. This is especially useful for texts. A CSS class can be used as default text style by setting __before__ the call of `initBoard()` and is defined for *all* boards of that web page. ```javascript JXG.Options.text.cssClass = 'myDefaultFont'; ``` After `initBoard()` has been called the default class for a specific board 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 may be overwritten by the JSXGraph properties `strokeWidth` and `fontSize`.
<style>
    .myFont {
        text-decoration: underline;
    }

    .myDefaultFont: {
        font-family: monospace;
    }

    .myFontHigh {
        font-weight: bold;
        border: 1px solid black;
    }

    .myFontHigh span {
        font-size: 150%;
    }
</style>
// 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: [-3, 3, 3, -3]
});

var txt = board.create('text', [0, 1, " <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], {
    name: 'AiX'
});

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.