codepen

by Michael Henderson

通过迈克尔·亨德森

CodePen技巧和最佳实践 (CodePen Tips and Best Practice)

When working in FCC there are going to be times when you create your own projects with CodePen. Campers like to share these projects on the Free Code Camp Forum to receive feedback from other Campers.

在FCC中工作时,有时会使用CodePen创建自己的项目。 营员喜欢在“ 免费代码营”论坛上分享这些项目,以接收其他营员的反馈。

Today, I am going to show you how to get the most out of CodePen and how to maximize your feedback within the FCC Forum.

今天,我将向您展示如何充分利用CodePen,以及如何在FCC论坛中最大化您的反馈。

Get your sleeping bag and marshmallows. Oh, and don't forget to get your Yeti Cooler back from that bear who stole it while you were sleeping! We are going on a hike to learn a few things.

拿起你的睡袋和棉花糖。 哦,别忘了从睡觉时偷走它的那只熊取回雪人冷却器! 我们要去远足学习一些东西。

在CodePen中组织代码 (Organizing Your Code In CodePen)

When working with CodePen for the first time I remember having all of my code in the HTML section of my Pen. Just like the image below I had my HTML, CSS, and <head> content all in one spot.

第一次使用CodePen时,我记得我的笔HTML部分中包含了所有代码。 就像下面的图片一样,我HTML,CSS和<head>内容全部集中在一个位置。

There is absolutely nothing wrong with building your website like this. But, in CodePen there are ways to clean up your code to make it more organized and readable by others who are helping you or simply checking out your awesome project.

像这样构建您的网站绝对没有错。 但是,在CodePen中,有一些方法可以清理您的代码,以使其他人在帮助您或者只是检查您的出色项目时更加井井有条,可读性强。

You can open this pen in another tab by clicking here. This will allow you to play around with the code and follow along.

您可以通过单击此处在另一个标签中打开此笔。 这将使您可以试用代码并继续学习。

