整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

在网页设计过程中正确理解css圆角边框及背景图

建企业网站时使用CSS边框圆角是很容易的事,但要设置边框圆角的渐变效果就需要费些功夫了,需要正确理解几个CSS属性的含义,background-origin,background-clip,background-size这几个是必须用到的,调整好性能的数值就可以灵活运用了。

想要实现CSS圆角渐变并匹配内容背景图可以参考以下代码:

<style>
div {
 width: 500px;
 height: 300px;
 margin: 10px;
 padding: 30px;
 border-radius: 50px; /*设置圆角*/
 border:50px solid transparent; /*设置边框颜色透明,确保背景渐变色显示*/
 background-origin:border-box; /*从边框开始背景图*/
 background-clip:padding-box,border-box; /*设置第一个背景和第二个背景的范围*/
 background-size:cover;
 /*由于背景图像不能设置纯色,所以可以使用下面的方式设置纯色*/
 background-image:linear-gradient(#fff, #fff),linear-gradient(#FC0, #F30); 
}
.a1{display:block;height:280px;background-image:url(/images/school.jpg);
background-repeat:no-repeat;background-size:contain;}
</style>

<div>
<span class="a1">边框渐变色从内边框到边框,背景图像单独设置不重复。</span>
</div>

background-origin表示的是背景起始位置,其三个值如下,依次是

border-box 从边框开始;
padding-box(默认) 从内边距开始;
content-box 从内容开始。

background-origin: border-box | padding-box(默认) | content-box

background-clip表示的是背景填充位置,其四个值如下,依次是

border-box(默认) 填充至边框;
padding-box 填充至内边距;
content-box 填充之内容;
text 作为字体前景色。

background-clip: border-box(默认) | padding-box | content-box | text

background-size表示的是背景尺寸,其五个值如下,依次是

contain 将图像扩大至适应最短的边,剩余部分默认重复图像
cover 将图像扩大至适应最长的边,图像可能显示不完整
length 两个值依次设置图像宽和高,未设置则为auto
percentage 两个百分比依次设置图像宽和高,未设置则为auto
auto 默认设置

载地址在github,文末有使用方法

github地址:https://github.com/crabbly/Print.js/

官网:https://printjs.crabbly.com/(可能被墙)

无法访问可以加企鹅群看离线版:1006429377

或者访问:https://www.yuque.com/caiyongjie/snknlo/ga5ef9

官网截图

简介

  • 原文:

Print.js was primarily written to help us print PDF files directly within our apps, without leaving the interface, and no use of embeds. For unique situations where there is no need for users to open or download the PDF files, and instead, they just need to print them.

One scenario where this is useful, for example, is when users request to print reports that are generated on the server side. These reports are sent back as PDF files. There is no need to open these files before printing them. Print.js offers a quick way to print these files within our apps.

  • 谷歌翻译:

Print.js主要是为了帮助我们直接在我们的应用程序中打印PDF文件,而无需离开界面,也不使用嵌入。 对于不需要用户打开或下载PDF文件的独特情况,相反,他们只需要打印它们。

例如,当用户请求打印在服务器端生成的报告时,这种情况很有用。 这些报告以PDF文件形式发回。 打印前无需打开这些文件。 Print.js提供了一种在我们的应用程序中打印这些文件的快捷方式。

  • 注意的地方:

PDF files must be served from the same domain as your app is hosted under. Print.js uses iframe to load files before printing them, therefore, it is limited by the Same Origin Policy. This helps preventing Cross-site scripting (XSS) attacks.

必须在托管应用程序的同一域中提供PDF文件。 Print.js在打印文件之前使用iframe加载文件,因此它受同源策略的限制。 这有助于防止跨站点脚本(XSS)攻击。

初体验

首先在页面上添加一个按钮

  • 打印PDF(注意:火狐不支持iframes,可以使用新标签页)
<button type="button" onclick="printJS('docs/printjs.pdf')">
 Print PDF
 </button>
  • 打印大文件(可以弹出提示消息)
<button type="button" onclick="printJS({printable:'docs/xx_large_printjs.pdf', type:'pdf', showModal:true})">
 Print PDF with Message
 </button>
  • html打印
 <form method="post" action="#" id="printJS-form">
 ...
 </form>
 <button type="button" onclick="printJS('printJS-form', 'html')">
 Print Form
 </button>
  • 打印带头部
 <button type="button" onclick="printJS({ printable: 'printJS-form', type: 'html', header: 'PrintJS - Form Element Selection' })">
 Print Form with Header
 </button>
  • 打印图片
<img src="images/print-01.jpg" />
 printJS('images/print-01-highres.jpg', 'image')
 printJS({printable: 'images/print-01-highres.jpg', type: 'image', header: 'My cool image header'})
  • 带头
 printJS({
 printable: ['images/print-01-highres.jpg', 'images/print-02-highres.jpg', 'images/print-03-highres.jpg'],
 type: 'image',
 header: 'Multiple Images',
 imageStyle: 'width:50%;margin-bottom:20px;'
 })
  • 从JSON数据
 someJSONdata = [
 {
 name: 'John Doe',
 email: 'john@doe.com',
 phone: '111-111-1111'
 },
 {
 name: 'Barry Allen',
 email: 'barry@flash.com',
 phone: '222-222-2222'
 },
 {
 name: 'Cool Dude',
 email: 'cool@dude.com',
 phone: '333-333-3333'
 }
 ]
 <button type="button" onclick="printJS({printable: someJSONdata, properties: ['name', 'email', 'phone'], type: 'json'})">
 Print JSON Data
 </button>
  • 自定义CSS
 <button type="button" onclick="printJS({
	 printable: someJSONdata,
	 properties: ['name', 'email', 'phone'],
	 type: 'json',
	 gridHeaderStyle: 'color: red; border: 2px solid #3971A5;',
	 gridStyle: 'border: 2px solid #3971A5;'
	})">
 Print JSON Data
 </button>
  • 自定义头
 <button type="button" onclick="printJS({
	 printable: someJSONdata,
	 properties: [
		{ field: 'name', displayName: 'Full Name'},
		{ field: 'email', displayName: 'E-mail'},
		{ field: 'phone', displayName: 'Phone'}
	 ],
	 type: 'json'
 })">
 Print with custom table header text
 </button>
