Line up three DIVs in the center - html

I want to line up three DIV's in the center of my page, but I can't seem to figure it out. They line up vertically but they won't center themselves. Can anyone help?
HTML:
<div id="page">
<div id="head">
<h1>Final Project</h1>
</div>
<div id="container">
<div align="center" class="float-left" id="arrow-left">
<img src="arrowleft.jpg">
</div>
<div align="center" class="float-left" id="picture">
<img src="old.jpg">
</div>
<div align="center" class="float-left" id="text">
TEXT
</div>
<div align="center" class="float-left id="arrow-right">
<img src="arrowright.jpg">
</div>
</div>
<div>
CSS: (I'm going to add more to #page and such)
.float-left {
float:left;
border: 1px solid black;
}
#page{
display: inline;
width:1000px;
position: absolute;
height: 100%;
width: 100%;
}
#container{
display: inline;
width:900px;
vertical-align: middle;
top: 50%;
position: relative;
}
#arrow-left{
display: inline;
top: -50%;
position: relative;
}
#picture{
display: inline;
top: -50%;
position: relative;
}
#text{
display: inline;
top: -50%;
position: relative;
}
#arrow-right{
display: inline;
top: -50%;
position: relative;
}

Try setting their margins to margin: 0 auto; each. You'll need to specify their widths as well.

Try this CSS:
<style>
.float-left {
display:table-cell;
border: 1px solid black;
}
#page{
display: inline;
width:1000px;
position: absolute;
height: 100%;
width: 100%;
}
#container{
display: table;
width:900px;
vertical-align: middle;
position: relative;
margin:auto;
}
#arrow-left{
position: relative;
}
#picture{
position: relative;
}
#text{
position: relative;
}
#arrow-right{
position: relative;
}
</style>

Your arrow-right div isn't working because the quotation mark is in the wrong place.

Okay so first of all I can see you have a typo in your HTML as shown in the below snippet of your code:
<div align="center" class="float-left id="arrow-right">
<a href="">
<img src="arrowright.jpg"></a></div>
</div>
On the first line of this snippet it should be:
<div align="center" class="float-left" id="arrow-right">
In other words you forgot the " in your class signature.
Second, here is a jsfiddle with three divs floating to the left and are centered. Note when you have multiple markup elements that require to be set in a menu like fashion do not try to style these in this fashion with respect to the body but enclose them in a container and therefore style only this container. As shown in the jsfiddle I center one container w.r.t the body and not 3 divs, this gives cleaner code and avoids future conflicts.
http://jsfiddle.net/7pvwv5pn/

Related

Text centered inside the image

