❶ 如何用CSS控制div畫三角形,聖誕樹
新建文本文檔】
在桌面新建一個文本文檔,並命名為「三角形」,打開新建的文本文檔,把html里的doctype、head、body等框架搭好。
【注意】可以在寫完之後再重新重命名為.html文件。
2
【創建div並用border屬性控制】
布局div,並命名id="tri",用CSS來控制div,在style裡面,使用border屬性對div進行控制,
#tri{
width: 0px;
height: 0px;
border-top: 400px solid red;
border-right: 400px solid blue;
border-bottom: 400px solid green;
border-left: 400px solid yellow;
}
【注意】div的長寬設為0,border為邊框,會看到如下四個三角狀的圖形。
3
【修改並選擇自己想要的三角形】
上述代碼畫的還不是三角形,但是是四個三角,只要將border周邊的顏色變成白色就可以了,例如除了border-bottom: 100px solid green;其餘全變為white,就會看到如下效果,當然你也可以根據自己需要來調整。
此外可以將border-top的像素設為0;其餘兩邊也調小一點並且顏色設為白色,就會只看到底下的一個三角形了。
【注意】根據自己實際來挑選自己想要達到的效果。圖一圖二效果不同,就是border設定不同的原因。
4
代碼如下僅做參考:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>三角練習</title>
<style>
#tri{
width: 0px;
height: 0px;
border-top: 0px solid white;
border-right: 100px solid white;
border-bottom: 400px solid green;
border-left: 100px solid white;
}
</style>
</head>
<body>
<div id="tri"></div>
</body>
</html>
END
畫聖誕樹
【畫兩個三角】
用上面三角形的基礎,先畫出兩個大小不同三角形。
#tri1{
width: 0px;
height: 0px;
border-top: 100px solid white;
border-right: 100px solid white;
border-bottom: 100px solid green;
border-left: 100px solid white;
}
#tri2{
width: 0px;
height: 0px;
border-top: 200px solid white;
border-right: 200px solid white;
border-bottom: 200px solid green;
border-left: 200px solid white;
}
【利用浮動以及margin調到合適位置】
將第一個小三角形浮動起來,這樣就覆蓋到第2個上面,然後利用margin值調動位置,最終顯示出聖誕樹的上面內容,代碼如下,圖如下。
#tri1{
width: 0px;
height: 0px;
border-top: 100px solid white;
border-right: 100px solid white;
border-bottom: 100px solid green;
border-left: 100px solid white;
float: left;
margin-left: 100px;
}
#tri2{
width: 0px;
height: 0px;
border-top: 200px solid white;
border-right: 200px solid white;
border-bottom: 200px solid green;
border-left: 200px solid white;
}
【畫樹干】
再加入一個div名字為footer,控制其大小形狀與顏色,並用margin調整期位置。
#footer{
width: 100px;
height: 200px;
background: gray;
margin-left: 150px;
}
最終,經過調整得到一課聖誕樹。如下圖所示
完整代碼如下,僅做參考
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>聖誕樹練習</title>
<style>
#header{
width: 0px;
height: 0px;
border-top: 100px solid white;
border-right: 100px solid white;
border-bottom: 100px solid green;
border-left: 100px solid white;
float: left;
margin-left: 100px;
}
#main{
width: 0px;
height: 0px;
border-top: 200px solid white;
border-right: 200px solid white;
border-bottom: 200px solid green;
border-left: 200px solid white;
}
#footer{
width: 100px;
height: 200px;
background: gray;
margin-left: 150px;
}
</style>
</head>
<body>
<div id="header"></div>
<div id="main"></div>
<div id="footer"></div>
</body>
</html>
❷ 如何用c語言編一個聖誕樹,謝謝
列印兩個等邊三角形,再打一個矩形就可以實現聖誕樹雛形;
參考代碼如下:
❸ 怎麼用java編寫一個聖誕樹,我有圖,幫我改下就行
您好!我沒有懂您為什麼這么寫,我寫了一個簡單易懂的,代碼如下:
System.out.println("*");
System.out.println("* *");
System.out.println("**");
System.out.println("**");
System.out.println("*********");
System.out.println("**");
System.out.println("**");
System.out.println("**");
System.out.println("**");
格式有問題。。。,您看圖吧:
❹ c語言,怎麼做出這個聖誕樹求寫代碼拍下來,必採納
printf("%5s ",str); 表示右對齊,佔5位輸出字元串 str, 代表換行。代碼:
#include<stdio.h>
intmain()
{
printf("%5s ","O");
printf("%6s ","OOO");
printf("%7s ","OOOOO");
printf("%6s ","OOO");
printf("%8s ","OOOOOOO");
printf("%9s ","OOOOOOOOO");
printf("%5s ","O");
printf("%5s ","O");
printf("%5s ","O");
printf("%5s ","O");
return0;
}
編譯運行:
❺ 如何用C語言畫一個「聖誕樹」
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
int j,s;
int k,x;
int y;
int n = argc > 1 ? atoi(argv[1]) : 4;
for ( j = 1; j <= n; j++) {
s = 1 << j, k = (1 << n) - s, x;
for ( y = s - j; y >= 0; y--, putchar(' ')) {
for (x = 0; x < y + k; x++) printf(" ");
for (x = 0; x + y < s; x++) printf("%c ", '!' ^ y & x);
for (x = 1; x + y < s; x++) printf("%c ", '!' ^ y & (s - y - x - 1));
}
}
}
❻ 電腦的C語言怎樣編寫出聖誕樹
列印兩個等邊三角形,再打一個矩形就可以實現聖誕樹雛形;
參考代碼如下:
#include<stdio.h>
voidmain()
{
inti,j;
printf("* ");
for(i=2;i<4;i++)
{
printf("");
for(j=1;j<2*i;j++)
printf("*");
printf(" ");
}
for(i=1;i<5;i++)
{
printf("");
for(j=1;j<2*i;j++)
printf("*");
printf(" ");
}
for(i=1;i<4;i++)
{
printf("");
printf("*** ");
}
}
❼ 如何用 C 語言畫一個「聖誕樹」
畫聖誕樹
1,用 C 語言畫的「聖誕樹」,對於我一個美術生來說,畫畫是自己的興趣,我也很喜歡畫畫,從小對畫畫還有創意性的,我大學是學藝術設計的,用電腦操作繪畫是我的專業,我嘗試用最少代碼來畫一個抽象一點的聖誕樹,可惜沒有畫樹干。然後,我嘗試用更真實一點的風格。因為樹是一個比較自相似的形狀,這次使用遞歸方式描述樹乾和分支。就是畫一主樹干,樹干越高看著就越幼。
所以考慮到太小的葉片是很難采樣得到好看的結果,我嘗試以一個較大的球體去表現葉片,就如素描時考慮更整體的光暗,而不是每片葉片的光暗,這樣畫出來的效果非常的漂亮,我覺得結果已有進步。
❽ java編打出5行聖誕樹,求教每一步詳細思想。下面是代碼
按照你的要求加詳細注釋的聖誕樹Java程序如下:(編程思想在注釋中說明)
publicclassShengDanShu2{
//這個程序的編程思想是利用對for循環變數i的控制達到一層循環代替雙層循環的目的
publicstaticvoidmain(String[]args){
intn=5;//初始化列印聖誕樹層數變數n
inta=0;//初始化列印前置空格數變數a
intb=0;//初始化列印星號數變數b
for(inti=1;i<=n;i++){//列印n層聖誕樹
if(a!=(n-i)){//如果前置空格數不等於n-i
System.out.print("");//列印一個空格
a++;//前置空格數加一
i=i-1;//i變數減一目的是固定住i變數不變直到a==n-i
}elseif(b!=(2*i-1)){//如果星號數不等於2*i-1
System.out.print("*");//列印一個星號
b++;//星號數加一
i=i-1;//i變數減一目的是固定住i變數不變直到b==2*i-1
}elseif(a==(n-i)&&b==(2*i-1)){//當以上兩個條件都滿足時,換行初始化a和b為0
System.out.println();//列印換行
a=0;//對新的一行重新初始化前置空格數變數a
b=0;//對新的一行重新初始化列印星號數變數b
//這里沒有控制for循環的i變數減一,因為這時i變數加一,開始新一行。
}
}
}
}
運行結果:
*
***
*****
*******
*********
❾ 用c++設計一個聖誕樹程序
#include <iostream>
using namespace std;
int main()
{cout<<'*'<<endl;
cout<<"*1*"<<endl;
cout<<"*2 3*"<<endl;
cout<<"*4 5 6* "<<endl;
cout<<"*7 8 9 10* "<<endl;
cout<<"**"<<endl;
cout<<"**"<<endl;
cout<<"**"<<endl;
}
簡單的問題用for反而麻煩了,我這個雖然是笨辦法,但還算清楚易懂吧
❿ 這是用css寫的聖誕樹的代碼,看不懂啊,能不能逐條翻譯一下,為什麼這么寫
<類型>
* {填充:0;保證金:0;}
位置:相對。樹{;}
樹的div。{ position:絕對;寬度:0;高度:0;}
樹。木材{寬度:20px;高度:50px;背景顏色:灰色;左:50%;margin-left: - 10px;頂:170px;}
。A1 {邊境:40px固綠;邊境上:40px固體# FFF;左:50%;margin-left: - 40px;高層:0;}
A2。{左邊界:40px固綠;邊境上:40px固體# FFF;左:50%;高層:0;}
B1。{邊界:70px固體綠;邊境上:固體# FFF 70px;左:50%;margin-left: - 70px;頂:20px;}
。B2 {左邊界:70px固體綠;邊境上:固體# FFF 70px;左:50%;頂部20px;}
。C1 {邊界:100px固綠;邊境上:100px固體# FFF;左:50%;margin-left: - 100px;頂:70px;}
C2。{左邊界:100px固綠;邊境上:100px固體# FFF;左:50%;頂:70px;}
< /樣式>
<div class=「樹」>
<div class=「木」> <數據>
<div></div = C1類><div></div = C2類>
<div></div = B1類><div></div = b2類>
<div class=「A1」></div><div class=「A2」> <數據>
<數據>