修复html和css代码

时间:2016-12-15 16:24:35

标签: html css

我想知道,为什么当我可以选择两个图像而不仅仅是一个。 (是图像而不是单选按钮)。例如,如果您尝试选择2个图像,则会显示这些图像,但我希望只能选择其中一个。

查看jsFiddle或查看下面的代码段:



* {
    margin: 0;
    padding: 0;
}
.main {
    position: relative;
    z-index: 10;
    padding-top: 60px;
    color: #999;
    width: 100%;
    min-height: calc(100vh - 60px);
}
.wrap{position:relative}
.wrap{width:100%;margin:0 auto;max-width:1024px;padding:0 16px}
.write {
    position: relative;
    max-width: 690px;
    padding: 40px 16px 70px;
}
.write-gender{
    text-align: center;
}
.write-gender {
    display: inline-block;
    width: 128px;
    height: 128px;
    margin: 0 10px;
    border: 5px solid transparent;
    border-radius: 100%;
}
.form__label, h6 {
    font-weight: 500;
    font-size: 14px;
    text-transform: uppercase;
}
.form__label, h4, h6 {
    line-height: 1.2em;
    margin-bottom: 20px;
}
h6 {
    display: block;
    font-size: 0.67em;
    -webkit-margin-before: 2.33em;
    -webkit-margin-after: 2.33em;
    -webkit-margin-start: 0px;
    -webkit-margin-end: 0px;
    font-weight: bold;
}
.write-title {
    text-align: center;
    margin-top: 18px;
    font-size: 13px;
    margin-bottom: 60px;
	position: relative;
    left: 235px;
}
.gender-selector input{
    -webkit-appearance:none;
    -moz-appearance:button;
    appearance:button;
    margin:0;
    padding:0;
}
.man{
    background-image:url(https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-512.png);
	border-color: #1f6ab0;
    position: relative;
    left: 400px;
    bottom: 80px;
	display: block;
    max-width: 100%;
}

.gender-selector:not(input:checked) input:active +.gen-sel{
    opacity: .6;
}

.gender-selector input:checked +.gen-sel{
    -webkit-filter: none;
    -moz-filter: none;
    filter: none;
}

