Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Bootstrap readonly input field look like normal text?

I have a field in my html page like this:

<input type="text" class="form-control" readonly>

I would like it to look like normal text between <p> tags. Please help me CSS wizards.

like image 862
JohnP Avatar asked Apr 12 '16 13:04

JohnP


People also ask

How do you style a readonly input?

How can I style the readonly attribute with CSS? input[readonly] should work. Make sure it's not being overridden by other, more specific selectors elsewhere in your stylesheet.

How do you make a text field Uneditable?

The readonly attribute makes a form control non-editable (or “read only”). A read-only field can't be modified, but, unlike disabled , you can tab into it, highlight it, and copy its contents. Setting the value to null does not remove the effects of the attribute. Instead use removeAttribute('readonly') .

What is form outline?

a. Method of arrangement or manner of coordinating elements in verbal or musical composition: presented my ideas in outline form; a treatise in the form of a dialogue.


4 Answers

you can try this

CSS

input[readonly]{
  background-color:transparent;
  border: 0;
  font-size: 1em;
}

if you want to use with a class you can try this one

HTML

<input type="text" class="form-control classname" value="Demo" readonly />

CSS

input[readonly].classname{
  background-color:transparent;
  border: 0;
  font-size: 1em;
}

if you want to make the <input> look like inline text (resizing the input element) please check this fiddle https://jsfiddle.net/Tanbi/xyL6fphm/ and please dont forget calling jquery js library

like image 117
Tanbi Avatar answered Oct 17 '22 15:10

Tanbi


I realise the question is about Bootstrap 3, but it might be good to know that Bootstrap 4 now has this out of the box: https://getbootstrap.com/docs/4.0/components/forms/#readonly-plain-text

<div class="form-group row">
<label for="staticEmail" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
  <input type="text" readonly class="form-control-plaintext" id="staticEmail" value="[email protected]">
</div>

like image 31
Wim Deblauwe Avatar answered Oct 17 '22 14:10

Wim Deblauwe


in addition to the accepted answer, I found that the following style works a bit better:

input[readonly] {
    background-color: transparent;
    border: 0;

    box-shadow: none;
}

Bootstrap introduces a shadow that one may want to hide.

like image 4
VeganHunter Avatar answered Oct 17 '22 15:10

VeganHunter


<input type="text" placeholder="Show your text" readonly style="border: 0px;" />

That should work

like image 3
Luca Nicoletti Avatar answered Oct 17 '22 15:10

Luca Nicoletti