自己写富文本编辑器jss

JSS is a JavaScript library that allows you to create objects that follow a CSS-like syntax for styling components. More technically, from the JSS docs, JSS lets you “use JavaScript to describe styles in a declarative, conflict-free and reusable way”.

JSS是一个JavaScript库,允许您创建对象,这些对象遵循类似于CSS的语法来设计组件样式。 从技术上讲,从JSS文档开始 ,JSS允许您“使用JavaScript以声明性,无冲突且可重用的方式描述样式”。

Many JavaScript libraries make use of JSS (also known as CSS-In-JS). As a React developer, I use it daily in place of regular CSS. Attempting to properly style and customize Material-UI components has also encouraged my use of JSS.

许多JavaScript库都使用JSS(也称为CSS-In-JS)。 作为一个React开发人员,我每天都用它代替常规CSS。 尝试正确设置样式和自定义Material-UI组件也鼓励了我使用JSS。

In fact, bumping into disabled, hovered, or otherwise special-state Material-UI components is what pushed me to write this article: even armed with knowledge of CSS syntax, it can be hard to get the selectors correct with JSS.

实际上,碰到禁用,悬停或其他特殊状态的Material-UI组件是促使我写这篇文章的原因:即使拥有CSS语法知识,也很难通过JSS来使选择器正确。

In this article, I will give a few examples of selecting pseudo-classes and child elements with JSS. If you want an example using Material-UI, see this article. Here is the CodeSandbox for the below examples.

在本文中,我将提供一些使用JSS选择伪类和子元素的示例。 如果要使用Material-UI的示例, 请参阅本文 。 这是下面示例的CodeSandbox 。

JSS一般规则和语法 (JSS General Rules and Syntax)

·JSS uses camel-case instead of dashes (i.e. fontWeight instead of font-weight)

·JSS使用驼峰大小写而不是破折号(即,用fontWeight代替font-weight)

·There is no ‘.’ in front of class names (i.e. buyButton instead of .buyButton)

·没有“。” 在类名的前面(即buyButton而不是.buyButton)

·Imports and other variables are fine. Remember, this is JavaScript

·导入和其他变量都可以。 记住,这是JavaScript

·Other JavaScript syntax is fine (i.e. object destructuring)

·其他JavaScript语法也可以(例如,对象分解)

Remember that when writing JSS, you are creating a JavaScript object. Therefore, all normal JavaScript Syntax applies.

请记住,在编写JSS时,您正在创建一个JavaScript对象。 因此,所有普通JavaScript语法都适用。

示例1 —:hover伪类的JSS选择器 (Example 1 — JSS selector for :hover pseudo-class)

Let’s add a :hover selector to a button. The elements are below (using JSX).

让我们在按钮上添加一个:hover选择器。 元素如下(使用JSX)。

<form>  <button className={classes.buyButton}>    Click Me!  </button></form>

And here is the JSS:

这是JSS:

buyButton: {  backgroundColor: 'blue',  width: 200,  height: 80,  borderRadius: 4,  fontSize: 24,  '&:hover': {    border: '4px solid red',    cursor: 'pointer'  }}

Notice the & has no space after it. This makes sense because we are not selecting a hovered child of buyButton.

注意&后面没有空格。 这是有道理的,因为我们没有选择buyButton的悬浮子项。

示例2 —适用于一个元素的两个伪类的JSS选择器 (Example 2 — JSS selector for two pseudo-classes applied to one element)

This time let’s resize a checked and disabled checkbox. The JSX:

这次让我们重新调整选中和禁用复选框的大小。 JSX:

<div>  <input    className={classes.personChecker}    type='checkbox'    id='person1'    name='person1'    value='Person'    checked={true}    disabled={true}  />  <label for='person1'> I am a person</label></div>

And the JSS:

和JSS:

personChecker: {  '&:checked:disabled': {    width: 20,    height: 20  }}

Notice once again that there are no spaces. There is also only one ‘&’.

再次注意,没有空格。 也只有一个“&”。

示例3 —嵌套伪类 (Example 3 — Nested pseudo-classes)

Here is an example of what the code would look like for a nested pseudo-class selector. This one is not in the CodeSandbox.

这是一个嵌套伪类选择器的代码示例。 此代码不在CodeSandbox中。

