vertical-align



значения свойства:


  • baseline
  • value
  • %
  • sub
  • super
  • top
  • text-top
  • middle
  • bottom
  • text-bottom
  • inherit



css/style.css
  • * {
  •  padding: 0;
  •  margin: 0;
  • }
  •  
  • body {
  •  background-color: #FFF5EE;
  • }
  •  
  • .main {
  •  width: 900px;
  •  height: 500px;
  •  position: absolute;
  •  left: 50%;
  •  top: 50%;
  •  margin-left: -450px;
  •  margin-top: -250px;
  • }
  •  
  • .left, .right {
  •  width: 270px;
  •  height: 500px;
  •  float: left;
  •  border: 1px solid #478E8E;
  •  background-color: #FFF;
  • }
  •  
  • .center {
  •  width: 270px;
  •  height: 500px;
  •  float: left;
  •  border: 1px solid #478E8E;
  •  background-color: #FFF;
  •  display: table;
  • }
  •  
  • .empty {
  •  width: 42px;
  •  height: 500px;
  •  float: left;
  • }
  •  
  • .a {
  •  vertical-align: top;
  • }
  •  
  • .c {
  •  vertical-align: top;
  •  display: table-cell;
  • }
  •  
  • .d {
  •  vertical-align: middle;
  •  display: table-cell;
  • }
  •  
  • .e {
  •  vertical-align: bottom;
  •  display: table-cell;
  • }
  •  
  • .f {
  •  vertical-align: super;
  •  background-color: #FFD700;
  • }
  •  
  • .g {
  •  vertical-align: sub;
  •  background-color: #FFD700;
  • }
  •  
  • .h {
  •  vertical-align: 100px;
  •  background-color: #9ACD32;
  • }
  •  
  • .k {
  •  vertical-align: -100px;
  •  background-color: #9ACD32;
  • }
* {
 padding: 0;
 margin: 0;
}

body {
 background-color: #FFF5EE;
}

.main {
 width: 900px;
 height: 500px;
 position: absolute;
 left: 50%;
 top: 50%;
 margin-left: -450px;
 margin-top: -250px;
}

.left, .right {
 width: 270px;
 height: 500px;
 float: left;
 border: 1px solid #478E8E;
 background-color: #FFF;
}

.center {
 width: 270px;
 height: 500px;
 float: left;
 border: 1px solid #478E8E;
 background-color: #FFF;
 display: table;
}

.empty {
 width: 42px;
 height: 500px;
 float: left;
}

.a {
 vertical-align: top;
}

.c {
 vertical-align: top;
 display: table-cell;
}

.d {
 vertical-align: middle;
 display: table-cell;
}

.e {
 vertical-align: bottom;
 display: table-cell;
}

.f {
 vertical-align: super;
 background-color: #FFD700;
}

.g {
 vertical-align: sub;
 background-color: #FFD700;
}

.h {
 vertical-align: 100px;
 background-color: #9ACD32;
}

.k {
 vertical-align: -100px;
 background-color: #9ACD32;
}


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <link href="css/style.css" rel="stylesheet" />
  •  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  • </head>
  • <body>
  •  <div class="main">
  •   <div class="left">
  •    <p class="a">Hello World! - top</p>
  •    <p id="p1">Hello World! - middle</p>
  •    <p class="b">Hello World! - bottom</p>
  •   </div>
  •   <div class="empty"></div>
  •   <div class="center">
  •    <!--<p class="c">Hello World! - top</p>-->
  •    <p class="d">Hello World! - middle</p>
  •    <!--<p class="e">Hello World! - bottom</p>-->
  •   </div>
  •   <div class="empty"></div>
  •   <div class="right">
  •    <p>Hello <span class="f">World!</span>  super</p>
  •    <p>Hello <span class="g">World!</span>  sub</p>
  •    <p>Hello <span class="h">World!</span>  100px</p>
  •    <p>Hello <span class="k">World!</span>  -100px</p>
  •   </div>
  •  </div>
  • <script>
  •  /*JavaScript*/
  •  document.getElementById("p1").style.verticalAlign = "middle";
  •  /*jQuery*/
  •  $(document).ready(function () {
  •   $(".b").css({ "vertical-align": "bottom" });
  •  });
  • </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <link href="css/style.css" rel="stylesheet" />
  •  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  • </head>
  • <body>
  •  <div class="main">
  •   <div class="left">
  •    <p class="a">Hello World! - top</p>
  •    <p id="p1">Hello World! - middle</p>
  •    <p class="b">Hello World! - bottom</p>
  •   </div>
  •   <div class="empty"></div>
  •   <div class="center">
  •    <!--<p class="c">Hello World! - top</p>-->
  •    <p class="d">Hello World! - middle</p>
  •    <!--<p class="e">Hello World! - bottom</p>-->
  •   </div>
  •   <div class="empty"></div>
  •   <div class="right">
  •    <p>Hello <span class="f">World!</span>  super</p>
  •    <p>Hello <span class="g">World!</span>  sub</p>
  •    <p>Hello <span class="h">World!</span>  100px</p>
  •    <p>Hello <span class="k">World!</span>  -100px</p>
  •   </div>
  •  </div>
  • <script>
  •  /*JavaScript*/
  •  document.getElementById("p1").style.verticalAlign = "middle";
  •  /*jQuery*/
  •  $(document).ready(function () {
  •   $(".b").css({ "vertical-align": "bottom" });
  •  });
  • </script>
  • </body>
  • </html>