1

I'm trying to make my registration form responsive for mobile devices but I got a little problem with the resizing of my input fields,

I made a jsfiddle to show the situation: https://jsfiddle.net/ntvrhLpe/

I would like that if the width is smaller than 540px the input fields automatically resize to full width with a margin of 10px at both sides.

I already tried some things but nothing works:

input[type=text], input[type=password], input[type=email]{
margin-left:10px;
margin-right:10px;
width:100%;
}

Can someone help me?

2 Answers 2

2

Your initial CSS for inputs

input[type=text], input[type=password], input[type=email] {
    font-size: 20px;
    margin-bottom:10px;
    padding: 8px 6px;
    height: 38px;
    width:250px;
    box-sizing: border-box;
}

Then in your media query:

input[type=text], input[type=password], input[type=email] {
    margin-left: 0px;
    margin-right: 0px;
    width: 100%;
}

fieldset {
    padding: 10px;
}

You will get it

You should get satisfaction

Sign up to request clarification or add additional context in comments.

2 Comments

Only problem is that the height of the input field is now changed?
The box-sizing: border-box; allows you to set a width even if a padding is set without disturbing the Math of width
0

You have not set the width is your css ( it was not in the fiddle although you have mention it in you question ! )

Please see https://jsfiddle.net/rwbLmex2/

@media (max-width: 540px) {
label {
    text-align:left;
    width:180px;
    float:left;
    margin-top:10px;
    margin-left:20px;
} 
input[type=text], input[type=password], input[type=email]{
    margin-left:10px;
    margin-right:10px;
    width : 100%
}
}

By the way I recommend to use a CSS framework like bootstrap which handle all them for you !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.