仅将 CSS 混合模式应用于边框
Apply CSS blend-mode to borders only
我一直在做一个小网站,只是为了练习整合。但是由于我对CSS没有深入的了解,不知道最后能不能实现:
我在网站上有一个表单,文本框被边框包围,我在其中应用了 Photoshop 中的混合模式。想知道它是否存在于 CSS 中,我很快尝试了一下,但在尝试仅在边框上应用 mix-blend-mode 时卡住了。
有没有办法做到这一点,或者有一个选择器可以让我只到达边界而没有其他地方?
感谢您的回答!
您可以使用 border-image
属性 但要谨慎使用现代浏览器支持,特别是 IE。
查看浏览器支持 here
这是一种看起来像漂亮的多色边框的方法
将表单标签包裹在一个容器中,让表单标签占据全部space。
在父容器中,应用背景颜色和一些周围填充。
下面的片段
div {
position: relative;
background: linear-gradient(to right, #bcbcbc 25%, #ffcd02 25%, #ffcd02 50%, #e84f47 50%, #e84f47 75%, #65c1ac 75%);
padding: 5px;
display: inline-block;
}
form {
width: 100%;
height: 100%;
display: inline-block;
background: white;
}
<div>
<form>
<input>
<input>
</form>
</div>
更改 .border-gradient
的 padding
将更改 "border" 宽度。
.border-gradient {
padding: 4px;
background: #1e5799;
background: -moz-linear-gradient(-45deg, #1e5799 0%, #7db9e8 100%);
background: -webkit-linear-gradient(-45deg, #1e5799 0%,#7db9e8 100%);
background: linear-gradient(135deg, #1e5799 0%,#7db9e8 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=1 );
}
.border-gradient > .margin-fix {
background-color: white;
padding: 1px;
margin: -1px;
}
p {
padding: 0 1rem;
}
<div class="border-gradient">
<div class="margin-fix">
<p>[32] But I must explain to you how all this mistaken idea of denouncing of a pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?
<p>[33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
</div>
</div>
请注意,创建跨浏览器背景渐变并非易事。我建议使用在线工具,例如 this one - 不认可或推荐,如果您不喜欢它,请寻找另一个 :).
这是 blend-mode
:
.blended {
padding: 20px;
background: red url('http://lorempixel.com/g/800/600/fashion') no-repeat 50% 50% /cover;
background-blend-mode: multiply;
}
.blended > .margin-fix {
background-color: white;
padding: 1px;
margin: -1px;
}
p {
padding: 0 1rem;
}
<div class="blended">
<div class="margin-fix">
<p>[32] But I must explain to you how all this mistaken idea of denouncing of a pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?
<p>[33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
</div>
</div>
我一直在做一个小网站,只是为了练习整合。但是由于我对CSS没有深入的了解,不知道最后能不能实现:
我在网站上有一个表单,文本框被边框包围,我在其中应用了 Photoshop 中的混合模式。想知道它是否存在于 CSS 中,我很快尝试了一下,但在尝试仅在边框上应用 mix-blend-mode 时卡住了。
有没有办法做到这一点,或者有一个选择器可以让我只到达边界而没有其他地方?
感谢您的回答!
您可以使用 border-image
属性 但要谨慎使用现代浏览器支持,特别是 IE。
查看浏览器支持 here
这是一种看起来像漂亮的多色边框的方法
下面的片段
div {
position: relative;
background: linear-gradient(to right, #bcbcbc 25%, #ffcd02 25%, #ffcd02 50%, #e84f47 50%, #e84f47 75%, #65c1ac 75%);
padding: 5px;
display: inline-block;
}
form {
width: 100%;
height: 100%;
display: inline-block;
background: white;
}
<div>
<form>
<input>
<input>
</form>
</div>
更改 .border-gradient
的 padding
将更改 "border" 宽度。
.border-gradient {
padding: 4px;
background: #1e5799;
background: -moz-linear-gradient(-45deg, #1e5799 0%, #7db9e8 100%);
background: -webkit-linear-gradient(-45deg, #1e5799 0%,#7db9e8 100%);
background: linear-gradient(135deg, #1e5799 0%,#7db9e8 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=1 );
}
.border-gradient > .margin-fix {
background-color: white;
padding: 1px;
margin: -1px;
}
p {
padding: 0 1rem;
}
<div class="border-gradient">
<div class="margin-fix">
<p>[32] But I must explain to you how all this mistaken idea of denouncing of a pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?
<p>[33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
</div>
</div>
请注意,创建跨浏览器背景渐变并非易事。我建议使用在线工具,例如 this one - 不认可或推荐,如果您不喜欢它,请寻找另一个 :).
这是 blend-mode
:
.blended {
padding: 20px;
background: red url('http://lorempixel.com/g/800/600/fashion') no-repeat 50% 50% /cover;
background-blend-mode: multiply;
}
.blended > .margin-fix {
background-color: white;
padding: 1px;
margin: -1px;
}
p {
padding: 0 1rem;
}
<div class="blended">
<div class="margin-fix">
<p>[32] But I must explain to you how all this mistaken idea of denouncing of a pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?
<p>[33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
</div>
</div>