如何将元素的对齐设置为与css对齐?

时间:2015-11-23 08:58:59

标签: html css3

我尝试将存在于div标签中的元素的对齐设置为暗类到居中。我有一个图像和一个带有img-circle类的div元素,大多数位于中心(垂直,水平)。请指教。
参见

上的演示
  

http://jsfiddle.net/hmahdavi921/94nfxyz8/

的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>

做到了。没问题

2 个答案:

答案 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%;}

<强>演示

&#13;
&#13;
.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;
&#13;
&#13;

================================

更新了演示

&#13;
&#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;
&#13;
&#13;

答案 1 :(得分:0)

将暗级顶部更改为60%

CSS:

.dark{ top: 60%; }

保证金 - 左图为40px图像

CSS:

.img-responsive{ margin-left: 40px; }

.img-responsive{ margin-left: 7%; }

enter image description here