显示完全垂直居中的内联元素

时间:2015-05-19 18:43:00

标签: css

我需要显示带有文件名,进度条和按钮的内联三个div。按钮始终关闭 - 低于其他按钮。如何将它们垂直对齐?

这里的小提琴:https://jsfiddle.net/chagrin/n4gfyq2v/

HTML:

<div class="ajax-file-upload-statusbar" style="width: 600px;">
    <div class="ajax-file-upload-filename">
        1). Untitled-1Very long name file.png
    </div>        
    <div class="ajax-file-upload-progress" style="">
        <div class="ajax-file-upload-bar ajax-file-upload-1432059821500" style="width: 100%;"></div>
    </div>
    <div class="ajax-file-upload-cancel" style="">
        Cancel
    </div>
</div>

CSS:

.ajax-file-upload-statusbar {
    border: 2px solid #eee;
    margin:auto;
    -moz-border-radius: 2px;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    padding: 0 5px;
    background:#f2f2f2;
    -webkit-box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.4);
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.4);
    display:block;
    vertical-align:middle;
}
.ajax-file-upload-statusbar:last-child {
    margin-bottom: 20px;
}
.ajax-file-upload-filename {
    font-family:'open_sanslight', Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #333;
    display:inline-block;
    width:200px;
    overflow:hidden;
    white-space:nowrap;
}
.ajax-file-upload-progress {
    margin: 2px 5px 0 5px;
    position: relative;
    width: 300px;
    display:inline-block;
    box-shadow: inset 0 -1px 1px rgba(196, 196, 196, 0.3);
}
.ajax-file-upload-bar {
    background: grey;
    width: 0;
    height: 16px;
    border-radius: 4px;
}
.ajax-file-upload-percent {
    position: absolute;
    display: inline-block;
    top: 3px;
    left: 48%;
}
.ajax-file-upload-cancel {
    background-color: #2d2f30;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    border-radius: 3px;
    margin: 0;
    display: inline-block;
    color: #fff;
    font-family:'open_sanslight', Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: normal;
    margin-bottom:2px;
    padding: 2px 5px;
    text-decoration: none;
    cursor: pointer;
}

1 个答案:

答案 0 :(得分:0)

display: inline-block添加vertical-align: middle

&#13;
&#13;
.ajax-file-upload-statusbar {
border: 2px solid #eee;
margin:auto;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
padding: 0 5px;
background:#f2f2f2;
 -webkit-box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.4);
 box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.4);
 display:block;
 vertical-align:middle;
}
.ajax-file-upload-statusbar > div{
    display: inline-block;
    vertical-align: middle;
}

.ajax-file-upload-statusbar:last-child {
	margin-bottom: 20px;
}
.ajax-file-upload-filename {
font-family: 'open_sanslight', Arial, Helvetica, sans-serif;
font-size: 10px;
color: #333;
display:inline-block;
  vertical-align: middle;   
width:200px;
overflow:hidden;
white-space:nowrap;
}
.ajax-file-upload-progress {
margin: 0 5px 0 5px;
position: relative;
width: 300px;
display:inline-block;
box-shadow: inset 0 -1px 1px rgba(196,196,196,0.3);
     vertical-align: middle;
}
.ajax-file-upload-bar {
background: grey;
width: 0;
height: 16px;
border-radius: 4px;
}
 
.ajax-file-upload-percent {
position: absolute;
display: inline-block;
top: 3px;
left: 48%;
}
.ajax-file-upload-red {
-moz-box-shadow: inset 0 39px 0 -24px #e67a73;
-webkit-box-shadow: inset 0 39px 0 -24px #e67a73;
box-shadow: inset 0 39px 0 -24px #e67a73;
background-color: #e4685d;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
display: inline-block;
color: #fff;
font-family: 'open_sanslight', Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
padding: 2px 10px;
line-height:16px;
margin-bottom:2px;
text-decoration: none;
text-shadow: 0 1px 0 #b23e35;
cursor: pointer;
}
.ajax-file-upload-green {
background-color: #2d2f30;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
margin: 0;
display: inline-block;
color: #fff;
font-family: 'open_sanslight', Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
margin-bottom:2px;
padding: 2px 5px;
text-decoration: none;
cursor: pointer;
}


.ajax-file-upload {
	font-family: 'open_sanslight', Arial, Helvetica, sans-serif;
	font-size:12px;
	text-transform:uppercase;
	cursor: pointer;
	display: table;
	height: 20px;
	padding: 5px;
	position: relative;
	border-radius: 5px;
	border: 1px solid #000;
	color: #f2f2f2;
	text-decoration: none;
	/*gradient*/
	background: #4c4c4c; /* Old browsers */
	background: -moz-linear-gradient(top,  #4d4d4d, #2f2f2f); /* FF3.6+ */
	background: -webkit-gradient(top,  #4d4d4d, #2f2f2f)); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top,  #4d4d4d, #2f2f2f); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top,  #4d4d4d, #2f2f2f); /* Opera 11.10+ */
	background: -ms-linear-gradient(top,  #4d4d4d, #2f2f2f); /* IE10+ */
	background: linear-gradient(top,  #4d4d4d, #2f2f2f); /* W3C */
}

.ajax-file-upload:hover,
.ajax-file-upload-green:hover {
	background: -moz-linear-gradient(top,  #5c5c5c, #4d4d4d); /* FF3.6+ */
	background: -webkit-gradient(top,  #5c5c5c, #4d4d4d)); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top,  #5c5c5c, #4d4d4d); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top,  #5c5c5c, #4d4d4d)); /* Opera 11.10+ */
	background: -ms-linear-gradient(top,  #5c5c5c, #4d4d4d); /* IE10+ */
	background: linear-gradient(top,  #5c5c5c, #4d4d4d); /* W3C */
}

.ajax-upload-dragdrop {
    border: 2px dashed #CCC;
    color: #DADCE3;
    text-align:center;
	margin:15px auto;
	-moz-border-radius: 4px;
	-webkit-border-radius: 4px;
	border-radius: 4px;
    padding: 9px;
	 -webkit-box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.4);
 	 box-shadow:inset 1px 1px 3px rgba(0, 0, 0, 0.4);
	 background: whitesmoke;
}

.ajax-upload-dragdrop span {
	font-family: 'open_sanslight', Arial, Helvetica, sans-serif;
	position: relative;
	margin-top: 25px;
}

.ajax-upload-dragdrop.state-hover
{ border: 2px dashed #333;
}

.ajax-file-upload-error {
    color: red;
}
&#13;
<div class="ajax-file-upload-statusbar" style="width: 600px;">
    <div class="ajax-file-upload-filename">1). Untitled-1Very long name file.png</div>
    <div class="ajax-file-upload-progress" style=""><div class="ajax-file-upload-bar ajax-file-upload-1432059821500" style="width: 100%;"></div>
    </div>
    <div class="ajax-file-upload-green" style="">Cancel</div>
</div>
&#13;
&#13;
&#13;