Need help with a CSS problem

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Need help with a CSS problem

Post by OldRod »

Trying to stylize my user registration screen and have run into a problem.

In my style.css file I have this:

Code: Select all

#pageMiddle > #register > input[type=text], input[type=password] {
	border: 1px solid black;
	display: block;
	margin: 0 0 1em 0;
	background: #ADA593;
}
Then in my registration page, I have this:

Code: Select all

<div id="pageMiddle">
     <div id="register">
          <h4>Choose a Username:</h4>
          <input type="text" name="username" />
          <h4>Password:</h4>
          <input type="password" name="password" />
     </div>
</div>
What is happening is the password box gets the custom style, but the textbox does not. I tried styling each one individually (just do #pageMiddle > #register > input[type=text] and then neither of them get the style. Only if I have them both on the same line does it work, and then only the 2nd element listed gets the style. If I swap text and password, then the text fields get it, but password fields don't.

What am I doing wrong?
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Need help with a CSS problem

Post by Epiales »

OldRod wrote:Trying to stylize my user registration screen and have run into a problem.

In my style.css file I have this:

Code: Select all

#pageMiddle > #register > input[type=text], input[type=password] {
	border: 1px solid black;
	display: block;
	margin: 0 0 1em 0;
	background: #ADA593;
}
Then in my registration page, I have this:

Code: Select all

<div id="pageMiddle">
     <div id="register">
          <h4>Choose a Username:</h4>
          <input type="text" name="username" />
          <h4>Password:</h4>
          <input type="password" name="password" />
     </div>
</div>
What is happening is the password box gets the custom style, but the textbox does not. I tried styling each one individually (just do #pageMiddle > #register > input[type=text] and then neither of them get the style. Only if I have them both on the same line does it work, and then only the 2nd element listed gets the style. If I swap text and password, then the text fields get it, but password fields don't.

What am I doing wrong?
Strange, as I just put your code into an empty page and both get the custom style. Do you have other css or styles that conflict with them?
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Need help with a CSS problem

Post by Epiales »

Maybe try something like:

Code: Select all

<style>
   input[type=text], input[type=password] {
   border: 1px solid black;
   display: block;
   margin: 0 0 1em 0;
   background: #ADA593;
}
   </style>
   <div class="pageMiddle">
   <div class="register">
   <h4>Choose a Username:</h4>
   <input type="text" name="username" />
   <h4>Password:</h4>
   <input type="password" name="password" />
   </div>
</div> 
Works for me as well.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: Need help with a CSS problem

Post by OldRod »

Yeah, if I remove the #pageMiddle and #register div names, then it works, but this form is inside those divs and I wanted it styled differently than other forms on the site if I can

I will keep tinkering with it :)
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Need help with a CSS problem

Post by Epiales »

OldRod wrote:Yeah, if I remove the #pageMiddle and #register div names, then it works, but this form is inside those divs and I wanted it styled differently than other forms on the site if I can

I will keep tinkering with it :)
Well, I've found out that CSS can be very touchy :lol: ! Hope you get it figured out soon. I also, as said before, took your code and plugged it into a blank file and it all worked. It formatted everything. So not sure! Thought maybe changing them individually might help and turning them into class.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: Need help with a CSS problem

Post by OldRod »

I got it working. I just made a special div class "reginput" and used that for those input boxes :)
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Need help with a CSS problem

Post by Epiales »

OldRod wrote:I got it working. I just made a special div class "reginput" and used that for those input boxes :)
Awesome! Glad you have it working ;)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”