Other#

Here are features that I haven’t had time to put into some more specific pages yet.

from IPython.display import HTML

Common attributes#

id - object identificator#

style set a style of element#

Allows to use integrated CSS for html elements.

<property1 name>:<setted value>;<property2 name>:<setted value>;...;<propertyn name>:<setted value>

%%HTML
<p style="color:blue">Blue text color</p>
<p style="background:red">Red background color</p>
<p style="background:red;color:blue">Red background color</p>

Blue text color

Red background color

Red background color

title - hint text#

If you hold the mouse for some time on the element created by the tag with the title attribute - close to the mouse, a small hint appears. So try it wit text which is the result for the next cell.

%%HTML
<p title="hello im title">text with title</p>

text with title

Content tags#

<img> add image to html#

src - set picture#

You can add url of the image or filepath on computer. In this argument you can use:

  • url;

  • filename on computer;

  • base64 - use the following syntax data:image/<img type>;base64;<base64 code>:

    • get base64 from bash: base64 <filename>;

    • get base64 from python: import base64; base64.b64encode(<binary picture data>).

%%HTML
<img src="https://content.codecademy.com/courses/web-101/web101-image_brownbear.jpg"/>
<img src="html_files/display_picture.jpg">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA
SklEQVQokc2QSQ4AIAgDW+L/v1wvmhDFhXiRG800kKEEITHmF3IGxsxmJHHhjwKfLF0VIpXLdwiY
FPuPYKm9dCp1GABKD3clOS0V5DQSGUBEBc8AAAAASUVORK5CYII=" width=200 height=200>

alt - text hint#

Describes the text that will be used if the picture cannot be uploaded. There no option to show how it works in jupyter notebook, but the html page with the following code:

%%bash
cat html_files/img_alt_ex.html
<img src="unreal image" alt="description of some image"/>

You can check here.

<video> - insert video#

controls handle video#

Attributes allow you to set controls for handling the video playback process. In the following example I have inserted the first video with the control attribute and the second without.

%%HTML
<video src="html_files/some_video.webm" widht=200 height=200 controls>
</video>
<video src="html_files/some_video.webm" widht=200 height=200>
</video>

Other tags#

<div> - division#

Helps to group html elements.

<style> - style for element group{#sec-style_tag}#

By useing this tag inside <head> tag you can set some css properties.

In the following example I set styles for all <p> and <img> tags in html page. You can check the results here. I can’t show in Jupyter notebook because the results are applied to the whole notebook.

with open("html_files/style_tag.html") as file:
    print(file.read())
<head>
    <style>
        p {text-align:center; color: red}
        img {border: 5px solid blue}
    </style>
</head>
<body>
    <p> Test paragraph1</p>
    <p> Test paragraph2</p>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA
SklEQVQokc2QSQ4AIAgDW+L/v1wvmhDFhXiRG800kKEEITHmF3IGxsxmJHHhjwKfLF0VIpXLdwiY
FPuPYKm9dCp1GABKD3clOS0V5DQSGUBEBc8AAAAASUVORK5CYII=">
</body>

<details> - hiden info#

Basics#

You can describe some information that is hidden by default, but appears when you press the “arrow” button.

%%HTML
<details>
Some hidden information.
</details>
Some hidden information.

By using <summary> tag you can add extra information.

%%HTML
<details>
    <summary>Details title<button>Test button</button></summary>
    Some hidden information
</details>
Details title Some hidden information

Overlapping#

By default, expanded <details> will move the following content. So the following example shows how expanded details moves div.

%%HTML
<details>
    line 0 <br>line 1 <br>line 2 <br>line 3 <br>line 4 <br>line 5 <br>line 6 <br>line 7 <br>line 8 <br>line 9 <br>
</details>
<details>
    line 0 <br>line 1 <br>line 2 <br>line 3 <br>line 4 <br>line 5 <br>line 6 <br>line 7 <br>line 8 <br>line 9 <br>
</details>
<div>
    Some other content
</div>
line 0
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 0
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
Some other content