你怎么能对齐单选按钮 [英] How could you align radio buttons

查看:74
本文介绍了你怎么能对齐单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写四个单选按钮的代码,希望它们居中对齐.html



Code that writes four radio buttons, would want them centre aligned on .html

public class ScanForWordsC {
    private static final Scanner INPUT = new Scanner(System.in);
    private static final String FILENAME = "F:/Android.html";

    public static void main(String[] args) throws FileNotFoundException {
        try (PrintStream output = new PrintStream(FILENAME)) {
            readFromUser(output);
        }
    }

    public static void readFromUser(PrintStream output) {
        String wordA = readLine("Word (a)");
        String wordB = readLine("Word (b)");
        String wordC = readLine("Word (c)");
        String wordD = readLine("Word (d)");
        String answer = readLine("Correct letter");

        output.println(radio("a", wordA, answer));
        output.println(radio("b", wordB, answer));
        output.println(radio("c", wordC, answer));
        output.println(radio("d", wordD, answer));
    }

    private static String readLine(String prompt) {
        System.out.print(prompt + ": ");
        return INPUT.nextLine();
    }

    private static String radio(String letter, String word, String answer) {
        String option = "(" + letter + ") " + word;
        String is = letter.equals(answer) ? "is" : "is not";

        return "<input type='radio' name='rbnNumber' value='You selected " 
                + option + " which " + is +  " the correct answer' />"
                + option + "<br/>";
    }
}





我的尝试:



java类,集合和java文档



What I have tried:

java classes, collections and java docs

推荐答案

您可以使用CSS在父级上设置文本对齐方式:

You could use CSS to set the text alignment on the parent:
text-align:center





例如:



For example:

<!DOCTYPE html>
<html>
<body style="text-align:center">
    <input type='radio'>First</input><br/>
    <input type='radio'>Second</input><br/>
    <input type='radio'>Third</input><br/>
</body>
</html>


这里的代码对齐两个单选按钮!但是其他的,有四个按钮对齐方式,css会增加更多的代码如果可以做表格对齐是好的



code here aligns two radio buttons !but others, is there way for four buttons alignment, css would increase more code if could do with table alignment is good

private static String radio(String letter, String word, String answer)
   {

       String option = "(" + letter + ") " + word;
       String is = letter.equals(answer) ? "is" : "is not";

       return "<html><table align = 'center'><tr><td>"
               + "<input type='radio' name='rbnNumber' value='You selected"
               + option + "which" + is + "the correct answer'/>"
               + option + "<br/>"
               + "</td></tr></html>";
   }


这篇关于你怎么能对齐单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