gpt4 book ai didi

css - CSS 中的相对定位在 Safari 和 Firefox 中完全不同?

转载 作者:太空宇宙 更新时间:2023-11-03 18:57:44 25 4
gpt4 key购买 nike

我是 CSS 的新手,一直在尝试创建一个单选按钮与文本字段对齐的 Web 表单。但是,在 Firefox 中,单选框看起来不错,但是当我在 Safari 中选中时,单选框位于文本字段的中间。

CSS 看起来像这样:

   input#answers
{
display: block;
height: 31px;
left: 87px;
position: relative;
top: 0px;
width: 350px;
}

input[type="radio"]
{
display: inline- block;
height: 20px;
left: 249px;
position: relative;
top: -30px;
vertical-align: middle;
}

HTML 是这样的:

    <form id="quizCreator" name="quizCreator" method="post" action="quiz.maker.php">
<label><span><img src="images/quizcreatorText.ques.png" hspace="79px" vspace="70px" class="titles" /></span> <br />
<input type="text" name="question" id="question" />
</label>
<label><img src="images/quizcreatorText.ans.png" hspace="79px" vspace="70px" class="titles" id="ans" /> <br />
<input type="hidden" name="creator" value="myform" />
<br />
<input type="text" name="answer1" id="answers" />
</label>
<label>
<input type="radio" name="radio" id="radio1" value="radio1" />
</label>

<label>
<input type="text" name="answer2" id="answers" />
</label>
<label>
<input type="radio" name="radio" id="radio3" value="radio2" />
</label>

<label>
<input type="text" name="answer3" id="answers" />
</label>
<label>
<input name="radio" type="radio" class="radio" id="radio3" value="radio3" />
</label>

<label>
<input type="text" name="answer4" id="answers" />
</label>
<label>
<input name="radio" type="radio" id="radio4" value="radio4" />
</label>
<span><input type="image" src="images/quiznameText.next.png" name="nextPage" id="nextPage" class="nxtbutton" /></span>
</form>

我试过使用相对定位和边距,但虽然它解决了 Safari 中的问题,但 Firefox 看起来不对。有没有办法用一组代码让它们都按我想要的方式工作? (那么 MSIE 呢?)

最佳答案

你不应该为此使用相对定位。

正确的结构是这样的(不确定你想要之前还是之后的文本):

<div class="answers">
<ul>
<li><label>your text</label><input type="radio" /></li>
...repeat...
</ul>
</div>

CSS:

.answers ul, .answers li {
list-style-type:none;
margin:0;
padding:0;
}

.answers li {
clear:both
}

.answers label {
display:block;
float:left;
width:100px;
}

.answers input {
display:block;
float:left;
}

关于css - CSS 中的相对定位在 Safari 和 Firefox 中完全不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13016187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com