简体   繁体   English

垂直对齐的表格和表格单元:中间

[英]Table and Table-cell with vertical-align: middle

Table and Table-cell doesn't work. 表格和表格单元格不起作用。 I took table's height 100% and table-cell auto. 我将桌子的高度设为100%,将表格单元格设为自动。 Then I try to set the table-cell in vertical-align middle with 100% width but doesn't work. 然后,我尝试将表格单元格设置为垂直对齐的中间,宽度为100%,但不起作用。 What is the wrong of my code? 我的代码有什么问题?

Live Preview: http://designer.com.bd/foysal/ 实时预览: http//designer.com.bd/foysal/

The code: 编码:

 /*Roboto Fonts*/ @import url(https://fonts.googleapis.com/css?family=Roboto:400,500,300,700,700italic,500italic,400italic,300italic); /*PlayFairDisplay Fonts*/ @import url(https://fonts.googleapis.com/css?family=Playfair+Display:400,400italic,700,700italic,900,900italic); /*UNIVERSAL CODE*/ * {margin: 0;padding: 0;} ul {margin: 0;padding: 0;list-style-type: none;} h1,h2,h3,h4,h5,h6 {margin: 0;padding: 0; font-family: 'Playfair Display', serif;margin: 0 0 15px; font-weight : 700} body {font-family: 'Roboto', sans-serif; font-size: 14px;} .alignleft {float:left; margin-right: 15px} .alignright {float:right; margin-left: 15px;} .aligncenter {display: block; margin: 0 auto 15px;} img {max-width: 100%; height: auto;} html, body {height: 100%} a:hover {text-decoration: none;} a:focus {text-decoration: none;outline: 0 solid} a:visited {text-decoration: none;} /*Remove chrome Input Field's Unwanted Yellow Background Color*/ input: -webkit-autofill, input: -webkit-autofill:hover, input: -webkit-autofill:focus {-webkit-box-shadow: 0 0 0 100px white inset !important;} /***********************************************/ .welcome-hero-area, .welcome-slider-area, .welcome-slider-area div { height: 100%; } .welcome-hero-area div.slide-item-tablecell, .welcome-hero-area div.slide-item-tablecell div { height: auto; } .slide-item-tablecell { display: table-cell; vertical-align: middle; width: 100%; } .slide-item-table { display: table; } 
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <title>Title goes to here</title> <!-- Google Fonts--> <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/font-awesome.min.css"> <!-- Bootstrap --> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet"> <link href="css/responsive.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <!--Starting Header with Welcome area--> <div class="welcome-hero-area"> <!--<div class="header_area"> <div class="container"> <div class="row"> <div class="col-md-4"> <div class="logo"> <a href="#"><img src="img/logo.png" alt="logo"></a> </div> </div> <div class="col-md-8"> <div class="mainmenu"> <ul> <li><a href="#">HOME</a></li> <li><a href="#">ABOUT</a></li> <li><a href="#">EXPERTISE</a></li> <li><a href="#">TEAMS</a></li> <li><a href="#">WORKS</a></li> <li><a href="#">PEOPLE SAY</a></li> <li><a href="#">CONTACT</a></li> </ul> </div> </div> </div> <!--end of row--> <!--</div> <!--end of container--> <!--</div> <!--end of header area --> <!--Starting Slider Area--> <div class="welcome-slider-area"> <div id="welcome-slide-carousel" class="carousel slide" data-interval="5000000" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#welcome-slide-carouse" data-slide-to="0" class="active"></li> <li data-target="#welcome-slide-carouse" data-slide-to="1"></li> <li data-target="#welcome-slide-carouse" data-slide-to="2"></li> <li data-target="#welcome-slide-carouse" data-slide-to="3"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner" role="listbox"> <div class="item active"> <!--1st img--> <div class="single-slide-item slide-1"> <div class="slide-item-table"> <div class="slide-item-tablecell"> <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <h2>We Are Awesome Creative Agency</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas voluptatibus animi atque at! Ad modi voluptatem, velit, officia eligendi nesciunt dolore nobis laborum repellendus sapiente, maiores magni odit. Temporibus, sit.</p> <a class="slide-btn" href="#">Learn More</a> </div> </div> </div> </div> </div> </div> </div> <div class="item"> <!--2nd img--> <div class="single-slide-item slide-2"> <div class="slide-item-table"> <div class="slide-item-tablecell"> <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <h2>We Are Awesome Creative Agency</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas voluptatibus animi atque at! Ad modi voluptatem, velit, officia eligendi nesciunt dolore nobis laborum repellendus sapiente, maiores magni odit. Temporibus, sit.</p> <a class="slide-btn" href="#">Learn More</a> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <!--end of welcome slider area--> </div> <!--end of welcome hero area--> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/bootstrap.min.js"></script> <!-- Custom JavaScript--> <script src="js/main.js"></script> </body> </html> <!--Today's Learn 21 May 2016 ----------- * giving css value to all div and child: Suppose, you've a div with calss of container and under the container you've another 4 div with calass name of them are: <div class="container"> <div class="1"> <div class="2"> <div class="3"> <div class="4"> </div> </div> </div> </div> </div> Now hoy you give to all div's css value which are same you have 2 ways 1 put css property and value separtly. or you can put css value all in one time if you have same css property and value. So how? then select the parrent div like .container div { height:100%; } In this code mention all of your div as a child and giving css. ----------- *Table and Tablecell rules: if you want to use table and tablecell for making content to center which is up or down/ left or right firstly you need to make 100% height for all div if the table and tablecell are child div then only tablecell need to height auto. --> 

.welcome-slider-area div {
    height: 100%;
}

This made your all div in .welcome-slider-area , try to set height to the children of .slide-item-tablecell div. 这使您在.welcome-slider-area所有div都尝试为.slide-item-tablecell div的子级设置高度。

<div class="container" style="height: 100px;">
    <!-- content -->
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM