search
HomeWeb Front-endHTML Tutorial[css]我要用css画幅画(二)_html/css_WEB-ITnose

接着之前的[css]我要用css画幅画(一) , 今天,我又画一个房子,很简单,屋顶、墙壁、门。

 

现在开始,做得效果都只兼容chrome,所以下面的css3的属性可能只有-webkit-前缀。 我只是为了兴趣画画, 何必理会兼容性呢,是吧? 

 

html如下:

 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4     <meta charset="UTF-8"> 5     <title>Css Paint</title> 6     <link rel="stylesheet" type="text/css" href="css/sun.css" /> 7     <link rel="stylesheet" type="text/css" href="css/house.css" /> 8 </head> 9 <body>10     <div class="sun">11         <div class="sun-body"></div>12         <div class="sun-shine-light sun-shine-light1"></div>13         <div class="sun-shine-light sun-shine-light2"></div>14         <div class="sun-shine-light sun-shine-light3"></div>15         <div class="sun-shine-light sun-shine-light4"></div>16         <div class="sun-shine-light sun-shine-light5"></div>17     </div>18 19     <div class="house-width house">20         <div class="house-width house-roof house-roof-left"></div>21         <div class="house-width house-roof house-roof-right"></div>22         <div class="house-width house-wall">23             24             <div class="house-wall-door">25                 26                 <div class="house-wall-door-handle"></div>27             </div>28         </div>29     </div>30 </body>31 </html>

 

css如下:

(原来的sun.css)

 1 .sun{ 2     position: relative; 3 } 4  5 .sun-body{     6     background-color: red; 7     border-radius: 50%; 8     height: 300px; 9     left: -100px;10     position: absolute;11     top: -100px;12     width: 300px;13     z-index: 9;14 }15 .sun-shine-light{16     background-color: yellow;17     height: 5px;18     left:250px;19     margin-top:30px;20     position: relative;21     width: 300px;22     z-index:10;23 }24 .sun-shine-light1{25     -webkit-transform: rotate(-3deg);26     -moz-webkit-transform: rotate(-3deg);27     -ms-webkit-transform: rotate(-3deg);28     -o-webkit-transform: rotate(-3deg);29 }30 .sun-shine-light2{31     top: 70px;32     left: 240px;33     -webkit-transform: rotate(10deg);34     -moz-webkit-transform: rotate(10deg);35     -ms-webkit-transform: rotate(10deg);36     -o-webkit-transform: rotate(10deg);37 }38 .sun-shine-light3{39     top: 160px;40     left: 195px;41     -webkit-transform: rotate(30deg);42     -ms-transform: rotate(30deg);43     -o-transform: rotate(30deg);44     transform: rotate(30deg);45 }46 .sun-shine-light4{47     top: 215px;48     left: 85px;    49     width: 260px;50     -webkit-transform: rotate(55deg);51     -ms-transform: rotate(55deg);52     -o-transform: rotate(55deg);53     transform: rotate(55deg);54 }55 .sun-shine-light5{56     top: 200px;57     left: -50px;58     width: 230px;59     -webkit-transform: rotate(85deg);60     -ms-transform: rotate(85deg);61     -o-transform: rotate(85deg);62     transform: rotate(85deg);63 }

(新增的house.css)

 1 .house-width { 2     width: 600px; 3 } 4  5 .house { 6     bottom: 20px; 7     height: 400px; 8     left: 600px; 9     position: absolute;10 }11 12 .house-roof {13     background: gold;14     border: 3px solid #000;15     left: -30px;16     height: 180px;17     position: relative;18 }19 20 .house-roof-left {21     border-left-width: 15px;22     float: left;23     -webkit-transform: matrix(0.25, 0, -0.4, 1, -298, 0);24 }25 26 .house-roof-right {27     -webkit-transform: matrix(1, 0, 0.3, 1, 0, 0);28 }29 30 .house-wall {31     border: 2px solid #000;32     height: 220px;33 }34 .house-wall::before{35     border: 2px solid #000;36     height: 220px;37     width:130px;38     content:'';39     left: -133px;40     top: 186px;41     position: absolute;42     display: block;43 }44 45 .house-wall-door {46     background: orange;47     bottom: 0px;48     height: 180px;49     left: 110px;50     position: absolute;51     width: 110px;52 }53 54 .house-wall-door-handle {55     background: brown;56     border: 1px solid #000;57     border-radius: 50%;58     height: 15px;59     position: absolute;60     right: 10px;61     top: 90px;62     width:15px;63 }

 

下面是code pen中的效果:  Sun and house

 

这里用到了以下几个陌生的css:

-webkit-transform: matrix(1, 0, 0.3, 1, 0, 0);  (由于任性的我只兼容chrome, 所以这里都带有-webkit前缀, 如果你要在FIREFOX下用,就改成-moz-前缀吧)

 

matrix, 我在画屋顶时用到它,matrix是用于画矩形的。

matrix的MDN文档在此:https://developer.mozilla.org/zh-CN/docs/Web/CSS/transform

另外,你可以在这里试验这个属性不同参数下的表现:http://www.css88.com/tool/css3Preview/Transform-Matrix.html

 

matrix接受6个参数, 这六个参数均接受正负小数:

1. 表示宽度的变性比例, 1表示100%,即不变, 0.25表示只有原本的25%

2. 表示以原点进行顺时针旋转的数值。 我没太理解,我的猜测是: 这个数值是旋转角度的正切函数的值,也就是当你输入1的时候,会顺时针旋转45度,因为tan45 = 1。或者叫做旋转的斜率。

3. 表示以原点为基准,原点之上向左倾斜变形、原点之下向右倾斜变形的数值, 这个数值我想应该和第二个参数一样是倾斜变形的斜率。 该数值越大,倾斜变形更严重。

4.表示高度的变性比例, 1表示100%,即不变, 0.25表示只有原本的25%

5.表示横向位移的像素值, 该参数只接受数字,不需要填写单位(px)。当你写100时,就向左平移了100px。 也可以输入负数

6.表示纵向位移的像素值, 其他同上

 

上面提到的“原点”, 可以通过transform-origin属性进行设置,若为设置,应该是对象的重心。

 

今天就到这,谢谢观看。

 

 

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!