Solved

Getting margin-left to cooperate between IE 9 and Firefox

Posted on 2011-09-28
6
333 Views
Last Modified: 2012-05-12
I cannot seem to get this simple css and layout to work on both firefox and IE9.  This is a very simplified version of my normal css but it demonstrates the issue.  In IE the textbox appears in the div (this is where I want it).  In Firefox the textbox appears offset right from the div.  I do not doubt that IE is the culprit here, but what can I do to get this to render the same in both browsers (without taking the textbox out of the div)?

Thanks for any suggestions!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<style>
		input[type=text]
		{
			margin-left: 118px;
			width: 380px;
			background-color: Red;
		}
		.userNameDiv
		{
			position: fixed;
			top: 50%;
			left: 50%;
			margin-left: -118px;
			width: 380px;
			background-color: Green;
		}
	</style>
</head>
<body>
	<div class="userNameDiv">
		<input type="text" />
	</div>
</body>
</html>

Open in new window

0
Comment
Question by:nicolees
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:SSupreme
ID: 36718142
It looks the same in FF6 and IE9. Could you please provide FF version you have used, and confirm that you used IE9.
0
 

Author Comment

by:nicolees
ID: 36718176
Firefox 6, and you are right about IE9.  It looks like I had my browser compatibility mode set to IE7.  So Firefox 6 and IE 9 behave the same.  IE7 and IE8 are different.

Fundamentally I want the textbox to sit inside the div on all 4 browsers (IE7, IE8, IE9, Firefox 6).  
0
 
LVL 16

Expert Comment

by:SSupreme
ID: 36718753
Try to remove margin-left: -118px; from .userNameDiv.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nicolees
ID: 36718868
Removing margin-left: -118px from .userNameDiv makes all browsers behave the same, but leave the div in the incorrect location.  I need it offset left 118 pixels from center

This gives me what I want in IE8, IE9, Firefox
		input[type=text]
		{
			margin-left: 0px;
			width: 380px;
			background-color: Red;
		}
		.userNameDiv
		{
			position: fixed;
			top: 50%;
			left: 50%;
			margin-left: -118px;
			width: 380px;
			background-color: Green;
		}

Open in new window


This gives me what I want on IE7
		input[type=text]
		{
			margin-left: 118px;
			width: 380px;
			background-color: Red;
		}
		.userNameDiv
		{
			position: fixed;
			top: 50%;
			left: 50%;
			margin-left: -118px;
			width: 380px;
			background-color: Green;
		}

Open in new window


I would rather not conditionally load stylesheets based on browser type.  This seems like a simple issue, I guess I was hoping that, with a single stylesheet, I could render a textbox aligned and inside of a div at 118px left of center.
0
 
LVL 16

Accepted Solution

by:
SSupreme earned 500 total points
ID: 36719640
I cannot get what you want as it isn't in the content. I mean is there any better possibilities to place div in center?
But you can do this: <div class="userNameDiv"><div><input type="text" /></div></div>
or add rule into CSS file specially for IE7, after original rule: *+html input[type=text] {margin-left: 118px;}
0
 

Author Comment

by:nicolees
ID: 36719815
Thanks, that is what I needed.  This css/html resolves my issue

<head>
	<style>
		input[type=text]
		{
			margin-left: 0px;
			width: 380px;
			background-color: Red;
		}
		.userNameDiv
		{
			position: fixed;
			top: 50%;
			left: 50%;
			margin-left: -118px;
			width: 380px;
			background-color: Green;
		}
		*+html input[type=text]
		{
			margin-left: 118px;
		}
	</style>
</head>
<body>
	<div class="userNameDiv">
		<input type="text" />
	</div>

</body>
</html>

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
output in HTML format powershell 6 48
boostsrap 1 32
problems with widget background image 9 34
Trying to use &NBSP to line up 3 rows 12 38
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question