0

I'm trying to disable browser 'Save Password' functionality (my previous question). To do that, I just added a new input type="password" field inside the form, So this is the code:

<form method="post" action="yoururl"> <input type="password" style="display:none"/><!-- Making "Save Password" disable --> <input type="text" name="username" placeholder="username"/> <input type="password" name="password" placeholder="password"/> </form> 

Note: Using autocomplete=false won't work on modern browsers. So please don't suggest it. In fact I'm trying to use this approach.

Well what's the problem? When I hide that useless input by display:none, it doesn't work (I mean still that saving password option is there.). But when I hide that useless input by visibility:hidden, it works.

As you know visibility property takes up space on the page which I don't want that. So how can I hide that useless input to both hide it and remove its space?

  • display:none is good, but destroys my purpose of adding that useless input.
  • visibility:hidden isn't good because it takes up space on the page.

So is there the other way?

5
  • 1
    position: absolute; left: -9999px Commented Jul 6, 2016 at 12:44
  • 1
    @RoryMcCrossan Yes it works, but seems really abnormal (ugly) :-) Commented Jul 6, 2016 at 12:45
  • css-tricks.com/video-screencasts/142-hiding-things-with-css Choose one ;) Commented Jul 6, 2016 at 12:47
  • It's not ideal, but it's all you can do in cases where an element has to take up space in the DOM but you don't want it to be seen. It also works for pre-loading images too. Commented Jul 6, 2016 at 12:52
  • You can add pointer-events: none if you wish to make the <input> disabled for mouse interactions. Commented Jul 6, 2016 at 12:53

3 Answers 3

1

There are many possible solutions.

One might be:

input[type='password']:nth-of-type(1) { visibility: hidden; width: 1px; height: 1px; } 
Sign up to request clarification or add additional context in comments.

3 Comments

Why not 0px ? :)
I wasn't immediately sure if the browser would accept that, but width:0; height:0; appears to be fine after all.
@Rounin There is a difference in fact. If you declare width and height to 0px, the browsers will think the element is display: none, and the screenreaders will not be able to use the element.
1

See this answer.

I think method 1 is best for you, which is setting width and height of element to 0.

Comments

1

You can disable the autofill trough this autocomplete="new-password"

But if you want to delete the space it take just position it as absolute and hide it behind the body with z-index: -9999;

.fakepassword { visibility: none; position: absolute; z-index: -9999; } 

1 Comment

autocomplete="new-password" works perfectly .. Thank you .. upvote

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.