diff --git a/sources/tech/20180131 For your first HTML code lets help Batman write a love letter.md b/sources/tech/20180131 For your first HTML code lets help Batman write a love letter.md deleted file mode 100644 index 78cb024bb4..0000000000 --- a/sources/tech/20180131 For your first HTML code lets help Batman write a love letter.md +++ /dev/null @@ -1,559 +0,0 @@ -Translating by MjSeven - - -For your first HTML code, let’s help Batman write a love letter -============================================================ - - -[Image Credit][1] - -One fine night, your stomach refuses to digest the large Pizza you had at dinner, and you have to rush to the bathroom in the middle of your sleep. - -In the bathroom, while wondering why this is happening to you, you hear a heavy voice from the vent: “Hey, I am Batman.” - -What would you do? - -Before you panic and stand up in middle of the critical process, Batman says, “I need your help. I am a super geek, but I don’t know HTML. I need to write my love letter in HTML — would you do it for me?” - -Who could refuse a request from Batman, right? Let’s write Batman’s love letter in HTML. - -### Your first HTML file - -An HTML webpage is like other files on your computer. As a .doc file opens in MS Word, a .jpg file opens in Image Viewer, and a .html file opens in your Browser. - -So, let’s create a .html file. You can do this in Notepad, or any other basic editor, but I would recommend using VS Code instead. [Download and install VS Code here][2]. It’s free, and the only Microsoft Product I love. - -Create a directory in your system and name it “HTML Practice” (without quotes). Inside this directory, create one more directory called “Batman’s Love Letter” (without quotes). This will be our project root directory. That means that all our files related to this project will live here. - -Open VS Code and press ctrl+n to create a new file and ctrl+s to save the file. Navigate to the “Batman’s Love Letter” folder and name the file “loveletter.html” and click save. - -Now, if you open this file by double-clicking it from your file explorer, it will open in your default browser. I recommend using Firefox for web development, but Chrome is fine too. - -Let’s relate this process to something we are already familiar with. Remember the first time you got your hands on a computer? The first thing I did was open MS Paint and draw something. You draw something in Paint and save it as an image and then you can view that image in Image Viewer. Then if you want to edit that image again, you re-open it in Paint, edit it, and save it. - -Our current process is quite similar. As we use Paint to create and edit images, we use VS Code to create and edit our HTML files. And as we use Image Viewer to view the images, we use the Browser to view our HTML pages. - -### Your first Paragraph in HTML - -We have our blank HTML file, so here’s the first paragraph Batman wants to write in his love letter - -“After all the battles we fought together, after all the difficult times we saw together, and after all the good and bad moments we’ve been through, I think it’s time I let you know how I feel about you.” - -Copy the paragraph in your loveletter.html in VS Code. Enable word wrap by clicking View -> Toggle Word Wrap (alt+z). - -Save and open the file in your browser. If it’s already open, click refresh on your browser. - -Voila! That’s your first webpage! - -Our first paragraph is ready, but this is not the recommended way of writing a paragraph in HTML. We have a specific way to let the browser know that a text is a paragraph. - -If you wrap the text with `
` and `
`, then the browser will know that the text inside the `` and `
` is a paragraph. Let’s do this: - -``` -After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
-``` - -By writing the paragraph inside `` and `
` you created an HTML element. A web page is collection of HTML elements. - -Let’s get some of the terminologies out of the way first: `` is the opening tag, `
` is the closing tag, and “p” is the tag name. The text inside the opening and closing tag of an element is that element’s content. - -### The “style” attribute - -You will see that the text covers the entire width of the screen. - -We don’t want that. No one want’s to read such long lines. Let’s give a width of, say, 550px to our paragraph. - -We can do that by using the element’s “style” attribute. You can define an element’s style (for example, width in our case), inside its style attribute. The following line will create an empty style attribute on a “p” element: - -``` -...
-``` - -You see that empty `""`? That’s where we will define the looks of the element. Right now we want to set the width to 550px. Let’s do that: - -``` -- After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -We set the “width” property to 550px separated by a colon “:” and ended by a semicolon “;”. - -Also, notice how we put the `` and `
` in separate lines and the text content indented with one tab. Styling your code like this makes it more readable. - -### Lists in HTML - -Next, Batman wants to list some of the virtues of the person that he admires, like this: - -“ You complete my darkness with your light. I love: -- the way you see good in the worst things -- the way you handle emotionally difficult situations -- the way you look at Justice -I have learned a lot from you. You have occupied a special place in my heart over time.” - -This looks simple. - -Let’s go ahead and copy the required text below the `:` - -``` -- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-- You complete my darkness with your light. I love: - - the way you see good in the worse - - the way you handle emotionally difficult situations - - the way you look at Justice - I have learned a lot from you. You have occupied a special place in my heart over the time. -
-``` - -Save and refresh your browser. - - - - -Woah! What happened here, where is our list? - -If you look closely, you will observe that line breaks are not displayed. We wrote the list items in new lines in our code, but those are displayed in a single line in the browser. - -If you want to insert a line break in HTML (newline) you have to mention it using `- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-
- You complete my darkness with your light. I love:
- - the way you see good in the worse
- - the way you handle emotionally difficult situations
- - the way you look at Justice
- I have learned a lot from you. You have occupied a special place in my heart over the time.
-
- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -``` -- You complete my darkness with your light. I love: -
- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -``` -- You complete my darkness with your light. I love: -
-``` - -``` -- I have learned a lot from you. You have occupied a special place in my heart over the time. -
-``` - -Save and reload. - -Notice that this time we defined the width of the “ul” element also. That’s because we have now moved our “ul” element out of the “p” element. - -Defining the width of all the elements of our letter can become cumbersome. We have a specific element for this purpose: the “div” element. A “div” element is a generic container which is used to group content so it can be easily styled. - -Let’s wrap our entire letter with a div element and give width:550px to that div element: - -``` -- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-- You complete my darkness with your light. I love: -
-- I have learned a lot from you. You have occupied a special place in my heart over the time. -
-- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -``` -- You complete my darkness with your light. I love: -
-- I have learned a lot from you. You have occupied a special place in my heart over the time. -
-- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -``` -- You complete my darkness with your light. I love: -
-- I have learned a lot from you. You have occupied a special place in my heart over the time. -
-- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -``` -- You complete my darkness with your light. I love: -
-- I have learned a lot from you. You have occupied a special place in my heart over the time. -
-- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -``` -- You complete my darkness with your light. I love: -
-- I have learned a lot from you. You have occupied a special place in my heart over the time. -
-- It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. -
-- I don't show my emotions, but I think this man behind the mask is falling for you. -
-I love you Superman.
-
- Your not-so-secret-lover,
- Batman
-
- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -``` -- You complete my darkness with your light. I love: -
-- I have learned a lot from you. You have occupied a special place in my heart over the time. -
-- It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. -
-- I don't show my emotions, but I think this man behind the mask is falling for you. -
-I love you Superman.
-
- Your not-so-secret-lover,
- Batman
-
- After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. -
-``` - -``` -- You complete my darkness with your light. I love: -
-- I have learned a lot from you. You have occupied a special place in my heart over the time. -
-- It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. -
-- I don't show my emotions, but I think this man behind the mask is falling for you. -
-I love you Superman.
-
- Your not-so-secret-lover,
- Batman
-
` 和 `
` 来包裹文本,那么浏览器将识别 `` 和 `
` 中的文本是一个段落。我们这样做: + +``` +After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.
+``` + +通过在 `` 和 `
`中编写段落,你创建了一个 HTML 元素。一个网页就是 HTML 元素的集合。 + +让我们首先来认识一些术语:`` 是开始标签,`
` 是结束标签,“p” 是标签名称。元素开始和结束标签之间的文本是元素的内容。 + +### “style” 属性 + +在上面,你将看到文本覆盖屏幕的整个宽度。 + +我们不希望这样。没有人想要阅读这么长的行。让我们设定段落宽度为 550px。 + +我们可以通过使用元素的 “style” 属性来实现。你可以在其 style 属性中定义元素的样式(例如,在我们的示例中为宽度)。以下行将在 “p” 元素上创建一个空样式属性: + +``` +...
+``` + +你看到那个空的 `""` 了吗?这就是我们定义元素外观的地方。现在我们要将宽度设置为 550px。我们这样做: + +``` ++ After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +我们将 “width” 属性设置为 550px,用冒号 “:” 分隔,以分号 “;” 结束。 + +另外,注意我们如何将 `` 和 `
` 放在单独的行中,文本内容用一个 tab 缩进。像这样设置代码使其更具可读性。 + +### HTML 中的列表 + +接下来,蝙蝠侠希望列出他所钦佩的人的一些优点,例如: + +“ You complete my darkness with your light. I love: +- the way you see good in the worst things +- the way you handle emotionally difficult situations +- the way you look at Justice +I have learned a lot from you. You have occupied a special place in my heart over time.” + +这看起来很简单。 + +让我们继续,在 `:` 下面复制所需的文本: + +``` ++ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
++ You complete my darkness with your light. I love: + - the way you see good in the worse + - the way you handle emotionally difficult situations + - the way you look at Justice + I have learned a lot from you. You have occupied a special place in my heart over the time. +
+``` + +保存并刷新浏览器。 + + + +哇!这里发生了什么,我们的列表在哪里? + +如果你仔细观察,你会发现没有显示换行符。在代码中我们在新的一行中编写列表项,但这些项在浏览器中显示在一行中。 + +如果你想在 HTML(新行)中插入换行符,你必须使用 `+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+
+ You complete my darkness with your light. I love:
+ - the way you see good in the worse
+ - the way you handle emotionally difficult situations
+ - the way you look at Justice
+ I have learned a lot from you. You have occupied a special place in my heart over the time.
+
+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
+``` + +``` ++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
+``` + +保存并刷新。 + +注意,这次我们还定义了 “ul” 元素的宽度。那是因为我们现在已经将 “ul” 元素放在了 “p” 元素之外。 + +定义情书中所有元素的宽度会变得很麻烦。我们有一个特定的元素用于此目的:“div” 元素。一个 “div” 元素就是一个通用容器,用于对内容进行分组,以便轻松设置样式。 + +让我们用 div 元素包装整个情书,并为其赋予宽度:550px + +``` ++ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +
++ I don't show my emotions, but I think this man behind the mask is falling for you. +
+I love you Superman.
+
+ Your not-so-secret-lover,
+ Batman
+
+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +
++ I don't show my emotions, but I think this man behind the mask is falling for you. +
+I love you Superman.
+
+ Your not-so-secret-lover,
+ Batman
+
+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +
++ I don't show my emotions, but I think this man behind the mask is falling for you. +
+I love you Superman.
+
+ Your not-so-secret-lover,
+ Batman
+
+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
+``` + +``` ++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +
++ I don't show my emotions, but I think this man behind the mask is falling for you. +
+I love you Superman.
+
+ Your not-so-secret-lover,
+ Batman
+
+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +
++ I don't show my emotions, but I think this man behind the mask is falling for you. +
+I love you Superman.
+
+ Your not-so-secret-lover,
+ Batman
+
+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +
++ I don't show my emotions, but I think this man behind the mask is falling for you. +
+I love you Superman.
+
+ Your not-so-secret-lover,
+ Batman
+
+ After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you. +
++ You complete my darkness with your light. I love: +
++ I have learned a lot from you. You have occupied a special place in my heart over the time. +
++ It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart. +
++ I don't show my emotions, but I think this man behind the mask is falling for you. +
+I love you Superman.
+
+ Your not-so-secret-lover,
+ Batman
+
\
) + + * 如何使用 style 属性在元素内编写样式(这称为内联样式,尽可能避免这种情况) + + * 如何在 中编写元素的样式(这称为嵌入式样式) + + * 在 HTML 中如何使用 在单独的文件中编写样式并链接它(这称为链接样式表) + + * 什么是标签名称,属性,开始标签和结束标签 + + * 如何使用 id 属性为一个元素赋予 id + + * CSS 中的标签选择器和 id 选择器 + +我们学习了以下 HTML 标签: + + * \:用于段落
+
+ * \
:用于换行
+
+ * \