让我们删除一些东西 (Let's Remove Some Things)

<!-- Remove The Following Lines of Code From The Html Section -->
<!DOCTYPE html>
<html lang="en">
</html>

We do not need these pieces of code because CodePen automatically injects them into our project.

我们不需要这些代码,因为CodePen自动将它们注入到我们的项目中。

请按照以下步骤将您的头部内容正确放置在CodePen中。 (Follow these steps to properly place your head content where it needs to go in CodePen.)

Let’s move our meta content and google font links to the Stuff For <head> part of CodePen.

让我们将元内容和google字体链接移动到CodePen的Stuff For <head>部分。

Here is a snapshot of the code between the head tags. You should only move the code that I have in bold.

这是head标签之间代码的快照。 您应该只移动我用粗体显示的代码。

<head>  <! — Theme Made By www.w3schools.com — No Copyright --> <title>Bootstrap Theme Company Page</title> <meta charset=”utf-8"> <meta name=”viewport” content=”width=device-width, initial-scale=1"> <link rel=”stylesheet” href=”http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <link href=”http://fonts.googleapis.com/css?family=Montserrat" rel=”stylesheet” type=”text/css”> <link href=”http://fonts.googleapis.com/css?family=Lato" rel=”stylesheet” type=”text/css”> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script src=”http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <style> body { font: 400 15px Lato, sans-serif; line-height: 1.8; color: #818181; } h2 { font-size: 24px; text-transform: uppercase; color: #303030; font-weight: 600; margin-bottom: 30px; } h4 { font-size: 19px; line-height: 1.375em; color: #303030; font-weight: 400; margin-bottom: 30px; }  .jumbotron { background-color: #f4511e; color: #fff; padding: 100px 25px; font-family: Montserrat, sans-serif; } .container-fluid { padding: 60px 50px; } .bg-grey { background-color: #f6f6f6; } .logo-small { color: #f4511e; font-size: 50px; } .logo { color: #f4511e; font-size: 200px; } .thumbnail { padding: 0 0 15px 0; border: none; border-radius: 0; } .thumbnail img { width: 100%; height: 100%; margin-bottom: 10px; } .carousel-control.right, .carousel-control.left { background-image: none; color: #f4511e; } .carousel-indicators li { border-color: #f4511e; } .carousel-indicators li.active { background-color: #f4511e; } .item h4 { font-size: 19px; line-height: 1.375em; font-weight: 400; font-style: italic; margin: 70px 0; } .item span { font-style: normal; } .panel { border: 1px solid #f4511e;  border-radius:0 !important; transition: box-shadow 0.5s; } .panel:hover { box-shadow: 5px 0px 40px rgba(0,0,0, .2); } .panel-footer .btn:hover { border: 1px solid #f4511e; background-color: #fff !important; color: #f4511e; } .panel-heading { color: #fff !important; background-color: #f4511e !important; padding: 25px; border-bottom: 1px solid transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; } .panel-footer { background-color: white !important; } .panel-footer h3 { font-size: 32px; } .panel-footer h4 { color: #aaa; font-size: 14px; } .panel-footer .btn { margin: 15px 0; background-color: #f4511e; color: #fff; } .navbar { margin-bottom: 0; background-color: #f4511e; z-index: 9999; border: 0; font-size: 12px !important; line-height: 1.42857143 !important; letter-spacing: 4px; border-radius: 0; font-family: Montserrat, sans-serif; } .navbar li a, .navbar .navbar-brand { color: #fff !important; } .navbar-nav li a:hover, .navbar-nav li.active a { color: #f4511e !important; background-color: #fff !important; } .navbar-default .navbar-toggle { border-color: transparent; color: #fff !important; } footer .glyphicon { font-size: 20px; margin-bottom: 20px; color: #f4511e; } .slideanim {visibility:hidden;} .slide { animation-name: slide; -webkit-animation-name: slide; animation-duration: 1s; -webkit-animation-duration: 1s; visibility: visible; } @keyframes slide { 0% { opacity: 0; -webkit-transform: translateY(70%); }  100% { opacity: 1; -webkit-transform: translateY(0%); } } @-webkit-keyframes slide { 0% { opacity: 0; -webkit-transform: translateY(70%); }  100% { opacity: 1; -webkit-transform: translateY(0%); } } @media screen and (max-width: 768px) { .col-sm-4 { text-align: center; margin: 25px 0; } .btn-lg { width: 100%; margin-bottom: 35px; } } @media screen and (max-width: 480px) { .logo { font-size: 150px; } } </style></head>
  1. Click the settings button.点击设置按钮。

2. Click HTML.

2.单击HTML。

3. Paste the content into Stuff for <head>. Once you are done click Save & Close.

3.将内容粘贴到用于<he ad>的Stuff中 。 完成后,单击“保存并关闭”。

现在让我们将CSS移到应该去的地方 (Now let's move our CSS where it supposed to go)

  1. Copy everything between your opening and closing styles tag and paste it into the CSS section.复制打开和关闭样式标签之间的所有内容,并将其粘贴到CSS部分中。

Your HTML and CSS are now separated. This makes for an organized and efficient working environment. Please note: You do not have to put <styles> tags in your CSS section.

您HTML和CSS现在分开了。 这提供了一个有组织的有效工作环境。 请注意:您不必在CSS部分中放入<styles>标记。

将Bootstrap样式表添加到项目中 (Adding The Bootstrap Stylesheet To Your Project)

  1. Click Settings.单击设置。
  2. Click CSS.

    单击CSS。

3. Click the drop down arrow at the bottom where it says “Quick-add” and select bootstrap. It will add it to your external CSS links.

3.单击底部显示“快速添加”的下拉箭头,然后选择引导程序。 它将添加到您的外部CSS链接。

Quick Tip: You can also add Font Awesome as an external style sheet. Read the content under Add External CSS.

快速提示:您也可以将Font Awesome添加为外部样式表。 阅读添加外部CSS下的内容

添加JavaScript (Adding JavaScript)

  1. Still in settings, click JavaScript.

    仍在设置中,单击JavaScript。

2. Click the “Quick-add” drop down menu and add jQuery and Bootstrap.

2.单击“快速添加”下拉菜单,然后添加jQuery和Bootstrap。

3. Click Save & Close.

3.单击保存并关闭。

从HTML部分移走我们JavaScript (Moving Our JavaScript from the HTML section)

  1. Scroll to the bottom and copy the javascript code between your script tags.滚动到底部,然后在脚本标签之间复制javascript代码。
<script>$(document).ready(function(){ // Add smooth scrolling to all links in navbar + footer link $(“.navbar a, footer a[href=’#myPage’]”).on(‘click’, function(event) { // Make sure this.hash has a value before overriding default behavior if (this.hash !== “”) { // Prevent default anchor click behavior event.preventDefault();
// Store hash var hash = this.hash;
// Using jQuery’s animate() method to add smooth page scroll // The optional number (900) specifies the number of milliseconds it takes to scroll to the specified area $(‘html, body’).animate({ scrollTop: $(hash).offset().top }, 900, function(){  // Add hash (#) to URL when done scrolling (default click behavior) window.location.hash = hash; }); } // End if });  $(window).scroll(function() { $(“.slideanim”).each(function(){ var pos = $(this).offset().top;
var winTop = $(window).scrollTop(); if (pos < winTop + 600) { $(this).addClass(“slide”); } }); });})</script>