<button type="button" onclick="printJS({
		printable: someJSONdata,
		type: 'json',
		properties: ['name', 'email', 'phone'],
		header: '<h3 class="custom-h3">My custom header</h3>',
		style: '.custom-h3 { color: red; }'
	 })">
	Print header raw html
</button>

安装使用

 npm install print-js --save
//或
 yarn add print-js


import print from 'print-js'


 //cdn,不知道能不能访问,我这可以访问
 https://printjs-4de6.kxcdn.com/print.min.js
 https://printjs-4de6.kxcdn.com/print.min.cssye
 <script src="print.js"></script>
  • 如果您将使用模态功能,还包括页面上的Print.css。
 <link rel="stylesheet" type="text/css" href="print.css">



详细配置:

兼容性

ostbirdAlertBox.js

下载地址:

https://github.com/postbird/PostbirdAlertBox.js

Alert

PostbirdAlertBox.alert({
    'title': '提示标题',
    'content': '提示内容主体',
    'okBtn': '好的',
    'contentColor': 'red',
    'onConfirm': function () {
    console.log("回调触发后隐藏提示框");
    alert("回调触发后隐藏提示框");
}

});

Confirm

PostbirdAlertBox.confirm({
    'title': '提示标题',
    'content': '离开本页面进行跳转',
    'okBtn': '好的',
    'contentColor': 'red',
    'onConfirm': function () {
    console.log("OK - 回调触发后隐藏提示框");
    alert("OK - 回调触发后隐藏提示框");
    },
    'onCancel': function () {
    console.log("Cancel-回调触发后隐藏提示框");
    alert("Cancel-回调触发后隐藏提示框");
    }
});

Prompt

PostbirdAlertBox.prompt({
'title': '请输入姓名',
'okBtn': '提交',
onConfirm: function (data) {
console.log("输入框内容是:" + data);
alert("输入框内容是:" + data);
},
onCancel: function (data) {
console.log("输入框内容是:" + data);
alert("输入框内容是:" + data);
},
});

使用说明

1. 引入js 和 css 文件

2. 通过全局对象 PostbirdAlertBox 调用相关方法,三个方法为: PostbirdAlertBox.alert({}); PostbirdAlertBox.confirm({}); PostbirdAlertBox.prompt({});

配置参数

参数属性 意义 适用方法 是否必须

title 弹框标题 alert、confirm(不适用于prompt) 否, 默认 : 提示信息

promptTitle prompt标题 prompt 否, 默认 :请输入内容

content 提示内容主体 alert、confirm(不适用于prompt) 否, 默认 : 提示内容

contentColor 提示内容颜色 alert、confirm 否,默认 : #000000

okBtn 确认按钮文字 alert、confirm(不适用于prompt) 否, 默认 : 好的

promptOkBtn prompt确认按钮文字 prompt 否, 默认 : 确认

okBtnColor 确认按钮颜色 alert、confirm、prompt 否, 默认 : #0e90d2

cancelBtn 取消按钮文字 alert、confirm、prompt 否, 默认 : 取消

onConfirm 确认按钮事件 alert、confirm、prompt(存在参数data) 否, 默认 : 不触发事件

onCancel 取消按钮事件 alert、confirm、prompt(存在参数data) 否, 默认 : 不触发事件

参数说明

1. title 和 promptTitle 分开主要是为了方便不传递title的情况,prompt和alert、confirm的显示文字不同

2. okBtn 和 promptOkBtn 分开同样是为了默认情况下,prompt和alert、confirm的显示文字不同

3. 正如前面的示例代码中,prompt的回调函数,会给予一个data参数,用来获取用户输入的内容