/    Sign up×
Community /Pin to ProfileBookmark

New to this and frustrated!

I have a background image and a form I want to center in the browser. I have the image working and I have the form centered vertically, but cannot get it horizontally. I did originally have it horizontally, but not vertically ….see code below: Any help would be appreciated.

[code]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>

<html>
<head>
<title>Adaptive Methods Login</title>
<style type=”text/css”>
#loginPage {
background-image:url(“login-screen-intranet.jpg”);
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
#myoutercontainer {
position:realative;
}
#myinnercontainer {
position:absolute;
top:50&#37;;
height:10em;
margin-top:-5em;
}
label {
color:#FFF;
}
</style>

</head>
<body id=”loginPage”>
<div id=”myoutercontainer”>
<div id=”myinnercontainer”>
<form>
<p><br/><br/><label>Username: </label><input type=”text”/></p>
<p><label>Password: </labbel><input type=”password”/></p>
<p><input type=”button” value=”Login”></p>
</form>
</div>
</div>
</body>
[/code]

to post a comment
CSS

8 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 28.2011 — This is a CSS problem, not a JavaScript one. I'll move your post to the CSS Forum
Copy linkTweet thisAlerts:
@Cory_RJul 28.2011 — Why are you using absolute positioning? It should be avoided unless it's totally necessary. You can likely accomplish whatever you want without it. [b]text-align: center;[/b] will center it without the absolute positioning, otherwise you can use something like [b]left: 40%;[/b]
Copy linkTweet thisAlerts:
@owudoinauthorJul 28.2011 — are you talking about under my innercontainer? It was a solution I found to center the form vertically. text-align has no affect if added.
Copy linkTweet thisAlerts:
@KorJul 28.2011 — are you talking about under my innercontainer? It was a solution I found to center the form vertically. text-align has no affect if added.[/QUOTE]
make the lateral margins as [B]auto[/B]
<i>
</i>.myClass{
display:block;
width:[COLOR="Blue"]XXX[/COLOR]px;
margin-left:auto;
margin-right:auto;
}
Copy linkTweet thisAlerts:
@Cory_RJul 28.2011 — [CODE]#myinnercontainer {
height: 100%;
position: relative;
text-align: center;
top: 50%;
}

body {
overflow: hidden;
}[/CODE]
There's something else you can try.

Kor's fix will not be resolution-friendly since the width has to be a fixed width.
Copy linkTweet thisAlerts:
@owudoinauthorJul 28.2011 — thanks for the help! that took care of the input lines except for the button.
Copy linkTweet thisAlerts:
@KorJul 28.2011 — 
Kor's fix will not be resolution-friendly since the width has to be a fixed width.[/QUOTE]

Resolution friendly? Only if we are talking about a full liquid design, which is not always a good choice. On the other hand the OP can use a [I]percent[/I] width as well. ?
Copy linkTweet thisAlerts:
@Cory_RJul 28.2011 — Actually, scratch what I said above, if you give the container a width of 100%, it will horizontally center it.
×

Success!

Help @owudoin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...