[英]How to align two elements on the same line from PHP
我想将两个$elements
对齐以显示在同一行上。
<span class="max">
<?php echo $tickets_sold, $max_tickets; ?>
</span>
当$tickets_sold
不包括在内, $max_tickets
那张上面。 但是当它被包括在内时,它立即进入下一行。
我尝试了许多不同的选项作为&&,但是,它们从未出现在同一行。 我确信解决方案很简单,但我是初学者。
$max_tickets = $product->get_max_tickets();
$tickets_sold = wc_get_stock_html( $product );
PHP代码
<div class="wcl-progress-meter <?php if($product->is_max_tickets_met()) echo 'full' ?>">
<progress max="<?php echo $max_tickets ?>" value="<?php echo $lottery_participants_count ?>" low="<?php echo $min_tickets ?>"></progress></br>
<span class="zero">0 </span>
<span class="max"> <?php echo $tickets_sold, $max_tickets?></div></span>
</div>
CSS文件
.wcl-progress-meter meter::-webkit-meter-suboptimum-value {
box-shadow: 0 5px 5px -5px #999 inset;
background: #cb132b;
display:inline-block;
}
.wcl-progress-meter .zero {
display: inline-block;
position: absolute;
top: -100%;
}
.wcl-progress-meter .min {
display: inline-block;
position: absolute;
top: -100%;
}
.wcl-progress-meter .max {
display: inline-block;
position: absolute;
top: -100%;
right: 0;
vertical-align: middle;
}
只需稍微调整一下HTML,所有内容都应该按照您的意愿运行:
<style>
.flex-parent{display:flex;}
.flex-child{flex-basis:content;margin-right:10px;}
</style>
<div class="max flex-parent">
<div class="flex-child"><?php echo $tickets_sold;?></div>
<div class="flex-child"><?php echo $max_tickets;?></div>
</div>
<style> .flex-parent{display:flex;} .flex-child{flex-basis:content;margin-right:10px;} </style> <div class="max flex-parent"> <div class="flex-child">tickets_sold</div> <div class="flex-child">max_tickets</div> </div>
或者,您也可以使用display:inline:
<style>
.inline-block{display:inline-block;margin-right:10px;}
</style>
<div class="max">
<div class="inline-block"><?php echo $tickets_sold;?></div>
<div class="inline-block"><?php echo $max_tickets;?></div>
</div>
<style> .inline-block{display:inline-block;margin-right:10px;} </style> <div class="max"> <div class="inline-block">tickets_sold</div> <div class="inline-block">max_tickets</div> </div>
请注意对第一个示例代码的更改 - 我忽略了将flex-parent
类(我发明的className,而不是约定)添加到.max
div。
要将项目置于父项中心,请添加justify-content:center;
给父母:
<style>
.flex-parent{display:flex;}
.flex-child{flex-basis:content;margin-right:10px;justify-content:center;}
</style>
<div class="max flex-parent">
<div class="flex-child"><?php echo $tickets_sold;?></div>
<div class="flex-child"><?php echo $max_tickets;?></div>
</div>
使用display:inline-block
方法:
<style>
.inline-parent{text-align:center;}
.inline-block{display:inline-block;margin-right:10px;}
</style>
<div class="max inline-parent">
<div class="inline-block"><?php echo $tickets_sold;?></div>
<div class="inline-block"><?php echo $max_tickets;?></div>
</div>
<style> .inline-parent{text-align:center;} .inline-block{display:inline-block;margin-right:10px;} </style> <div class="max inline-parent"> <div class="inline-block">tickets_sold</div> <div class="inline-block">max_tickets</div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.