Demo
年月日
PHP&CSS
<div class="php_bir_select3">
<?php
// 使用している変数名
// $d, $this_year, $start_year, $birth_year, $birth_month, $birth_day, $i
$d = date_create();
$this_year = date_format($d, "Y");
$start_year = $this_year - 100;
$birth_year = $birth_month = $birth_day = "<option value=\"\">--</option>";
for($i = $start_year; $i <= $this_year; $i++){
$birth_year .= "<option value=\"{$i}\">{$i}</option>";
}
for($i = 1; $i <= 12; $i++){
$i = sprintf('%02d', $i);
$birth_month .= "<option value=\"{$i}\">{$i}</option>";
}
for($i = 1; $i <= 31; $i++){
$i = sprintf('%02d', $i);
$birth_day .= "<option value=\"{$i}\">{$i}</option>";
}
echo "<select name=\"birth_year\">{$birth_year}</select>年<select name=\"birth_month\">{$birth_month}</select>月<select name=\"birth_day\">{$birth_day}</select>日";
?>
</div>
.php_bir_select3 select{
width: 4rem;
outline: none;
padding: 0.3rem 0;
margin: 0 0.2rem 0 0.5rem;
border: 1px solid #ccc;
}
.php_bir_select3 select:first-child{
margin-left: 0rem;
}