我正在做一个个人项目,我不知道如何将这些单选按钮与上面的文本对齐.

My current situation is this... example

I would like to achieve this other... would_like_2

这是我的HTML码:

<!doctype html>
<html lang="en">

<head>
    <title>Simulatore Quiz AREU</title>
</head>
<form action='/risultati' method='POST'>
    <ol style="text-align: center; list-style-position: inside">
        {% for i in q %}<br/>
            <div>
                <li>{{ i }}</li>
                    {% for j in o[i] %}
                        <div>
                            <label>
                                <input type='radio' value='{{ j }}' name='{{ i }}' required/>
                            </label>{{ j }}<br/>
                        </div>
                    {%- endfor %}
                </div>
            {%- endfor %}
        </ol>
        <button type="submit" name="submit_button"> Finisci Test</button>
    </form>
</html>

这是css:

/* https://www.bootdey.com/snippets/view/microsoft-metro-tiles-bootstrap#html */

.site-title {
    margin-top: 2rem;
    margin-bottom: 3.5rem;
    font-weight: 500;
    line-height: 1.2;
    color: black;
    text-align: center;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    text-align: center;
}

form {
    margin: 10px;
    width: 1200px;
    text-overflow: ellipsis;
    display: contents;
}

input[type="radio"] {
    margin-right: 5px;
    align-items: flex-start;
}

form button[type="submit"] {
    margin-top: 30px;
    position: relative;
    overflow: hidden;
    background-color: #d00000;
    color: white;
    border: 0;
    padding: 1.5em 0.7em;
}

footer {
    margin-top: auto;
    text-align: center;
}


p, span, a, ul, li, button {
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
}

strong {
    font-weight: 600;
}

h1, h2, h3, h4, h5 {
    font-family: 'Open Sans', "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serify, serif;
    line-height: 1.5em;
    font-weight: 300;
}

.card-tile {
    width: 100%;
    display: inline-block;
    box-sizing: border-box;
    background: #fff;
    padding: 20px;
    margin-bottom: 30px;
}

.card-title {
    margin-top: 0;
    text-align: center;
}

.purple, .blue, .red, .orange, .green {
    color: #fff;
}

.red {
    background: #d00000;
}

所有按钮可能都应该与最长问题的第一个字符对齐.

推荐答案

您需要将text-align: center;更改为text-align: left;这会导致单选按钮居中,但如果您将其更改为text-align: left;,单选按钮将向左移动.

更新后的代码是

.site-title {
        margin-top: 2rem;
        margin-bottom: 3.5rem;
        font-weight: 500;
        line-height: 1.2;
        color: black;
        text-align: left;
    }

    body {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        text-align: left;
    }

    form {
        margin: 10px;
        width: 1200px;
        text-overflow: ellipsis;
        display: contents;
    }

    input[type="radio"] {
        margin-right: 5px;
        align-items: flex-start;
    }

    form button[type="submit"] {
        margin-top: 30px;
        position: relative;
        overflow: hidden;
        background-color: #d00000;
        color: white;
        border: 0;
        padding: 1.5em 0.7em;
    }

    footer {
        margin-top: auto;
        text-align: center;
    }


    p, span, a, ul, li, button {
        font-family: inherit;
        font-size: inherit;
        font-weight: inherit;
        line-height: inherit;
    }

    strong {
        font-weight: 600;
    }

    h1, h2, h3, h4, h5 {
        font-family: 'Open Sans', "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serify, serif;
        line-height: 1.5em;
        font-weight: 300;
    }

    .card-tile {
        width: 100%;
        display: inline-block;
        box-sizing: border-box;
        background: #fff;
        padding: 20px;
        margin-bottom: 30px;
    }

    .card-title {
        margin-top: 0;
        text-align: left;
    }

    .purple, .blue, .red, .orange, .green {
        color: #fff;
    }

    .red {
        background: #d00000;
    }
<!doctype html>
    <html lang="en">

    <head>
        <title>Simulatore Quiz AREU</title>
    </head>
    <form action='/risultati' method='POST'>
        <ol style="text-align: center; list-style-position: inside; padding-left: 200px;">
            <div style="text-align: left;">{% for i in q %}<div>
                <div style="text-align: left;">
                    <li>{{ i }}</li>
                        {% for j in o[i] %}
                            <div>
                                <label>
                                    <input type='radio' value='{{ j }}' name='{{ i }}' required/>
                                </label>{{ j }}<br/>
                            </div>
                        {%- endfor %}
                    </div>
                {%- endfor %}
            </ol>
            <button type="submit" name="submit_button"> Finisci Test</button>
        </form>
    </html>

Html相关问答推荐

Vue.js复选框对齐问题:在表格单元格中居中复选框

有没有一种方法可以用css和html在桌面上并排显示列,在移动设备上显示一个下方的列?

每次在视口中运行动画

如何在Vim中删除Html标签?

轨道上的居中范围滑块拇指(Webkit)

创建特定的CSS网格布局

如何使 CSS 网格项目像 Flexbox 项目一样匹配父级的高度

在 WooCommerce 存档产品类别描述上添加阅读更多/阅读更少按钮

在span中添加

为什么可滚动弹性项目需要 flex-basis: 0 ?

为什么即使我点击其他地方,我的 contenteditable="true" 也会被激活?

在HTML使用link标签导入外部CSS时出现元素link不允许使用尾斜杠错误

CSS 网格跨度行到所有行

在 iPhone 上分隔 HTML 邮箱输入中的多个邮箱条目

pandas `to_html()` - 如何只使特定的行有边框

如何在Bootstrap卡片底部添加波浪形状

在 SQL 中合并 HTML 表中的单元格

发光效果html动画

沿文本对齐双引号

粘性定位的子元素忽略父母的填充