我正在使用.total-center
的全局类来尝试将图像对齐bonus-left
的中心。由于某种原因,img超出了容器bonus-left
...
有没有人知道为什么我的图片不会在bonus-left
div中垂直居中?
.total-center {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 100%;
}
#review-bonus {
width: 99%;
border: 1px solid #CDCDCD;
background: #F7F7F7;
margin: 30px auto;
}
#review-bonus-inner {
padding: 20px;
}
#bonus-left,
#bonus-right {
display: inline-block;
}
#bonus-right {
width: 75%;
}
#bonus-left {
width: 25%;
position: relative;
}
#bonus-left img {
width: 60%;
height: auto;
display: block;
margin: 0 auto;
}
<div id="review-bonus">
<div id="review-bonus-inner">
<div id="bonus-left">
<div class="total-center"><img src="http://www.iconarchive.com/download/i60915/himacchi/sweetbox/gift.ico"></div>
</div><div id="bonus-right">
<h3 id="bonus-title">FREE</h3>
<p id="bonus-description">f jdkl fnjfn rweofnrfnfndafndffn ddfd fdhfanjk herowf fhrgfndfndf wfefnanf fefnf f hqaf hef fewh f hfewanf f aWFH F HWEEFNDNADS ANDJFDNF E </p>
<ul>
<li>g erj iroehgnvfd f nvjvhrnvjf nevj nvonvrfvnfvn envdvn nfereonovfnjofnvf oegnpvnfdonvfognoa</li>
<li>fndj iofgh rionrn ;nn oej rejbnvofn noe revofnoa;gvan</li>
<li>h trhth thwgh 4t ththhthtw th aregtrhw</li>
<li>htr htrh twh htrh thth twhtr hwht w</li>
<li>grtg regh htrw hthtthwhth tr th twhw hhttwhtrh w h</li>
</ul>
</div>
</div>
</div>
答案 0 :(得分:1)
要了解我的调整,您需要了解有关CSS和HTML的一些事项:
var inputString = "sum(a) / nullif(sum(b)::numeric, 0)"
var strToReplace = inputString.match(/sum\([\w]\)/g); /*Find all of type sum()*/
/*Convert get the variable to be replaced for sum(some word)*/
var varToReplace = strToReplace.map(function(item){
var x = item.replace(/sum\(/,''); x = x.replace(/\)/,'');return x; })
/*Replace the string*/
strToReplace.forEach(function(item,index){
var re = new RegExp(escapeRegExp(item));
inputString = inputString.replace(re,varToReplace[index]);
})
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
&#13;
#review-bonus {
width: 100%;
border: 1px solid #CDCDCD;
background: #F7F7F7;
margin: 30px auto;
}
#review-bonus-inner {
padding: 20px;
}
#bonus-left,
#bonus-right {
display: inline-block;
vertical-align: middle;
}
#bonus-right {
width: 75%;
}
#bonus-left {
width: 25%;
}
#bonus-left img {
width: 100%;
}
&#13;
答案 1 :(得分:0)
在奖金左侧和奖励右侧添加垂直对齐将解决此问题
#bonus-left,
#bonus-right {
vertical-align: middle;
display: inline-block;
}
您可能还想在图片上添加最大宽度。在宽屏幕上它会太大而且溢出。
答案 2 :(得分:0)
添加垂直对齐:顶部到#bonus-right将解决您的问题
#bonus-left {
width: 25%;
vertical-align: top;
position: relative;
}
试试这个