英文:
Align radio buttons on left side of the page
问题
I am working on a personal project and I don't know how to align these radio buttons with the above text of each other.
My current situation is this...
I would like to achieve this other...
This is my 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>
And this is 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;
}
Potentially, all buttons should be aligned with the first character of the longest question.
英文:
I am working on a personal project and I don't know how to align these radio buttons with the above text of eachother.
My current situation is this...
I would like to achieve this other...
This is my 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>
And this is 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;
}
Potentially, all buttons should be aligned with the first character of the longest question.
答案1
得分: 1
你需要将 text-align: center;
更改为 text-align: left;
,这导致了单选按钮居中,但如果你将其更改为 text-align: left;
,它们就会向左移动。
更新后的代码如下:
.site-title {
text-align: left;
}
body {
text-align: left;
}
form {
text-align: left;
}
input[type="radio"] {
align-items: flex-start;
}
footer {
text-align: center;
}
.card-title {
text-align: left;
}
英文:
You need to change the text-align: center;
to text-align: left;
this was causing the radio buttons to be centered, but if you change it to text-align: left;
they will go left.
The updated code is
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.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;
}
<!-- language: lang-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; 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>
<!-- end snippet -->
答案2
得分: 0
如果我理解正确,您希望您的调查问卷位于左侧,但您设置了 text-align: center;
来使包括这些调查问卷的 ol
标签居中对齐。
因此,您希望将其移到左侧,您需要在您的 div 中声明 text-align: left;
。
<form action='/risultati' method='POST'>
<ol style="text-align: left; list-style-position: inside;margin-left: 0;padding-left: 0;">
{% for i in q %}<br/>
<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>
英文:
If my understanding is correct you want your questionnaire to be on left, but you set text-align: center;
of your ol
tag that includes these questionnaire so that all it's aligned center.
Therefore, you want to make it to the left side, you need to declare text-align: left;
in your div.
<!-- begin snippet: js hide: true console: true babel: false -->
<!-- language: lang-css -->
.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;
}
<!-- language: lang-html -->
<form action='/risultati' method='POST'>
<ol style="text-align: center; list-style-position: inside;margin-left: 0;padding-left: 0;">
{% for i in q %}<br/>
<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>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论