jax
0
Q:

css vertical align middle

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style type="text/css">
      div {
        display: table-cell;
        width: 250px;
        height: 200px;
        vertical-align: middle;
      }
    </style>
  </head>
  <body>
    <div>Vertically aligned text</div>
  </body>
</html>
10
/* Answer to: "css vertical align middle" */

/*
  Go to: https://www.w3schools.com/css/css_align.asp
  Here you can learn many ways to align horizontal and vertically!
  My favourite method is below:
*/

.center {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
  border: 3px solid green;
}
5
.container{	
	margin: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
  	width: /* Define the width here; */
    height: /* Define the height here; */
}

/*You have to define the width and height! */
2
.container{
  display: table;
}

.div-inside-container{
  display: table-cell;
  vertical-align: middle;
}
3
<!-- 
	 Simple CSS CENTER DIV Example
 	 
	 * See Fiddle in link for PoC *
-->

<div class="parent">
  <div class="child">
    <p>
      Eh Up Me Duck!
    </p>
  </div>
</div>

<style>
.parent {
  /* Just for aesthetics: see fiddle */
  border: 1px solid black;
  padding: 2px;
}

.child {
  border: 1px solid red;
  width: 50%;
  
  /* This is where the magic happens */
  margin-left: auto;
  margin-right: auto;
  /**********************************/
}

p {
  /* As you do */
  text-align: center;
}
</style>
8
#inner {
  width: 50%;
  margin: 0 auto;
}
1

    img.a {
  vertical-align: baseline;
}

img.b {
  vertical-align: text-top;
}

img.c {

      
    vertical-align: text-bottom;
}

img.d {
  
    vertical-align: sub;
}

img.e {
  vertical-align: super;
}  
0
<!DOCTYPE html>
<!--clearfix-->
<html>
<head>
<style>
div {
  border: 3px solid #4CAF50;
  padding: 5px;
}

.img1 {
  float: right;
}

.clearfix {
  overflow: auto;
}

.img2 {
  float: right;
}
</style>
</head>
<body>

<p>In this example, the image is taller than the element containing it, and it is floated, so it overflows outside of its container:</p>

<div>
  <img class="img1" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...
</div>

<p style="clear:right">Add a clearfix class with overflow: auto; to the containing element, to fix this problem:</p>

<div class="clearfix">
  <img class="img2" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...
</div>

</body>
</html>
1

.clearfix {
  overflow: auto;
} 
2

New to Communities?

Join the community