Centering everything vertically, in DIV / LI - html

this might be simple, still cant figure it out...
html
<ul>
<li>
<a href="/">
<div class="menuIcons">
<img src="http://prog.hu/assets/site/text/quicknews/03418/silverlight-boot-by-yanomami--dyn--focus.jpg" width="25" height="25" alt="home icon"><span style="background-color: green;">Home</span>
</div>
</a>
</li>
</ul>
css
.menuIcons
{
display:table-cell;
background-color: red;
vertical-align: middle;
height: 40px;
}
li, img
{
padding: 0; margin: 0; border: 0;
}
li
{
background-color: yellow;
}
div
{
background-color: red;
}
http://jsfiddle.net/AvL9Y/1/
this is not precisely centered at all

http://jsfiddle.net/AvL9Y/9/
Floating elements allows you to position them vertically, while text gets aligned in the middle of your element when you set a line height (so all you need to do is set the line height of the text container to whatever height you want - 25px being the height of your image, I went for that):
.myImage, .text { float: left; display: block; }
.text { line-height: 25px; }
I've slightly modified your HTML to:
<ul>
<li>
<a href="/">
<div class="menuIcons">
<img class="myImage" src="http://prog.hu/assets/site/text/quicknews/03418/silverlight-boot-by-yanomami--dyn--focus.jpg" width="25" height="25" alt="home icon" /><div class="text" style="background-color: green;">Home</div>
</div>
</a>
</li>
</ul>

http://jsfiddle.net/AvL9Y/18/
HTML:
<ul>
<li>
<a href="/">
<div class="menuIcons">
<div class="wrapper">
<img src="http://prog.hu/assets/site/text/quicknews/03418/silverlight-boot-by-yanomami--dyn--focus.jpg"width="25" height="25" alt="home icon" />
<div class="text">Home</span>
</div>
</div>
</a>
</li>
<li>
<a href="/">
<div class="menuIcons">
<div class="wrapper">
<img src="http://prog.hu/assets/site/text/quicknews/03418/silverlight-boot-by-yanomami--dyn--focus.jpg"width="25" height="25" alt="home icon" />
<div class="text">Home</span>
</div>
</div>
</a>
</li>
CSS:
.menuIcons
{
display:table-cell;
background-color: red;
vertical-align: middle;
height: 40px;
}
.wrapper{
display:table;
}
li,img{
display:table-cell;
vertical-align: middle;
}
.text{
background-color: green;
display:table-cell;
vertical-align: middle;
}
li
{
background-color: yellow;
height: 50px;
}
div
{
background-color: red;
}

LIke this
demo
css
.menuIcons {
display: table-cell;
background-color: red;
vertical-align: middle;
height: 40px;
background-color: yellow;
}
li, img {
padding: 0;
margin: 0;
border: 0;
vertical-align: middle;
text-align: center;
}
li {
list-style-type: none;
vertical-align: middle;
display: inline-block;
overflow: hidden;
margin: 0 3px;
}
a {
display: block;
}
div {
background-color: red;
vertical-align: middle;
}
span {
vertical-align: middle;
display: block;
}

Try This
<ul>
<li> <a href="/"> <span class="menuIcons">
<img src="http://prog.hu/assets/site/text/quicknews/03418/silverlight-boot-by-yanomami--dyn--focus.jpg" width="25" align="center" height="25" alt="home icon"><span style="background-color: green;">Home</span>
</span>
</a>
</li>
</ul>
CSS
.menuIcons
{
display:table-cell;
background-color: red;
list-style-type: none;
vertical-align: middle;
height: 40px;
}
li, img
{
padding: 0; margin: 0; border: 0;
}
li
{
display:block;
vertical-align:middle;
background-color: yellow;
}
div
{
background-color: red;
}

Related

How come one of my images aren't displaying next to each other?

I'm trying to line up 3 images and some text on one 'line', the first 2 images are lined up fine, same with the text but the 3rd image refuses to and i'm not sure why.
here is my code so far:
* {
box-sizing: border-box;
}
body {
display: inline-block;
width: 800px;
height: 1000px;
}
.logo {
padding: 5px;
display: inline;
}
.pfp {
display: inline;
}
.msg {
display: inline;
}
.userid {
text-decoration-color: white;
background-color: rgb(250, 250, 250);
text-align: left;
width: 50px;
border-radius: 20%;
display: block;
font-size: 10px;
margin-left: 160px;
margin-top: -18px;
}
<div class='logo'>
<img src='logo.jpg' , width=1 00px>
</div>
<div class="pfp">
<a href="Profile Page.html">
<img src='pfp.jpg' , width=5 0px>
</a>
</div>
<div class='userid'>
<span>[user_id]</span>
</div>
<div class='msg'>
<a href='messages.html'>
<img src='messages.jpg' , width=5 0px>
</a>
</div>
Your .userid also needs to be displayed inline or inline-block so the next item can be inline with it. Right now it's displayed as block so it's shoving anything after it to the next line.
* {
box-sizing: border-box;
}
body {
display: inline-block;
width: 800px;
height: 1000px;
}
.logo {
padding: 5px;
display: inline;
}
.pfp {
display: inline;
}
.msg {
display: inline;
}
.userid {
text-decoration-color: white;
background-color: rgb(250, 250, 250);
text-align: left;
width: 50px;
border-radius: 20%;
//display: block;
display: inline;
font-size: 10px;
margin-left: 160px;
margin-top: -18px;
}
<div class='logo'>
<img src='logo.jpg' , width=1 00px>
</div>
<div class="pfp">
<a href="Profile Page.html">
<img src='pfp.jpg' , width=5 0px>
</a>
</div>
<div class='userid'>
<span>[user_id]</span>
</div>
<div class='msg'>
<a href='messages.html'>
<img src='messages.jpg' , width=5 0px>
</a>
</div>

How do you make every text display perfectly in the center of the image? [duplicate]

This question already has answers here:
Vertically align text next to an image?
(26 answers)
How can I vertically align elements in a div?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 2 years ago.
Look that every text is displayed below the picture. I would like every text to be displayed perfectly in the center of the picture.
Here is the code:
https://jsfiddle.net/Krzysiek_35/Ljybwz97/37/
body {
left: 8%;
top: 10%;
position: absolute;
background-color: #6699cc;
}
.box3 {
background-color: #191919;
position: absolute;
padding: 15px 40px 15px;
font-size: 12px;
color: #DDDDDD;
font-family: Verdana;
font-size: 12px;
width: 400px;
}
.box3 > li {
display: block;
}
.box3 > li span {
display: inline-block;
vertical-align: middle;
}
<body>
<div class="box3">
<li>
<img src="pictures/contact/skype.png" width="34px" height="34px" />
<span>Skype name</span>
</li>
<li>
<img src="pictures/contact/gadu-gadu.png" width="34px" height="34px" />
<span>Gadu-Gadu number</span>
</li>
<li>
<img src="pictures/contact/email.png" width="34px" height="34px" />
<span>Email address</span>
</li>
</div>
</body>
How do you make every text display perfectly in the center of the image?
I will be very grateful for effective help.
Set vertical-align: middle to img:
body
{
left: 8%;
top: 10%;
position: absolute;
background-color: #6699cc;
}
.box3
{
background-color: #191919;
position: absolute;
padding: 15px 40px 15px;
font-size: 12px;
color: #DDDDDD;
font-family: Verdana;
font-size: 12px;
width: 400px;
}
.box3 > li
{
display: block;
}
.box3 > li span
{
display: inline-block;
vertical-align: middle;
}
.box3 img{
vertical-align: middle;
}
<body>
<div class="box3">
<li>
<img src="pictures/contact/skype.png" width="34px" height="34px" />
<span>Skype name</span>
</li>
<li>
<img src="pictures/contact/gadu-gadu.png" width="34px" height="34px" />
<span>Gadu-Gadu number</span>
</li>
<li>
<img src="pictures/contact/email.png" width="34px" height="34px" />
<span>Email address</span>
</li>
</div>
</body>
.box3 > li {
display: flex;
align-items: center;
}
you can use this also
.box3 > li span
{
display: inline-block;
vertical-align: middle;
margin-top:-30px;
}