<div>
<img style="vertical-align:middle" src="https://placehold.it/60x60">
<span style="">Product</span>
</div>
I need it like this and it must be responsiveness too. Can you tell me how to do that?
So this question has been asked many times before, here's a snippet from a duplicate I've answered in the past. Hope you can work your own code into the example shown :)
div.counter {
position: relative;
display: inline-block;
}
div.counter span {
position: absolute;
text-align: center;
height: 100%;
width: 100%;
}
div.counter span:before {
display: inline-block;
vertical-align: middle;
height: 100%;
content: '';
}
<div class="counter">
<span>Product</span>
<img src="http://placehold.it/60x60"/>
</div>
below is code what will do that for you.
<!DOCTYPE html>
<html>
<head>
<style>
.center {
margin: auto;
width: 60%;
border: 3px solid #73AD21;
padding: 10px;
}
</style>
</head>
<body>
<h2>Center Align Elements</h2>
<p>To horizontally center a block element (like div), use margin: auto;</p>
<div class="center">
<p><b>Note: </b>Using margin:auto will not work in IE8, unless a !DOCTYPE is declared.</p>
</div>
</body>
</html>
Just put background-image property inside of div style.
One way is to put text as position: absolute;. Another is to put image as background.
#sample-1 img {
vertical-align: middle;
}
#sample-1 {
position: relative;
display: inline-block;
}
#sample-1 span {
position: absolute;
left: 5px;
top: 20px;
}
#sample-2 {
background-image: url('https://placehold.it/60x60');
width: 60px;
height: 60px;
text-align: center;
}
#sample-2 span {
line-height: 60px;
}
<div id="sample-1">
<img src="https://placehold.it/60x60">
<span>Product</span>
</div>
<div id="sample-2">
<span>Product 2</span>
</div>
Try this
<div class="demo">
<img style="vertical-align:middle" src="https://placehold.it/200x200">
<span style="">Product</span>
</div>
css
.demo {
width:200px;
position:relative;
}
.demo span{
position:absolute;
left: 0;
right: 0;
top: 50%;
text-align: center;
margin: -9px auto 0;
}
Use below code in this i have seted line height equals to div height and it is responsive also
#imgContainer{
background: url(https://placehold.it/60x60);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 100%;
text-align: center;
}
#imgDesc{
top: 50%;
position: relative;
}
<div id="imgContainer">
<span id="imgDesc">Works.</span>
</div>
.image {
position:relative;
}
.image img {
width:300px;
}
.text {
left: 0;
position:absolute;
text-align:center;
top: 100px;
width: 300px
}
<div class="image">
<img src="https://placehold.it/60x60"/>
<div class="text">
Text
</div>
</div>

display table can be center in Chrome, but firefox does not show it in center

I want to have a div in center vertically and horizontally with display:table, and It is working very well in chrome but Firefox not showing that correctly.
the div id is #content:
#content {
background: red;
width: 367px;
height: 441px;
display: table;
}
.centered {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
}
<div id="content" class="centered">
<img src="https://www.google.com/images/srpr/logo11w.png" id="img-logo" alt="Google logo">
</div>
jsfiddle
If you can use CSS3, then use transform:translate
See fiddle
This should work
#content {
margin-right: auto;
margin-left: auto;
position: relative;
top: 50%;
transform: translateY(+50%);
}
For css2, you can use table-cell to center contents:
#content {
background: red;
width: 640px;
height: 441px;
display: table-cell;
vertical-align: middle;
text-align: center;
}
<div id="content" class="centered">
<img src="https://www.google.com/images/srpr/logo11w.png" id="img-logo" alt="Google logo">
<div>test</div>
</div>
If you want center the #content on the page, add this css: margin: 0 auto;
See http://www.w3.org/Style/Examples/007/center.en.html

How do I center my logo image to another div in CSS horizontally and vertically?

I need help positioning a logo horizontally center. It also needs to be centered vertically to the top of my links div. Can someone help me?
I'd like my logo to look like this:
Below is my HTML and CSS:
HTML - http://codebin.org/view/199faa14
<div id="container">
<div id="logo">
<img src="images/images/logo.gif" />
</div>
<div id="navigation">
navigation
</div>
<div id="header">
</div>
<div id="line">
</div>
<div id="content">
content
</div>
</div>
CSS - http://codebin.org/view/dda88d94
body {
background: url(../images/images/bg_page.gif) center center;
}
#container {
width: 940px;
margin: 0 auto;
}
#header {
height: 281px;
background: url(../images/home/header.gif) top center;
position: relative;
}
#logo {
position: absolute;
z-index: 2;
top: 0px
height: 214px;
margin: 10px auto 0 auto;
}
#navigation {
position: relative;
height: 40px;
background: #fff;
margin-top: 100px
}
#content {
height: 541px;
background: url(../images/home/bg_body.png) top center;
position: relative;
}
#line {
height: 4px;
background: url(../images/home/line.gif) top center;
position: relative;
}
try something like this before using javascript!
.center {
width: 300px;
height: 300px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -150px;
}
or this!
.image_container {
width: 300px;
height: 300px;
background: #eee;
text-align: center;
line-height: 300px;
}
.image_container img {
vertical-align: middle;
}
I think I understand your question. Since you are calling out your logo img in the html, try this.
<div id="logo">
<img src="images/images/logo.gif" alt="logo" align="center"/>
</div>
You could achieve this with:
display:inline-block;
line-height;
negative margin
text-align:justify (you have 5 items 4 links & 1 img in middle)
:after
Demo made in a similar context for someone else :
http://dabblet.com/gist/5375725
Some people will facing some problems while using the vertical-align: middle; styling attribute. CSS needs to be written in the prober way. For people looking for a quick fix.
.logo { left:0; top:0; height:100%; width:100px; }
<div class="logo" style="background:url('/assets/images/site-logo.png') center center no-repeat;">
<img src="/site/logo.png" style="display:none;" />
</div>
*make sure the container has the position:relative; css attribute.
It's easy handeling retina and compatible with all kind of CSS markups. hope this simple technique can save some time for people :)

