我尝试将存在于div标签中的元素的对齐设置为暗类到居中。我有一个图像和一个带有img-circle类的div元素,大多数位于中心(垂直,水平)。请指教。
参见
的CSS:
.img-circle img {
top: 50%;
left: 50%;
border: 6px solid #b9b7b7;
-ms-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
-ms-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
}
.dark {
position: relative;
z-index: 2;
overflow: hidden;
}
div.dark:after {
position: absolute;
content: '';
top: 50%;
left: 50%;
height: 100%;
width: 100%;
-ms-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
-ms-box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
-webkit-transition: all 0.4s;
-moz-transition: all 0.4s;
-ms-transition: all 0.4s;
-o-transition: all 0.4s;
transition: all 0.4s;
}
div.dark:hover:after {
height: 0%;
width: 0%;
}
HTML:
<div class="dark img-circle">
<div>
<div id="dnn_ctr428_ContentPane" class="img-circle">
<h3>نام من</h3>
<p>توضیحات من </p>
<button class="btn btn-primary">بیشتر ...</button>
<!-- Start_Module_428 --><div id="dnn_ctr428_ModuleContent" class="DNNModuleContent ModDNNHTMLC">
<div id="dnn_ctr428_HtmlModule_lblContent" class="Normal">
<img class="img-responsive" alt="" src="http://www.dnnskin.net/portals/631/team3.png" height="279" width="446">
</div>
</div><!-- End_Module_428 --></div>
</div>
</div>
如果您需要更改此标签的位置
<h3>نام من</h3>
<p>توضیحات من </p>
<button class="btn btn-primary">بیشتر ...</button>
做到了。没问题
答案 0 :(得分:1)
现在已经习惯了这个css。
.Normal{
position:absolute;
left:0;right:0;top:50%;margin-top:-145px;bottom:0;text-align:center;
}
html body, html, .dark{height:100%;}
<强>演示强>
.Normal{
position:absolute;
left:0;right:0;top:50%;margin-top:-145px;bottom:0;text-align:center;
}
html body, html{height:100%;}
.img-circle img {
border: 6px solid #b9b7b7;
-ms-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
-ms-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
}
.dark {
position: relative;
z-index: 2;
overflow: hidden;
height:100%;
}
div.dark:after {
position: absolute;
content: '';
top: 50%;
left: 50%;
height: 100%;
width: 100%;
-ms-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
-ms-box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
-webkit-transition: all 0.4s;
-moz-transition: all 0.4s;
-ms-transition: all 0.4s;
-o-transition: all 0.4s;
transition: all 0.4s;
}
div.dark:hover:after {
height: 0%;
width: 0%;
}
&#13;
<div class="dark img-circle">
<div>
<div id="dnn_ctr428_ContentPane" class="img-circle">
<h3>نام من</h3>
<p>توضیحات من </p>
<button class="btn btn-primary">بیشتر ...</button>
<!-- Start_Module_428 --><div id="dnn_ctr428_ModuleContent" class="DNNModuleContent ModDNNHTMLC">
<div id="dnn_ctr428_HtmlModule_lblContent" class="Normal">
<img class="img-responsive" alt="" src="http://www.dnnskin.net/portals/631/team3.png" height="279" width="446">
</div>
</div><!-- End_Module_428 --></div>
</div>
</div>
&#13;
更新了演示
.Normal, .imgText{
position:absolute;
left:0;right:0;top:50%;margin-top:-145px;bottom:0;text-align:center;
}
.imgText{
z-index:9;top:50%;margin-top:-57px;
}
html body, html{height:100%;}
.img-circle img {
border: 6px solid #b9b7b7;
-ms-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
-ms-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
}
.dark {
position: relative;
z-index: 2;
overflow: hidden;
height:100%;
}
div.dark:after {
position: absolute;
content: '';
top: 50%;
left: 50%;
height: 100%;
width: 100%;
-ms-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
-ms-box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 0px 200px rgba(0, 0, 0, 0.3);
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
-webkit-transition: all 0.4s;
-moz-transition: all 0.4s;
-ms-transition: all 0.4s;
-o-transition: all 0.4s;
transition: all 0.4s;
}
div.dark:hover:after {
height: 0%;
width: 0%;
}
&#13;
<div class="dark img-circle">
<div>
<div id="dnn_ctr428_ContentPane" class="img-circle">
<!-- Start_Module_428 -->
<div id="dnn_ctr428_ModuleContent" class="DNNModuleContent ModDNNHTMLC">
<div class="imgText">
<h3>نام من</h3>
<p>توضیحات من </p>
<button class="btn btn-primary">بیشتر ...</button>
</div>
<div id="dnn_ctr428_HtmlModule_lblContent" class="Normal">
<img class="img-responsive" alt="" src="http://www.dnnskin.net/portals/631/team3.png" height="279" width="446" />
</div>
</div><!-- End_Module_428 -->
</div>
</div>
</div>
&#13;
答案 1 :(得分:0)