Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Phillip Elkins
Front End Web Development Techdegree Student 14,875 PointsCentering
I need some help centering everything on my page, this is driving me crazy...
Live View Website
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Computer Emotions | JS Pet</title>
<link rel="stylesheet" href="main.css">
<script src="emotions.js"></script>
</head>
<body>
<header>
<button onclick="buttonClickMain(); return false;">Main</button>
<button onclick="buttonClickHappy(); return false;">Happy</button>
<button onclick="buttonClickSad(); return false;">Sad</button>
<button onclick="buttonClickLieSick(); return false;">Sick</button>
<button onclick="buttonClickScared(); return false;">Scared</button>
<button onclick="buttonClickAngry(); return false;">Angry</button>
</header>
<div>
<img id="main" class="center" src="img/computer.png" alt="" height="500" width="500">
<img id="happy" class="center" src="img/happy.png" alt="" height="500" width="500">
<audio id="hap" src="hap.wav" type="audio/wav"></audio>
<img id="sad" class="center" src="img/sad.png" alt="" height="500" width="500">
<audio id="sad" src="sad.wav" type="audio/wav"></audio>
<img id="sick" class="center" src="img/sick.png" alt="" height="500" width="500">
<audio id="sic" src="sic.wav" type="audio/wav"></audio>
<img id="scared" class="center" src="img/scared.png" alt="" height="500" width="500">
<audio id="sca" src="sca.WAV" type="audio/wav"></audio>
<img id="angry" class="center" src="img/angry.png" alt="" height="500" width="500">
<audio id="ang" src="ang.wav" type="audio/wav"></audio>
</div>
<script src="emotions.js"></script>
</body>
</html>
/**********************************
GENERAL
***********************************/
body {
font-size: 1.3em;
max-width: 800px;
background-color:;
color: #222;
text-align: center;
}
#main {
visibility: visible;
}
#happy, #sad, #sick, #scared, #angry {
visibility: hidden;
}
img {
position: absolute;
}
/**********************************
buttons
***********************************/
header {
margin: 25px;
padding: 25px;
}
button {
width: 100px;
height: 50px;
text-align: center;
text-transform: uppercase;
margin: 0 auto;
display: inline;
}
div.center {
margin: 0 auto;
}
2 Answers
Phillip Elkins
Front End Web Development Techdegree Student 14,875 PointsFIGURED IT OUT!!! :)
img {
margin: 0px;
position: absolute;
top: 70%;
left: 50%;
margin-right: -50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%)
}
Sue Dough
35,800 PointsEnjoy.
/**********************************
GENERAL
***********************************/
body {
font-size: 1.3em;
max-width: 800px;
background-color:;
color: #222;
text-align: center;
margin: 0 auto;
}
#main {
visibility: visible;
}
#happy, #sad, #sick, #scared, #angry {
visibility: hidden;
}
/**********************************
buttons
***********************************/
header {
margin: 25px;
padding: 25px;
}
button {
width: 100px;
height: 50px;
text-align: center;
text-transform: uppercase;
margin: 0 auto;
display: inline;
}
div.center {
margin: 0 auto;
}
Phillip Elkins
Front End Web Development Techdegree Student 14,875 PointsBut when I do that it separates my images >> Changes
Sue Dough
35,800 Pointsyeah saw that, hold up.
Sue Dough
35,800 PointsIts an issue with your JavaScript I think dude.
Sue Dough
35,800 Pointsvisibility: hidden hides the element, but it still takes up space in the layout.
Phillip Elkins
Front End Web Development Techdegree Student 14,875 PointsOk Ill keep trouble shooting, thank for your help.
benfarnham
17,073 Pointsbenfarnham
17,073 PointsGlad you figured it out! Make sure to add your vendor prefixes to cover yourself cross browser wise. 2d transforms are pretty well supported but I would add prefixes just to be safe!
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsYou absolutely need vendor prefixes if you want iDevices to display properly.