.women{
    background-image:url(https://cdn1.iconfinder.com/data/icons/user-pictures/100/female1-512.png);
	border-color: #b24592;
    position: relative;
    left: 60px;
    top: 3px;
	display: block;
    max-width: 100%;
}

.gen-sel{
    cursor:pointer;
    display:inline-block;
    width:100px;
    height:70px;
    background-size:contain;
    background-repeat:no-repeat;
     -webkit-filter: brightness(1.8) grayscale(1) opacity(.7);
    -moz-filter: brightness(1.8) grayscale(1) opacity(.7);
    filter: brightness(1.8) grayscale(1) opacity(.7);
}
.gen-sel:hover{
    -webkit-filter: brightness(1.2) grayscale(.5) opacity(.9);
    -moz-filter:  brightness(1.2) grayscale(.5) opacity(.9);
    filter:  brightness(1.2) grayscale(.5) opacity(.9);
}

<main class="main ">
<div>
<div class="wrap write">	
<div class="write-gender">
<h6 class="write-title">Select gender</h6>
	<div class="gender-selector">
        <input id="gender" type="radio" name="gender" value="w" />
        <label class="gen-sel write-gender women" for="gender"></label>
        <input id="gender2" type="radio" name="gender2" value="m" />
        <label class="gen-sel write-gender man"for="gender2"></label>
    </div>
</div>
</div>
</div>
</main>
&#13;
&#13;
&#13;

另外,我想知道其他事情: - 我已经创建了一个数据库来存储这些信息。 id为&#34; gender&#34;,在输入的html代码中,我调用了一个带id的输入 - &gt;性别和其他输入id - &gt;在我的PHP代码上的gender2我通过使用这个来匹配id gender2和id性别 - &gt; &#34; $ gender2 =&amp; $性别; &#34;是正确的 ?

4 个答案:

答案 0 :(得分:1)

您的复选框需要具有相同的名称属性

<input id="gender" type="radio" name="gender" value="w" />
<label class="gen-sel write-gender women" for="gender"></label>
<input id="gender2" type="radio" name="gender" value="m" />
<label class="gen-sel write-gender man"for="gender2"></label>

答案 1 :(得分:1)

如果您使用单选按钮,请使用相同的name属性 - gender,例如:

<div class="gender-selector">
  <input id="gender" type="radio" name="gender" value="w" />
  <label class="gen-sel write-gender women" for="gender"></label>
  <input id="gender2" type="radio" name="gender" value="m" />
  <label class="gen-sel write-gender man"for="gender2"></label>
</div>

请查看下面的代码段或更新后的fiddle

* {
    margin: 0;
    padding: 0;
}
.main {
    position: relative;
    z-index: 10;
    padding-top: 60px;
    color: #999;
    width: 100%;
    min-height: calc(100vh - 60px);
}
.wrap{position:relative}
.wrap{width:100%;margin:0 auto;max-width:1024px;padding:0 16px}
.write {
    position: relative;
    max-width: 690px;
    padding: 40px 16px 70px;
}
.write-gender{
    text-align: center;
}
.write-gender {
    display: inline-block;
    width: 128px;
    height: 128px;
    margin: 0 10px;
    border: 5px solid transparent;
    border-radius: 100%;
}
.form__label, h6 {
    font-weight: 500;
    font-size: 14px;
    text-transform: uppercase;
}
.form__label, h4, h6 {
    line-height: 1.2em;
    margin-bottom: 20px;
}
h6 {
    display: block;
    font-size: 0.67em;
    -webkit-margin-before: 2.33em;
    -webkit-margin-after: 2.33em;
    -webkit-margin-start: 0px;
    -webkit-margin-end: 0px;
    font-weight: bold;
}
.write-title {
    text-align: center;
    margin-top: 18px;
    font-size: 13px;
    margin-bottom: 60px;
	position: relative;
    left: 235px;
}
.gender-selector input{
    -webkit-appearance:none;
    -moz-appearance:button;
    appearance:button;
    margin:0;
    padding:0;
}
.man{
    background-image:url(https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-512.png);
	border-color: #1f6ab0;
    position: relative;
    left: 400px;
    bottom: 80px;
	display: block;
    max-width: 100%;
}

.gender-selector:not(input:checked) input:active +.gen-sel{
    opacity: .6;
}

.gender-selector input:checked +.gen-sel{
    -webkit-filter: none;
    -moz-filter: none;
    filter: none;
}

.women{
    background-image:url(https://cdn1.iconfinder.com/data/icons/user-pictures/100/female1-512.png);
	border-color: #b24592;
    position: relative;
    left: 60px;
    top: 3px;
	display: block;
    max-width: 100%;
}

.gen-sel{
    cursor:pointer;
    display:inline-block;
    width:100px;
    height:70px;
    background-size:contain;
    background-repeat:no-repeat;
     -webkit-filter: brightness(1.8) grayscale(1) opacity(.7);
    -moz-filter: brightness(1.8) grayscale(1) opacity(.7);
    filter: brightness(1.8) grayscale(1) opacity(.7);
}
.gen-sel:hover{
    -webkit-filter: brightness(1.2) grayscale(.5) opacity(.9);
    -moz-filter:  brightness(1.2) grayscale(.5) opacity(.9);
    filter:  brightness(1.2) grayscale(.5) opacity(.9);
}
<main class="main ">
<div>
<div class="wrap write">	
<div class="write-gender">
<h6 class="write-title">Select gender</h6>
	<div class="gender-selector">
        <input id="gender" type="radio" name="gender" value="w" />
        <label class="gen-sel write-gender women" for="gender"></label>
        <input id="gender2" type="radio" name="gender" value="m" />
        <label class="gen-sel write-gender man"for="gender2"></label>
    </div>
</div>
</div>
</div>
</main>

希望这有帮助!

答案 2 :(得分:0)

回答第一个问题: 分组的radiobutton必须具有相同的名称,因此只需将第二个radiobutton更改为:

<input id="gender2" type="radio" name="gender" value="m" />

第二个问题: 我不知道你在问什么。请提供更多信息或代码。

答案 3 :(得分:0)

试试这段代码......这对你来说非常有用..

<main class="main ">
<div>
<div class="wrap write">    
<div class="write-gender">
<h6 class="write-title">Select gender</h6>
<div class="gender-selector">
<input id="gender" type="radio" name="gender" value="w" />
<label class="gen-sel write-gender women" for="gender"></label>
<input id="gender2" type="radio" name="gender" value="m" />
<label class="gen-sel write-gender man"for="gender2"></label>
</div>
</div>
</div>
</div>
</main>

输入类型无线电的名称必须相同。input type radio-w3schools