2. Paste it in the JavaScript section.

2.将其粘贴到JavaScript部分。

整理起来 (Finishing up)

Now that your HTML, CSS, and JavaScript are separated out, you have a more organized working environment within CodePen. This also makes it easier for others to help you in the Free Code Camp Forum, because they can locate your code and easily diagnose any errors. Play around in the CodePen settings and see what else you can do.

现在,您HTML,CSS和JavaScript已分离出来,您将在CodePen中拥有一个更有条理的工作环境。 这也使其他人可以更轻松地在Free Code Camp论坛中为您提供帮助,因为他们可以找到您的代码并轻松诊断任何错误。 在CodePen设置中玩转,看看还能做什么。

Next time you build a project in CodePen you will know how to add stylesheets, where to properly place <head> content, how to add a JavaScript library, and how to separate your HTML, CSS, and JavaScript. I hope this helps!

下次在CodePen中构建项目时,您将了解如何添加样式表,正确放置<head>内容的位置,如何添加JavaScript库以及如何分隔HTML,CSS和JavaScript。 我希望这有帮助!

I also have a video explaining how to do some of this too.

我也有一个视频解释如何也做一些。

Happy coding my friends!

祝我的朋友编码愉快!

If you liked this article, please let us know down in the comments.

如果您喜欢这篇文章,请在评论中告知我们。

Also, feel free to checkout my YouTube channel where I do cool stuff like review projects and share my life as a Software Engineer.

另外,请随时查看我的YouTube频道 ,我在那里做一些很棒的事情,例如审查项目,并分享我作为软件工程师的生活。

翻译自: https://www.freecodecamp.org/news/codepen-tips-and-best-practice-cf926ebd0b11/

codepen

