Solved

Getting margin-left to cooperate between IE 9 and Firefox

Posted on 2011-09-28
6
327 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now