Why is there spacing?

I have this annoying little bit of spacing I can't remove.
Here's a fiddle.
It's the white padding(?) between the dog and grey box.
I should probably mention I'm in the process of learning about the box model (relative/absolute) etc.
use display: block; on your img http://jsfiddle.net/QzYcf/1/
#header img { width: 100%; display: block; border: none;}
Move the wrapper div to encase all the divs. Like this: fiddle
You what the header like this fiddle right
HTML:
<div id="wrapper">
<div id="outer">
<div id="inner"></div>
</div></div>
<div id="header">
<img src="http://davesizer.com/blogs/wp-content/uploads/2010/03/eva_jump.jpg" alt="Dog">
</div>
Change this #wrapper and #header to this:
#wrapper{
position: relative; /*or position: absolute; top: 250px;*/
top: 240px;
width:100%;
background-color: lightgrey;
}
#header{
position: fixed;
top: 0;
width: 100%;
height:auto;
background-size: 100%;
}

How can I center text between the top and bottom of a div?

I want to align my text to the middle of my div, but I can't seem to make it work. How can I do this?
Thanks for the help!
<div style="height:40px;">Personal Information</div>
"Personal Information" should be centered between the top and bottom.
CSS:
myDiv
{
display:table-cell;
vertical-align:middle;
}
INLINE:
<div style="display:table-cell; vertical-align:middle;">Personal Information</div>
UPDATE:
This works on JSFIDDLE...
div {
display:table-cell;
width: 200px;
height: 200px;
vertical-align:middle;
background: red;
}
Making line-height the size of the element. It will, however, only work if you have only one line of text.
You can use the table-cell display style to achieve this:
CSS
display: table-cell;
vertical-align: middle;
How about this?
CSS:
#outer {
height: 400px;
overflow: hidden;
position: relative;
width: 100%;
}
#outer[id] {
display: table;
position: static;
}
#middle {
position: absolute;
top: 50%;
width: 100%;
text-align: center;
} /* for explorer only */
#middle[id] {
display: table-cell;
vertical-align: middle;
position: static;
}
#inner {
position: relative;
top: -50%;
text-align: center;
} /* for explorer only */
#inner {
margin-left: auto;
margin-right: auto;
}
div.greenBorder {
border: 1px solid green;
background-color: ivory;
}
HTML
<div id="outer" class="greenBorder">
<div id="middle">
<div id="inner" class="greenBorder"> center
</div>
</div>
</div>
http://jsfiddle.net/3NjUF/4/
This is with the height of 40px:
http://jsfiddle.net/3NjUF/5/
try this(yellow is there to show that it is in the center of the div
<html>
<body>
<div style="height:40px; background-color:yellow">
<div style="position:absolute; top:50%; display:table">Personal Information</div>
</div>
</body>
</html>
You can use a neat Trick of margin:0 auto; to align the contents inside the div to center.
In this case the following code should work fine,
HTML:
<div style="height:40px;"><span>Personal Information</span></div>
CSS:
span
{
width: 50%;
margin: 20px auto;
text-align: center;
display:block
}