我正在尝试显示两个表单按钮(每个都属于一个单独的表单)内联和居中(水平)。
这是我的代码:
<div>
<?php
if(($id && $upperConvLim) || ($id && !$upperConvLim && !$lowerConvLim)){
?>
<span> </span>
<form method="post" action="index.php" class="previous">
<input type="submit" value="Previous" name="submit1" />
<?php echo '<input type = "hidden" value="'.$id.'"name = "id" />'; ?>
<?php echo '<input type = "hidden" value="'.$previous.'"name = "previous" />'; ? >
</form>
<?php
}
if(($id && $lowerConvLim) || ($id && !$upperConvLim && !$lowerConvLim)){
?>
<span> </span>
<form method="post" action="index.php" class="next">
<input type="submit" value="Next" name="submit2" />
<?php echo '<input type = "hidden" value="'.$id.'"name = "id" />'; ?>
<?php echo '<input type = "hidden" value="'.$next.'"name = "next" />'; ?>
</form>
<?php
}
?>
</div>
我尝试在我的 CSS 中使用以下内容内联它们,
form, form div {
display: inline-block;
}
这工作正常,但我无法将两个按钮居中。我想知道1)如何使两个按钮居中以及2)是否有更好的方法来内联它们。欣赏它。
编辑:按照 Cynthia 的建议,我将 php/html 代码更改为,
<div class="center-form">
<?php
if(($id && $upperConvLim) || ($id && !$upperConvLim && !$lowerConvLim)){
?>
<span> </span>
<form method="post" action="index.php" class="hform">
<input type="submit" value="Previous" name="submit1" />
<?php echo '<input type = "hidden" value="'.$id.'"name = "id" />'; ?>
<?php echo '<input type = "hidden" value="'.$previous.'"name = "previous" />'; ?>
</form>
<?php
}
if(($id && $lowerConvLim) || ($id && !$upperConvLim && !$lowerConvLim)){
?>
<span> </span>
<form method="post" action="index.php" class="hform">
<input type="submit" value="Next" name="submit2" />
<?php echo '<input type = "hidden" value="'.$id.'"name = "id" />'; ?>
<?php echo '<input type = "hidden" value="'.$next.'"name = "next" />'; ?>
</form>
<?php
}
?>
</div>
还有我的新 CSS:
table {
font-family: Verdana;
font-size: 10pt
}
#table4 {
margin-left: auto;
margin-right: auto;
border:1px solid black;
width :70%;
padding:10px;
background-color:#FAFAD2;
}
#table3 {
margin-left: auto;
margin-right: auto;
border:1px solid black;
width :60%;
padding:10px;
background-color:#FFDAB9;
}
/*
form, form div {
display: inline-block;
text-align: center;
}
*/
.center-form { display:block ; width:165px ; margin:auto }
form.hform { display:inline }
input[type=submit] { padding:4px 0 ; width:80px }
谢谢!