codepen_CodePen技巧和最佳实践相关推荐

  1. idea资源包下创建资源包_资源包技巧和最佳实践

    idea资源包下创建资源包 今天是资源捆绑日. 通常,这是Java中最著名的国际化机制(i18n). 使用它应该很容易. 但是,弄污双手时会出现许多小问题. 如果您有相同的想法,则此文章适合您. 基本 ...

  2. 资源包技巧和最佳实践

    今天是资源捆绑日. 通常,这是Java中最著名的国际化机制(i18n). 使用它应该很容易. 但是,在弄脏手时会出现许多小问题. 如果您有相同的想法,则此文章适合您. 基本 java.util.Res ...

  3. 超实用的JavaScript技巧及最佳实践

    众所周知,JavaScript是一门非常流行的编程语言,开发者用它不仅可以开发出炫丽的Web程序,还可以用它来开发一些移动应用程序(如PhoneGap或Appcelerator),它还有一些服务端实现 ...

  4. java 8入门与实践_30个Java入门技巧和最佳实践

    java 8入门与实践 Java是最流行的编程语言之一-无论是Win应用程序,Web应用程序,移动,网络,消费电子产品,机顶盒设备,Java随处可见. 在Java上运行的设备超过30亿. 据Oracl ...

  5. 45个超实用的JavaScript技巧及最佳实践(一)

    2019独角兽企业重金招聘Python工程师标准>>> 21. 使用逻辑AND/OR来处理条件语句 var foo = 10; foo == 10 && doSome ...

  6. 周五14点直播丨数据库大咖讲坛(第6期):数据库性能优化技巧与最佳实践

    活动时间 8月27日  14:00-16:40 活动概述 DT(Data Technology)时代,云计算.大数据.数据库等技术迅猛发展,面对海量数据以及快速迭代的业务类型的需求,作为核心系统的数据 ...

  7. 网站图片优化技巧及最佳实践

  8. PHP入门指南:简单易学的语法和丰富的调试工具与安全性最佳实践

    PHP是一种非常流行的服务器端编程语言,它被广泛地应用于Web开发中.如果您想学习Web开发,那么PHP是一个非常好的选择.在本文中,我将介绍PHP的一些基础知识,包括语法.变量.函数.数组.数据库连 ...

  9. Dynatrace AppMon最佳实践(一)

    经常有客户问我,如何利用Dynatrace捕获必要的应用性能监控信息,从而快速诊断性能问题?所谓捕获必要的信息,即是在应用出现性能下降的时候,PurePath能够捕获导致事务响应缓慢的方法,或是导致事 ...

最新文章

  1. 机器学习Python实践》——数据导入(CSV)
  2. O365(世纪互联)SharePoint 之站点个性化
  3. Nginx的安装和多域名配置的实现方法
  4. 【Hibernate】hibernate主键生成策略与配置详解
  5. xubuntu沒有登錄輸入框,左上角出現白色方框,解決方案
  6. javascript date utc
  7. Atitit dsl实现(1)------异常的库模式实现  异常的ast结构
  8. android判断是华为手机,华为手机怎么辨别真假?华为手机真伪验证多种方法
  9. [Python]ImportError: This platform lacks a functioning sem_open implementation, therefore, the requi
  10. 爱分析·中国采购数字化行业趋势报告
  11. 【Flutter实战静态页面】--在线点餐app(7)——页面跳转
  12. 什么是固定资产管理系统?用固定资产管理系统管理固定资产的好处?
  13. 使用Photoshop辅助线制作ps切片教程
  14. 树梅派搭建MPI集群
  15. 系统架构设计基础(一)
  16. 电脑更换固态硬盘并安装系统
  17. 5大代码规则,守护程序猿世界的爱与和平!
  18. 事件冒泡详解及阻止事件冒泡
  19. 从K个数组中任取一个字符串进行按顺序拼接
  20. 【DDD设计】 Domain model VS DAL Entity VS Presentation DTO

热门文章

  1. 计算机无法识别华为m3,华为M3平板怎么开启学生模式过滤不良网站?
  2. Android开发者值得深入思考的几个问题,赶紧收藏备战金三银四!
  3. CentOS 7 Realtek 8192cu WIFI网卡驱动配置
  4. 高通电源管理qpnp-vm-bms驱动-电量计
  5. 通则ZLT X21 CPE使用指南
  6. redis编程(hredis)
  7. 2021年东北林业大学蓝桥杯选拔赛(软件类)(A B C D F G H)
  8. 免费Zblog采集工具插件-批量管理监控Zblog网站采集发布
  9. mac未能正确推出移动硬盘而读取不了
  10. 单工、半双工、全双工一点通