2

I've been working on a small website, just as an exercise for integration. But as I don't have an extended knowledge of CSS, I do not know if it is possible in the end :

I have in the website a form, with text boxes surrounded by a border, on which I applied a blend mode in Photoshop. Curious to know if it existed in CSS, I quickly tried it out, but got stuck trying to apply mix-blend-mode only on the border.

Is there anyway to do it, or a selector which would allow me to reach only the border and nothing else ?

Thanks for your answers !

Solomai
  • 33
  • 1
  • 6

2 Answers2

1

Changing the padding of .border-gradient will change the "border" width.

.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>

Please note that creating cross-browser background gradients is not yet trivial. I recommend using an online tool, such as this one - not endorsed or recommended, find another if you don't like it :).

Here it is with 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>
tao
  • 82,996
  • 16
  • 114
  • 150
  • 1
    Hm, tell me if I am wrong, but this is for a gradient only, isn't it ? I don't see any way to adapt a blend mode to this code. – Solomai Apr 08 '17 at 17:43
  • What exactly do you mean by *"blend mode"*? – tao Apr 08 '17 at 17:44
  • I guess [this](https://css-tricks.com/basics-css-blend-modes/) would explain better. I have a background image and would like my border (and only the border) to blend with it. I know it's a lot of hassle and I could just run opacity, I just wanted to know the limits of this property. – Solomai Apr 08 '17 at 17:52
  • And what's stopping you from applying that effect to the `.border-gradient` wrapper? That's just a wrapper that enables you to transfer any `background` effect to make it seem a border, because `border` doesn't allow the same freedom as `background` does. I really don't understand what your difficulty is. Updated answer with an example. – tao Apr 08 '17 at 17:55
  • I'm a beginner, so I don't fully understand what goes where, and the effects of some properties. I guess that's my main difficulty here :D – Solomai Apr 08 '17 at 18:00
  • I've updated my answer with another example. The outer div is a placeholder that acts like a border, but, in fact, we use it's background properties. Should point you in the right direction. We're all beginners, you're just a few documentation reads behind. Don't worry. – tao Apr 08 '17 at 18:05
  • I understand what your code leads to, took me a while ! Thanks for your time and explanations. But the problem in my case is that the background is already set [as in this example](http://imgur.com/a/Qlxjm), so I can't really do it this way, as I can't insert a new image to create a new background. – Solomai Apr 08 '17 at 18:20
  • It's possible. Use equal negative margins and padding on the inner container and `background-crop: padding-box`. – tao Apr 08 '17 at 18:30
0

You can use border-image property but be prudent with modern browser support, speicifically IE.

See browser support here

Here is an approach that looks like nice multicolor border

  • wrap the form tag in a container, make the form tag occupy all space.
  • In the parent container, apply a background color and some surrounding padding.

    Snippet below

    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>
  • repzero
    • 8,254
    • 2
    • 18
    • 40