Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add static text inside an input form

How can I put this static text in an input form?

It's there all the time.

Enter image description here

This is my code:

<label for="subdomain">Subdomain:</label>
<input type="text" placeholder="ExampleDomain" id="subdomain"/>
like image 232
Davor Budimir Avatar asked Jun 23 '14 15:06

Davor Budimir


1 Answers

You can achieve this with the following approach:

  • place the <input> in a <label> with position:relative
  • give the <label> an ::after pseudo-element with position:absolute
  • set box-sizing of the <input> to border-box
  • give the <input> a padding-right equal to the width of the ::after pseudo-element

Working Example:

label, input {
    position: relative;
    display: block;
    padding-right: 76px;
    width: 174px;
    box-sizing: border-box;
}

label::after {
    content: '.' attr(data-domain);
    position: absolute;
    top: 4px;
    left: 96px;
    font-family: arial, helvetica, sans-serif;
    font-size: 12px;
    display: block;
    color: rgba(0, 0, 0, 0.6);
    font-weight: bold;
}
<label data-domain="domain.com">
<input type="text" placeholder="exampledomain" />
<label>
like image 104
Rounin - Glory to UKRAINE Avatar answered Sep 24 '22 11:09

Rounin - Glory to UKRAINE