How to center three divs horizontally within a parent div? [duplicate]

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 6 years ago.
I know this question has been frequently asked but I can never seem to get it to work. Can you tell me what's wrong?
I have three divs within a #container div, which I want to centre side by side. The #container is 1000px wide (I want to keep it that way). Here is my code:
#container {
margin-top: 500px;
position: absolute;
width: 1000px;
}
.related-article {
background-color: #D6A400;
display: inline-block;
width: 230px;
height: 300px;
border-radius: 30px;
margin-bottom: 0px;
}
.related-article > img {
width: 200px;
height: 150px;
border-radius: 15px;
margin-top: 15px;
}
.related-article > h3 {
font-size: 15px;
width: 180px;
text-align: justify;
margin-left: auto;
margin-right: auto;
color: #f1f1f1;
font-family: Abel, serif;
margin-bottom: none;
}
a {
text-decoration: none;
}
#right {
float: right;
}
#left {
float: left;
}
#center {
margin-left: 385px;
margin-right: 385px;
}
<div id="container">
<h2>Here's what you'll do!</h2>
<div id="left">
<a href="#" class="related-article first" align="middle">
<img src="download.jpeg" alt="T-rex">
<h3>Constructing amazing fossils you never even dreamed of</h3>
</a>
</div>
<div id="center">
<a href="#" class="related-article second" align="middle">
<img src="fossil-fish-10-lg.jpg" alt="Fish">
<h3>Studying ancient marine biology</h3>
</a>
</div>
<div id="right">
<a href="#" class="related-article third" align="middle">
<img src="fossil.turtle2.jpg" alt="Turtle">
<h3>Uncovering the world's greatest mysteries</h3>
</a>
</div>
</div>
All help would be gladly appreciated.
You can do that quite simple using flexbox:
#container {
/* margin-top: 500px; */
width: 1000px;
margin: 0 auto;
}
.related-article {
background-color: #D6A400;
display: inline-block;
border-radius: 30px;
margin-bottom: 0px;
}
.related-article > img {
width: 200px;
height: 150px;
border-radius: 15px;
margin-top: 15px;
}
.related-article > h3 {
font-size: 15px;
width: 180px;
text-align: justify;
margin-left: auto;
margin-right: auto;
color: #f1f1f1;
font-family: Abel, serif;
margin-bottom: none;
}
a {
text-decoration: none;
}
}
#container {
width: 1000px;
}
.related-article {
background-color: #D6A400;
display: inline-block;
width: 230px;
height: 300px;
border-radius: 30px;
margin-bottom: 0px;
}
.related-article > img {
width: 200px;
height: 150px;
border-radius: 15px;
margin-top: 15px;
}
.related-article > h3 {
font-size: 15px;
width: 180px;
text-align: justify;
margin-left: auto;
margin-right: auto;
color: #f1f1f1;
font-family: Abel, serif;
margin-bottom: none;
}
a {
text-decoration: none;
}
.box {
margin-right: 10px;
width: 230px;
height: 300px;
}
.flex-container {
display: flex;
align-items: center;
justify-content: center;
}
<div id="container">
<h2>Here's what you'll do!</h2>
<div class="flex-container">
<div id="left" class="box">
<a href="#" class="related-article first" align="middle">
<img src="download.jpeg" alt="T-rex">
<h3>Constructing amazing fossils you never even dreamed of</h3>
</a>
</div>
<div id="center" class="box">
<a href="#" class="related-article second" align="middle">
<img src="fossil-fish-10-lg.jpg" alt="Fish">
<h3>Studying ancient marine biology</h3>
</a>
</div>
<div id="right" class="box">
<a href="#" class="related-article third" align="middle">
<img src="fossil.turtle2.jpg" alt="Turtle">
<h3>Uncovering the world's greatest mysteries</h3>
</a>
</div>
</div>
</div>
A solution using display: flex. Read more about flexbox here
Apply display: flex to the container
Add flex: 1 to all the child's which are to be centered horizontally.
h2 {
margin-top: 500px;
}
#container {
position: absolute;
width: 1000px;
display: flex;
text-align: center;
}
#container div {
flex: 1;
}
.related-article {
background-color: #D6A400;
display: inline-block;
width: 230px;
height: 300px;
border-radius: 30px;
margin-bottom: 0px;
}
.related-article > img {
width: 200px;
height: 150px;
border-radius: 15px;
margin-top: 15px;
}
.related-article > h3 {
font-size: 15px;
width: 180px;
text-align: justify;
margin-left: auto;
margin-right: auto;
color: #f1f1f1;
font-family: Abel, serif;
margin-bottom: none;
}
a {
text-decoration: none;
}
<h2>Here's what you'll do!</h2>
<div id="container">
<div id="left">
<a href="#" class="related-article first" align="middle">
<img src="download.jpeg" alt="T-rex">
<h3>Constructing amazing fossils you never even dreamed of</h3>
</a>
</div>
<div id="center">
<a href="#" class="related-article second" align="middle">
<img src="fossil-fish-10-lg.jpg" alt="Fish">
<h3>Studying ancient marine biology</h3>
</a>
</div>
<div id="right">
<a href="#" class="related-article third" align="middle">
<img src="fossil.turtle2.jpg" alt="Turtle">
<h3>Uncovering the world's greatest mysteries</h3>
</a>
</div>
</div>
Remove all the floats and replace them with :
display: inline-block;
Also, as much as i have tried, with that spacing between divs, you wont be able to display them the right way. Make the space between the #left, #center and #right divs less than 50px, or work with percentage(%).
You may use display:table for that..
You can have Parent div with style
display:table
and your 3 child divs as
display:table-cell
#container {
margin-top: 500px;
position: absolute;
width: 1000px;
}
.related-article {
background-color: #D6A400;
display: inline-block;
width: 230px;
height: 300px;
border-radius: 30px;
margin-bottom: 0px;
}
.related-article > img {
width: 200px;
height: 150px;
border-radius: 15px;
margin-top: 15px;
}
.related-article > h3 {
font-size: 15px;
width: 180px;
text-align: justify;
margin-left: auto;
margin-right: auto;
color: #f1f1f1;
font-family: Abel, serif;
margin-bottom: none;
}
a {
text-decoration: none;
}
#container {
margin-top: 500px;
position: absolute;
width: 1000px;
display: table;
}
.related-article {
background-color: #D6A400;
display: inline-block;
width: 230px;
height: 300px;
border-radius: 30px;
margin-bottom: 0px;
}
.related-article > img {
width: 200px;
height: 150px;
border-radius: 15px;
margin-top: 15px;
}
.related-article > h3 {
font-size: 15px;
width: 180px;
text-align: justify;
margin-left: auto;
margin-right: auto;
color: #f1f1f1;
font-family: Abel, serif;
margin-bottom: none;
}
a {
text-decoration: none;
}
#left,
#right,
#center {
display: table-cell;
}
#center {
margin-left: 385px;
margin-right: 385px;
}
h2 {
display: table-row;
}
<div id="container">
<h2>Here's what you'll do!</h2>
<div id="left">
<a href="#" class="related-article first" align="middle">
<img src="download.jpeg" alt="T-rex">
<h3>Constructing amazing fossils you never even dreamed of</h3>
</a>
</div>
<div id="center">
<a href="#" class="related-article second" align="middle">
<img src="fossil-fish-10-lg.jpg" alt="Fish">
<h3>Studying ancient marine biology</h3>
</a>
</div>
<div id="right">
<a href="#" class="related-article third" align="middle">
<img src="fossil.turtle2.jpg" alt="Turtle">
<h3>Uncovering the world's greatest mysteries</h3>
</a>
</div>
</div>
remove float from and add display: inline-block to all three, then add text-align: center; to the container.
Try this, and add float:left to your right,left and center div and reduce your margin left and right of center div.
#right {
float: left;
}
#left {
float: left;
}
#center {
margin-left: 85px;
margin-right: 85px;
float:left;
}
Instead adding center, left and right. Use ul and set the width of li in percentage. It will improve the code and reduce the css code.
The codepen url is http://codepen.io/SESN/pen/pbbjrb
CSS
#container { width: 100%; }
.ulContainer { margin: 0px auto; list-style: none; width: 80%; }
.ulContainer li { width: 33.33%; float: left; }
HTML
<div id="container">
<h2>Here's what you'll do!</h2>
<ul class="ulContainer">
<li>
<a href="#" class="related-article first" align="middle">
<img src="download.jpeg" alt="T-rex">
<h3>Constructing amazing fossils you never even dreamed of</h3>
</a>
</li>
<li>
<a href="#" class="related-article second" align="middle">
<img src="fossil-fish-10-lg.jpg" alt="Fish">
<h3>Studying ancient marine biology</h3>
</a>
</li>
<li>
<a href="#" class="related-article third" align="middle">
<img src="fossil.turtle2.jpg" alt="Turtle">
<h3>Uncovering the world's greatest mysteries</h3>
</a>
</li>
</ul>
</div>

