HTML5 + CSS3 draw a jagged rectangle and html5css3 draw a sawtooth
Recently, I have been typing Html5 + Css3 to share some of the things I think are worth learning.
How to draw a jagged rectangle:
We know that canvas can be used to draw images. canvas is a new tag that appears in HTML5. It is used to draw images on webpages. H5 canvas uses Javascript to draw images on webpages.
The above jagged rectangle is drawn using canvas.
Implementation Code:
Copy XML/HTML Code to clipboard
- <! Doctype html>
- <Html lang = "en">
- <Head>
- <Meta charset = "UTF-8">
- <Title> sawtooth chart </title>
- <Script type = "text/javascript">
- Window. addEventListener ("load", eventWindowLoaded, false );
- Function eventWindowLoaded (){
- Var x, y;
- Var theCanvas = document. getElementById ("canvas ");
- Var context = theCanvas. getContext ("2d ");
- Context. strokeStyle = '# CB9A61 ';
- Context. lineWidth = 10;
- Context. strokeRect (10, 10, theCanvas. width-20, theCanvas. height-20 );
- Context. fillStyle = "# FFFFFF ";
- For (x = 5; x <= canvas. width; xx = x + 10 ){
- Context. beginPath ();
- Context. arc (x, 5, 5, 0, Math. PI * 2, true );
- Context. arc (x, canvas. height-5, 5, 0, Math. PI * 2, true );
- Context. closePath ();
- Context. fill ();
- }
- For (y = 5; y <= canvas. height; yy = y + 10 ){
- Context. beginPath ();
- Context. arc (5, y, 5, 0, Math. PI * 2, true );
- Context. arc (canvas. width-5, y, 5, 0, Math. PI * 2, true );
- Context. closePath ();
- Context. fill ();
- }
- }
- </Script>
- </Head>
- <Body>
- <Div style = "position: absolute; top: 100px; left: 100px;">
- <Canvas id = "canvas" width = "400" height = "170" top = 50px; left = 50px;>
- </Div>
- </Body>
- </Html>
How to write the following shape, a rectangle is divided into two parts, separated by a diagonal line, two colors.
At first it was such an idea that a div was used to draw a diagonal line in the middle and divide it into two parts, two colors, but they were not implemented. Due to the weak front-end and limited capabilities, I thought of another solution.
With three Divs, the left and right are two divs. Setting width and height plays an important role in this part:
It is actually a rectangle, divided into two triangles, and finally achieved the above effect. In another way, it is so easy to implement, so it cannot be suspended on a tree.
The Code is as follows:
Copy XML/HTML Code to clipboard
- <! Doctype html>
- <Html lang = "en">
- <Body style = "margin: 0 0 0 0;">
- <Div id = "1" style = "background-color: #727171; width: 50px; height: 20px; float: left"> </div>
- <Div id = "2" style = "float: left; border-width: 10px; border-color: #727171 #9fa0a0 #9fa0a0 #727171; border-style: solid "> </div>
- <Div id = "3" style = "background-color: #9fa0a0; width: 50px; height: 20px; float: left"> </div>
- </Body>
- </Html>
In the future, I will continue to summarize some knowledge about HTML and CSS. The front-end knowledge looks simple, but it is actually a meticulous work that can train a person's patience. From Simplicity to complexity, from entry to depth, you can improve yourself a little bit.