From 9f8986a5cab97a55d085618d9daff7825c92fb83 Mon Sep 17 00:00:00 2001 From: MjSeven <33125422+MjSeven@users.noreply.github.com> Date: Thu, 29 Nov 2018 21:02:20 +0800 Subject: [PATCH] Create 20180131 For your first HTML code lets help Batman write a love letter.md --- ...de lets help Batman write a love letter.md | 905 ++++++++++++++++++ 1 file changed, 905 insertions(+) create mode 100644 translated/tech/20180131 For your first HTML code lets help Batman write a love letter.md diff --git a/translated/tech/20180131 For your first HTML code lets help Batman write a love letter.md b/translated/tech/20180131 For your first HTML code lets help Batman write a love letter.md new file mode 100644 index 0000000000..a35aa37ab6 --- /dev/null +++ b/translated/tech/20180131 For your first HTML code lets help Batman write a love letter.md @@ -0,0 +1,905 @@ +对于你的第一行 HTML 代码,让我们来帮助蝙蝠侠写一封情书 +====== + +![](https://cdn-images-1.medium.com/max/1000/1*kZxbQJTdb4jn_frfqpRg9g.jpeg) + +[Image Credit][1] + +在一个美好的夜晚,你的肚子拒绝消化你在晚餐吃的大块披萨,所以你不得不在睡梦中冲进洗手间。 + +在浴室里,当你在思考为什么会发生这种情况时,你听到一个来自通风口的低沉声音:“嘿,我是蝙蝠侠。” + +这时,你会怎么做呢? + +在你恐慌并处于关键节点之前,蝙蝠侠说:“我需要你的帮助。我是一个超级极客,但我不懂 HTML。我需要用 HTML 写一封情书,你愿意帮助我吗?” + +谁会拒绝蝙蝠侠的请求呢,对吧?所以让我们用 HTML 来写一封蝙蝠侠的情书。 + +### 你的第一个 HTML 文件 + +HTML 网页与你电脑上的其它文件一样。就同一个 .doc 文件以 MS Word 打开,.jpg 文件在图像查看器中打开一样,一个 .html 文件在浏览器中打开。 + +那么,让我们来创建一个 .html 文件。你可以在 Notepad 或其它任何编辑器中完成此任务,但我建议使用 VS Code。[在这里下载并安装 VS Code][2]。它是免费的,也是我唯一喜欢的微软产品。 + +在系统中创建一个目录,将其命名为 “HTML Practice”(不带引号)。在这个目录中,再创建一个名为 “Batman’s Love Letter”(不带引号)的目录,这将是我们的项目根目录。这意味着我们所有与这个项目相关的文件都会在这里。 + +打开 VS Code,按下 ctrl+n 创建一个新文件,按下 ctrl+s 保存文件。切换到 “Batman’s Love Letter” 文件夹并将其命名为 “loveletter.html”,然后单击保存。 + +现在,如果你在文件资源管理器中双击它,它将在你的默认浏览器中打开。我建议使用 Firefox 来进行 web 开发,但 Chrome 也可以。 + +让我们将这个过程与我们已经熟悉的东西联系起来。还记得你第一次拿到电脑吗?我做的第一件事是打开 MS Paint 并绘制一些东西。你在 Paint 中绘制一些东西并将其另存为图像,然后你可以在图像查看器中查看该图像。之后,如果要再次编辑该图像,你在 Paint 中重新打开它,编辑并保存它。 + +我们目前的流程非常相似。正如我们使用 Paint 创建和编辑图像一样,我们使用 VS Code 来创建和编辑 HTML 文件。就像我们使用图像查看器查看图像一样,我们使用浏览器来查看我们的 HTML 页面。 + +### HTML 中的段落 + +我们有一个空的 HTML 文件,以下是蝙蝠侠想在他的情书中写的第一段。 + +“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.” + +复制这些到 VS Code 中的 loveletter.html。单击 View -> Toggle Word Wrap (alt+z) 自动换行。 + +保存并在浏览器中打开它。如果它已经打开,单击浏览器中的刷新按钮。 + +瞧!那是你的第一个网页! + +我们的第一段已准备就绪,但这不是在 HTML 中编写段落的推荐方法。我们有一种特定的方法让浏览器知道一个文本是一个段落。 + +如果你用 `
` 和 `
` 来包裹文本,那么浏览器将识别 `` 和 `
` 中的文本是一个段落。我们这样做: + +``` +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. +
+``` + +保存并刷新浏览器。 + +![](https://cdn-images-1.medium.com/max/1000/1*M0Ae5ZpRTucNyucfaaz4uw.jpeg) + +哇!这里发生了什么,我们的列表在哪里? + +如果你仔细观察,你会发现没有显示换行符。在代码中我们在新的一行中编写列表项,但这些项在浏览器中显示在一行中。 + +如果你想在 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 标签: + + * \:用于段落
+
+ * \
:用于换行
+
+ * \