Allign divs to middle of screen by their middle

Using bootstrap, I need to have a page with divs (4 initially) as buttons in the middle of the screen, as below image:
I succeeded to do this, but, next, I need to enlarge one of them when mouseover as below image:
so, they are aligned by their middle. and all others will be smaller when another on is hover.
Simply increase the width and height on :hover.
html, body,
.container {
height: 100%;
}
.container {
display: table;
vertical-align: middle;
}
.vertical-center-row {
display: table-cell;
vertical-align: middle;
}
.buttons-container {
vertical-align: bottom;
text-align: center;
}
.app-button:hover {
width: 75px;
height: 75px;
}
.app-button {
width: 50px;
height: 50px;
margin: 15px;
background-color: #cccccc;
display: inline-block;
vertical-align: middle;
transition: all 0.5s;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row vertical-center-row">
<div class="col-md-12 buttons-container">
<div class="app-button"></div>
<div class="app-button"></div>
<div class="app-button"></div>
<div class="app-button"></div>
</div>
</div>
</div>
You can try two methods one is to increase the height and width and the other is to use transform
With transform Fiddle
html, body, .container {
height: 100%;
}
.container {
display: table;
vertical-align: middle;
}
.vertical-center-row {
display: table-cell;
vertical-align: middle;
}
.buttons-container {
vertical-align: bottom;
text-align: center;
}
.app-button {
width: 50px;
height: 50px;
margin: 15px;
background-color: #cccccc;
display: inline-block;
}
.app-button:hover {
transform:scale(1.5,1.5);
margin: 15px;
background-color: #cccccc;
display: inline-block;
}
<div class="container">
<div class="row vertical-center-row">
<div class="col-md-12 buttons-container"> <a href="#">
<div class="app-button"></div>
</a>
<a href="#">
<div class="app-button"></div>
</a>
<a href="#">
<div class="app-button">
</div>
</a>
<a href="#">
<div class="app-button">
</div>
</a>
</div>
</div>
</div>
By changing height and width Fiddle
html, body, .container {
height: 100%;
}
.container {
display: table;
vertical-align: middle;
}
.vertical-center-row {
display: table-cell;
vertical-align: middle;
}
.app-button:hover {
height:100px;
width:100px;
}
.buttons-container {
vertical-align: bottom;
text-align: center;
}
.app-button {
width: 50px;
height: 50px;
margin: 15px;
background-color: #cccccc;
display: inline-block;
vertical-align:middle;
}
<div class="container">
<div class="row vertical-center-row">
<div class="col-md-12 buttons-container"> <a href="#">
<div class="app-button"></div>
</a>
<a href="#">
<div class="app-button"></div>
</a>
<a href="#">
<div class="app-button">
</div>
</a>
<a href="#">
<div class="app-button">
</div>
</a>
</div>
</div>
</div>

Making a footer for a page but some CSS does not work out

So I am trying to make a footer for a webpage.
Here is what I have:
What I want is (I did my best to demonstrate it):
(The images seem to be too small because it is too long. If you don't mind, zoom in your browser.)
Then here comes my HTML structure:
<div id="footer">
<table id="info">
<tr>
<td colspan="3">You're here:
<div id="where"></div></td>
</tr>
<tr>
<th>
<div id="additional-links">
<ul class="nobullet">
<li>Intro</li>
<li>Hiring</li>
<li>Collab</li>
<li>Credits</li>
<div id="shared">
<span style="color: #fff;">|</span>
<img src="fl.jpg" alt="facebook">
<img src="tl.jpg" alt="twitter">
<img src="tml.png" alt="tumblr">
<span style="color: #fff;">|</span>
</div>
</ul>
</div>
</th>
</tr>
<tr>
<td colspan="3">©2013
</td>
</tr>
</table>
</div>
Then the corresponding CSS:
div {
padding: 0;
margin: 0;
text-align: center;
}
#footer {
width: 100%;
height: 15%;
background-color: #dcd9ca;
}
#info {
text-align: center;
width: 100%;
min-height: 100%;
}
.nobullet li {
display: inline;
}
.nobullet li a {
text-decoration: none;
color: brown;
}
#shared {
float: right;
position: relative;
}
#shared img{
width: 24px;
height: 24px;
vertical-align: middle;
}
So my question is: how do I make the changes?
I hope I have made myself clear.
I agree with the comment made by #vishalkin that you should not use the table structure.
Even if you did, you have an issue that make yours HTML invalid. The #shared div cannot be a parent of an ul. You need to wrap this in a li.
Here is my solution on jsfiddle.net.
Here is the HTML:
<div id="footer">
<p>You're here:</p>
<div id="footerLinks">
<ul id="links">
<li>Intro</li>
<li>Hiring</li>
<li>Collab</li>
<li>Credits</li>
</ul>
<ul id="shared">
<li>| <img src="" alt="facebook"/></li>
<li><img src="" alt="twitter"/></li>
<li><img src="" alt="tumblr"/> |</li>
</ul>
</div>
<p>©2013</p>
</div>
Here is the CSS:
body { background: #060; width: 1024px; }
div { padding: 0; margin: 0; text-align: center; }
#footer { width: 100%; text-align: center; background-color: #dcd9ca; position: relative; }
#footer ul,
#footer li { margin: 0px; padding: 0px; }
#footerLinks { position: relative; }
#links { list-style: none; display: inline; width: auto; }
#links li { display: inline-block; *display: inline; *zoom: 1; /* IE7 fix */ }
#links li > a { display: block; width: 150px; text-decoration: none; color: brown; text-align: center; font-weight: bold; }
#shared { position: absolute; top: 0px; right: 75px; /* your margin from the right */ list-style: none; color: #fff;}
#shared li { display: inline-block; *display: inline; *zoom: 1; /* IE7 fix */ }
#shared img { border: 0px; width: 24px; height: 24px; vertical-align: middle; }
I threw in some extras for you:
Border 0 on your social media images. Some browsers will show a giant blue border when images are inside links
Made your footer links block, so that they are more accessible, rather than only taking up the text area
In my jsfiddle, I put a width on the body, and a color, only to demonstrate the padding on the right of your social media links.
To solve both issues, you can make the shared div absolutely positioned.
<div id="additional-links">
<div id="shared">
<span style="color: #fff;">|</span>
<img src="fl.jpg" alt="facebook">
<img src="tl.jpg" alt="twitter">
<img src="tml.png" alt="tumblr">
<span style="color: #fff;">|</span>
</div>
<ul class="nobullet">
<li>Intro</li>
<li>Hiring</li>
<li>Collab</li>
<li>Credits</li>
</ul>
</div>
You can adjust how far from the right the shared links are by changing the 150px setting below.
#additional-links {
position: relative;
}
#shared {
position: absolute;
right: 150px;
}
Hope that helps.