buyButton: {  '&:hover': {    backgroundColor: 'blue',    '&:before: {      textDecoration: 'bold',    }  }}

This nested pseudo-selector allows some styles to be applied on hover (backgroundColor in this case) with separate styling applied on both :hover and :before.

此嵌套的伪选择器允许将某些样式应用于悬停(在本例中为backgroundColor),同时将单独的样式应用于:hover :before。

示例4 —子选择器 (Example 4 — Child selector)

Let’s select all spans in the form. JSX:

让我们选择表单中的所有跨度。 JSX:

<form className={classes.form}>  <span>Child span</span>  <span>Another child span</span></form>

JSS:

JSS:

form: {  "& span": {     backgroundColor: "red",    margin: 4  }}

Notice how I had to use form as a class.

请注意,我必须如何将表单用作类。

React Material-UI (React Material-UI)

If you are a React developer and looking for a good component library, I recommend using Material-UI. Material-UI uses the JSS syntax above for styling components. If you want to gain an in-depth understanding of Material-UI syntax and APIs for styling components, I recommend you read my book, Styling Material-UI Components (affiliate link). I cover the class object API, Styled Components, and overriding components using the theme. Furthermore, there are many examples of custom component styling.

如果您是React开发人员,并且正在寻找一个好的组件库,我建议您使用Material-UI。 Material-UI使用上面的JSS语法对组件进行样式设置。 如果您想深入了解Material-UI语法和用于样式化组件的API,建议您阅读我的书, 样式化Material-UI组件 (关联链接)。 我将介绍使用主题的类对象API,样式化组件和重写组件。 此外,还有许多自定义组件样式的示例。

Read it for FREE with a free Kindle Unlimited trial membership (affiliate link).

用读它免费 免费的Kindle无限试用会员 (会员链接)。

Are you a developer looking to start your first side hustle? Learn how here.

您是否正在寻找开始第一手的开发人员? 在这里了解如何 。

翻译自: https://medium.com/the-clever-dev/jss-selectors-and-syntax-rules-e4008e07966b

自己写富文本编辑器jss


http://www.taodudu.cc/news/show-6622489.html

相关文章:

  • 简洁的文本处理代码
  • XSLT实现XML文档转换成HTML文档
  • 简单的文本编辑器 - wxWindows编程事例
  • 如何翻译图片?这三个软件能翻译图片
  • Unity学习之工厂模式
  • 趣谈java工厂模式
  • Java设计模式——工厂模式讲解以及在JDK中源码分析
  • 百度试题:度度熊
  • RT-ThreadBearPi 开发笔记 -- 为小熊派开发板制作 RT-Thread BSP 包
  • 5步教你完成小熊派开发板贴片
  • 熊厂实习生招聘面试经验
  • 加入熊厂,越努力,越迷茫
  • Java判断字符串是否为非负整数 / 数字
  • 求一个整数的位数(包含0,正数和负数)
  • 如何判断是否是整数
  • 利用位运算判断整数的正负
  • 判断是否是整数,小数或实数
  • 大整数1000位包括正负数的加减运算
  • c++中的负数取整问题
  • 怎么判断一个数是否为整数
  • Windows关闭某个端口的服务
  • 如何关闭80端口,如何查找哪些端口在使用中
  • 关闭常见的端口
  • 端口详解及如何开起端口关闭端口
  • 关闭端口的三种方法
  • 端口大全及端口关闭/打开方法(下)
  • 如何关闭一些不必要的服务和端口?
  • 端口大全及端口关闭方法
  • 端口详解 | 开启端口 | 关闭端口
  • 常用端口及端口关闭方法

自己写富文本编辑器jss_JSS选择器和语法规则相关推荐

  1. 原生手写富文本编辑器组件

    H5富文本编辑器原理解析: 核心属性: 1.contentEditable="true"; //属性规定是否可编辑元素的内容 2.window.document.designMod ...

  2. kind富文本编辑器_在项目中集成富文本编辑器

    前   言 现在学程序的都离不开 Markdown 语法了吧,Markdown 已经成为典型的转换为HTML的非正式规范和参考实现,现在市场上也出现了许多Markdown实现,在基本语法之上额外增加了 ...

  3. 富文本编辑器tinymce 自定义中文字号(四号,小四,五号,小五等)

    富文本编辑器tinymce 自定义中文字号(四号,小四,五号,小五等) 前因 探索 最终解决 最终效果 关键代码 前因 在写富文本编辑器转换word的过程中,因为所使用的富文本编辑器tinymce中的 ...

  4. 【wangEditor富文本编辑器】富文本三种使用方法,html使用富文本,html套vue脚手架使用富文本,vue使用富文本【简单易用,复制即用】

    前言 富文本编辑器功能是很多人都要使用的 市面上有很多的编辑器可以供选择,但是很多编辑器会有点复杂,或者文档看起来难受. 我最近做了一个需求,是需要在html文件上写富文本编辑器. 但是我看了以前用的 ...

  5. 富文本编辑器、日期选择器、软件天堂、防止XSS攻击、字体icon、转pdf

    [超好用的日期选择器] Layui:http://www.layui.com/laydate/ 备注:日期选择器,用过很多很多,自己也写过一些:相信这个简单而又不简单的选择器,能够给你多些美好的时光 ...

  6. 博客系统-写文章之富文本编辑器editor

    editor 直接再官网下载下来 之后从下载下来的文件选取有用的文件放到项目专门包下,注意下图 可以选择下载好的文件中的上图部分,放入新建md中 然后就是写文章页面 <!DOCTYPE html ...

  7. 如何写一个简便的富文本编辑器

    如何写一个简便的富文本编辑器 目的 使用div创建编辑器的输入框 使用到的DOM API 目的 仅是学习过程中的记录,发着玩的.如果是使用富文本编辑器投入使用,现成有很多富文本编辑器可供选择. 使用d ...

  8. themyleaf 图片上传_springboot thymeleaf 整合 百度富文本编辑器UEditor进行图片上传

    项目中需要使用到富文本编辑器,找来找去发现百度UEditor富文本编辑器在国内最为常用因此就尝试引入.编辑器官网是:http://ueditor.baidu.com/website/index.htm ...

  9. JavaWeb 富文本编辑器(Ckeditor)文件上传

    目录 一.什么是富文本编辑器? 二.CKEditor介绍 三.CKEditor下载 四.使用富文本编辑器 五.文件上传 一.什么是富文本编辑器? 富文本编辑器是一种可内嵌于浏览器,所见即所得的文本编辑 ...

最新文章

  1. c/c++ typedef定义函数指针(Hook前奏2)
  2. Mybatis——返回类型为 集合嵌套集合 应该如何处理
  3. java从入门到精通第11章_《Java从入门到精通》第十章学习笔记
  4. oracle 10g oci.dll 下载,Oracle 11g oci.dll下载
  5. TCP、UDP、Socket、HTTP网络编程面试题(总结最全面的面试题)
  6. win8计算机无法安装打印机驱动程序,win8系统安装打印机驱动失败怎么办|win8系统安装打印机驱动失败的解决方法...
  7. 克里金方法内插生成高程曲面
  8. MYSQL 数据库给表加约束条件 (史上最详细教程!)!!
  9. linux考试中的7654_7654支持的未启用卡指的是()
  10. 企业微信防撤回插件 WeChatICU v1.0.1中文版
  11. 用计算机数字表白,数字表白公式 表白套路情话
  12. 2017年你不应该错过的编程语言、框架和工具
  13. word设置章标题与节标题
  14. 对创业团队的一点想法
  15. ROSCon会议详细资料
  16. HTML基础之label标签
  17. 政府采购:国产软件发展的第一推动力
  18. 安卓Service组件使用系列2:使用Service下载网络图片并存储于sdCard卡上
  19. 莫烦python pytorch_[莫烦 PyTorch 系列教程] 1.2 – 安装 PyTorch
  20. STM32移植lvgl遇到的bug(坑)

热门文章

  1. php中英尺厘米换算,php 英尺、英里、英寸转换的实现方法
  2. 电阻的作用有哪些?(超全)
  3. emd_visu函数_visu
  4. 纯前端表格控件SpreadJS以专注业务、提升效率赢得用户与市场
  5. ansible角色部署mysql主从复制
  6. 原码补码相互转换,简单方法
  7. 不安装标准件如何直接导出含有标准件的BOM
  8. 计算机桌面图标点不动,电脑桌面假死,所有图标都点不动怎么回事?如何解决?...
  9. POI的不同版本的兼容问题
  10. 支持javascript的ppt软件_用 reveal.js 随心所欲地制作 PPT