如何对准DIV内的单选按钮?

时间:2014-11-26 19:42:17

标签: php html css html5 css3

有人可以指导我正确的方向或告诉我我的CSS做错了吗?我想让我的单选按钮在DIV内水平对齐。

我想要的是什么:

|------(*)------|------|
1d     1w     1m     3m
提前谢谢。 here is my fiddle了解它现在的样子

map.php

<div id="menu_option">
        <h1>Menu Option</h1>
            <div id="button_position">


        <div id="date_selector">    
            <label>Select Date Range</label>
        <form action="show_aht2.php" method="post">
                    <input type="radio" name="date_selected" value="1d" checked="checked"/>1d
                    <input type="radio" name="date_selected" value="1w" />1w
                    <input type="radio" name="date_selected" value="1m" />1m
                    <input type="radio" name="date_selected" value="3m" />3m
                    <input type="submit" name="get_aht" value="Get AHT" />
        </form>
</div><!--date selector-->

                <div class="clear"></div> 

            </div><!--button position-->
    </div><!-- end menu_option div-->

CSS:

/*menu bar option*/
#menu_option{
width:200px;
height:600px;
background:#0099FF;
border-style: solid;
border-color: black;
position: relative;
float:right;
overflow:hidden;
text-align:center; 
}

input[type="radio"] {
margin-left:10px;
}

#date_selector{
border:3px;
border-color:black;
}

#button_position{
width: 150px;
height: 80px
position: absolute;
}

#button_position button{
font-weigth:bold;    
font-size:1.3em;
}

4 个答案:

答案 0 :(得分:1)

您的问题可能是您错误地使用isset()。正如您现在所做的那样,第一个if语句将始终引发错误。

isset( $_POST['date_selected'] === "1d" )

将其分解,你有一个比较语句,其结果总是一个布尔值。然后将其作为参数传递给isset()函数。然后isset会引发错误,因为它不知道如何处理标量值。

至于水平对齐CSS按钮,请查看此other question

答案 1 :(得分:0)

在第6行的小提琴中,我没有看到任何方法。

你把&#39;方法=&#34;&#34;&#39;。正确的是&#39;方法=&#34; post&#34;&#39;

答案 2 :(得分:0)

我总是使用它,请阅读此内容。我发现这是一个很好的做法

if($_SERVER['REQUEST_METHOD'] == 'POST'){
     //Do the thing
}

答案 3 :(得分:0)

那么有很多方法可以将这些数据发送到PHP,我的可能不太实用,但也许有些东西可以提供帮助。如果您希望对发送到PHP文件的数据进行大量控制,您可以通过javascript发送它并使用$ GET从PHP文件中读取它。我制作了一个复制和粘贴示例html文件,您可以在与PHP文件相同的目录中运行它,它应该通过少量编辑产生您要查找的结果。我喜欢这种方法只是因为它甚至可以在将数据发送到PHP文件之前控制数据,从而使PHP文件的编码更小。 (从理论上讲,这种方法可以提高性能!^ ^)

<html>
<body>
<div id="date_selector">        
<input type="radio" name="date_selected" value="1d" checked="checked"/>1d<br/>
<input type="radio" name="date_selected" value="1w" />1w<br />
<input type="radio" name="date_selected" value="1m" />1m<br />
<input type="radio" name="date_selected" value="3m" />3m<br />
<button onclick="sendRadios()">Get AHT</button>
<div id="test"></div>
<script>
function sendRadios() {
var a = document.getElementsByTagName("input");
var i = a.length - 1;
while (i != -1) {
if (a[i].checked == true) {
var rVal = a[i].value;
window.location.href = "./show_aht2.php?date_selected=" + rVal;
}
i = i - 1;
}
}
</script>
</div>
</body>
</html>

基本上,上面的代码是如何通过Javascript将网页上的数据发送到PHP。

P.S。如果使用此更改您的$ _POST到$ _GET