0

I have an HTML form that looks like this:

enter image description here

But I don't have a lot of room, so I'd like to have the m: and f: tags within the input boxes. And I want to indicate that they're not really part of the input, so I'd like to have them partially obscured by transucent triangles, which I want behind the dark bold text, so that if someone types more text the triangle will not be as relevant, sort of like this:

enter image description here

I've seen stuff like this recently on web checkout forms that ask for the person's name and CCN, and when I start typing in the field the legend text moves up and shrinks.

Is there a straightforward way to do this?

vy32
  • 28,461
  • 37
  • 122
  • 246
  • Have you tried anything? – Etheryte May 12 '19 at 03:01
  • I have no idea how to start on this. – vy32 May 12 '19 at 03:05
  • See [how to make CSS triangles](https://css-tricks.com/snippets/css/css-triangle/) and [any tutorial on CSS positioning](https://marksheet.io/css-position.html). You can also right click and choose _Inspect_ on the web pages you've already seen this on to see how they've solved the problem. – Etheryte May 12 '19 at 03:27

1 Answers1

0

Use a simple background on the input element:

label {
  position:absolute;
}
input {
  background:linear-gradient(to top left,transparent 49.5%,rgba(255,0,0,0.5) 50%) left/20px 100% no-repeat;
  padding-left:20px;
  border:1px solid;
}
<div class="box">
<label for="name">m:</label><input id="name" type="text">
</div>

Related: https://stackoverflow.com/a/49696143/8620333

Temani Afif
  • 245,468
  • 26
  • 309
  • 415