自定义单选按钮没有正确间距

时间:2017-06-22 17:06:27

标签: javascript jquery html css

所以,我正在制作一个电子邮件签名创建者,我制作了自己的单选按钮(我不喜欢常规按钮的外观)。我的基础是this post。我希望它们看起来相似,所以我或多或少地复制它们,以便我希望得到相同的结果。我调整了一下它们并使用了它们的功能,最终我得到了这个:Radio Buttons。我喜欢他们的样子,但他们太靠近了。当你看到其余部分时,你绝对可以看到:

Rest of picture

如您所见,按钮太靠近了。我希望它们有点间隔(不管我想要多少)但是当我尝试rightmargin-right等事情的时候,他们却揭示了背后的实际无聊的旧输入。

有什么想法吗?这是我到目前为止整个程序的代码:



$(function() {
  $("#editorTextInfoName").keyup(function() {
    var infoNameTextValue = $("#editorTextInfoName").val();
    $("#fullName").text(infoNameTextValue);
  });
  $("#editorTextInfoJob").keyup(function() {
    var infoJobTextValue = $("#editorTextInfoJob").val();
    $("#jobText").text(infoJobTextValue);
  });
});

table {
  display: inline-block;
}
#image {
  width: 125px;
  height: 125px;
  border-radius: 50%;
  margin-top: -45px;
}
.spacer {
  width: 15px;
}
hr {
  height: 200px;
  width: 7.5px;
  border-radius: 20px;
  border: none;
  background-color: cornflowerBlue;
}
#fullName {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 24px;
  color: orange;
  margin-top: -40px;
  }
#job {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 18px;
  margin-top: -10px;
  }
#jobLocationText {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 16px;
  margin-top: -10px;
}
.otherText {
  color: seaGreen;
}
#emailAddress, #phoneNumber, #officePhoneNumber, #address, #website {
  font-size: 17px;
}
#extra1, #extra2, #extra3, #extra4, #extra5, #extra6 {
    white-space: pre-wrap;
}
#signatureEditorText {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 24px;
  margin-bottom: 40px;
}
.editorTextInfo {
  color: gray;
  font-family: 'Lato', sans-serif;
  font-size: 18px;
  margin-bottom: 7px;
  margin-right: 60px;
}
.editorTextBox {
  font-family: 'Source Sans Pro', sans-serif;
  margin-right: 60px;
  margin-bottom: 20px;
  font-size: 16px;
  height: 20px;
  width: 160px;
  border: 2px solid darkGray;
  border-radius: 6px;
}
.editorTextBox:focus {
  outline: 0;
}
input[type = "radio"]:after {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  top: -12px;
  right: 6px;
  margin-right: 50px;
  background-color: darkGray;
  content: "";
  position: relative;
  display: inline-block;
}
input[type = "radio"]:hover {
  cursor: pointer;
}
input[type = "radio"]:checked:after {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background-color: orange;
  top: -12px;
  right: 6px;
  content: "";
  position: relative;
  display: inline-block;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <link rel="icon" href="Logo.ico">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
        <title>HTML Hub</title>
        <link href="index.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
      <center>
        <table cellpadding="0" cellspacing="0" border="0" style="background: none; border-width: 0px; border: 0px; margin: 0; padding: 0;">
          <tr>
            <td>
              <center>
                <img src="https://vignette2.wikia.nocookie.net/mafiagame/images/2/23/Unknown_Person.png/revision/latest?cb=20151119092211" id="image" title="Picture to be displayed">
              </center>
            </td>
            <td class="spacer"></td>
            <td rowspan="4">
              <hr>
            </td>
            <td class="spacer"></td>
          </tr>
          <tr>
            <td>
              <center>
                <div id="fullName">Billy Staples</div>
              </center>
            </td>
          </tr>
          <tr>
            <td>
              <center>
                <div id="job"><i id = "jobText">Programmer</i></div>
              </center>
            </td>
          </tr>
          <tr>
            <td>
              <center>
                <div id="jobLocationText">at <b id="jobLocation">My Company</b></div>
              </center>
            </td>
          </tr>
        </table>
        <table id="contactInfo" cellpadding="0" cellspacing="0" border="0" style="background: none; border-width: 0px; border: 0px; margin: 0; padding: 0;">
          <tr>
            <td>
              <div id="emailAddress"><span class="otherText">Email: </span><span id="emailAddressText">email@domain.com</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="phoneNumber"><span class="otherText">Phone: </span><span id="phoneNumberFirst">111</span>-<span id="phoneNumberSecond">222</span>-<span id="phoneNumberThird">3333</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="officePhoneNumber"><span class="otherText">Office Phone: </span><span id="officePhoneNumberFirst">444</span>-<span id="officePhoneNumberSecond">555</span>-<span id="officePhoneNumberThird">6666</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="address"><span class="otherText">Address: </span><span id="addressText">1379 Philadelphia Avenue</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="website"><span class="otherText">Website: </span><span id="websiteText">example.com</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra1"><span class="otherText" id="extra1Label"></span><span id="extra1Text"> </span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra2"><span class="otherText" id="extra2Label"></span><span id="extra2Text"> </span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra3"><span class="otherText" id="extra3Label"></span><span id="extra3Text"> </span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra4"><span class="otherText" id="extra4Label"></span><span id="extra4Text"> </span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra5"><span class="otherText" id="extra5Label"></span><span id="extra5Text"> </span></div>
            </td>
          </tr>
        </table>
      </center>
      &nbsp;
      <p></p>
      <table id = "editTable" cellpadding="0" cellspacing="0" border="0" style="background: none; border-width: 0px; border: 0px; margin: 0; padding: 0;">
          <tr>
            <td>
              <div id = "signatureEditorText">Signature Editor</div>
            </td>
          </tr>
          <tr>
            <td>
              <div class = "editorTextInfo">Name</div>
            </td>
            <td>
              <div class = "editorTextInfo">Job</div>
            </td>
          </tr>
          <tr>
            <td>
              <input id = "editorTextInfoName" type = "text" class = "editorTextBox">
            </td>
            <td>
              <input id = "editorTextInfoJob" type = "text" class = "editorTextBox">
            </td>
          </tr>
          <tr>
            <td>
              <div class = "editorTextInfo">Company</div>
            </td>
            <td>
              <div class = "editorTextInfo">At / At the</div>
            </td>
          </tr>
          <tr>
            <td>
              <input id = "editorTextInfoCompany" type = "text" class = "editorTextBox">
            </td>
            <td>
              <input name = "radio" id = "editorRadioInfoCompany1" type = "radio" class = "editorRadio">
              <input name = "radio" id = "editorRadioInfoCompany2" type = "radio" class = "editorRadio">
            </td>
          </tr>
        </table>
    </body>
</html>
&#13;
&#13;
&#13;

谢谢!

2 个答案:

答案 0 :(得分:2)

给出输入本身(不是&#34;:&#34;元素)的一些余量,应该解决问题。类似的东西:

input[type = "radio"] { margin:5px }

答案 1 :(得分:1)

在单选按钮的代码之间添加&amp; nbsp,如下面的代码段

所示

$(function() {
  $("#editorTextInfoName").keyup(function() {
    var infoNameTextValue = $("#editorTextInfoName").val();
    $("#fullName").text(infoNameTextValue);
  });
  $("#editorTextInfoJob").keyup(function() {
    var infoJobTextValue = $("#editorTextInfoJob").val();
    $("#jobText").text(infoJobTextValue);
  });
});
table {
  display: inline-block;
}
#image {
  width: 125px;
  height: 125px;
  border-radius: 50%;
  margin-top: -45px;
}
.spacer {
  width: 15px;
}
hr {
  height: 200px;
  width: 7.5px;
  border-radius: 20px;
  border: none;
  background-color: cornflowerBlue;
}
#fullName {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 24px;
  color: orange;
  margin-top: -40px;
  }
#job {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 18px;
  margin-top: -10px;
  }
#jobLocationText {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 16px;
  margin-top: -10px;
}
.otherText {
  color: seaGreen;
}
#emailAddress, #phoneNumber, #officePhoneNumber, #address, #website {
  font-size: 17px;
}
#extra1, #extra2, #extra3, #extra4, #extra5, #extra6 {
    white-space: pre-wrap;
}
#signatureEditorText {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 24px;
  margin-bottom: 40px;
}
.editorTextInfo {
  color: gray;
  font-family: 'Lato', sans-serif;
  font-size: 18px;
  margin-bottom: 7px;
  margin-right: 60px;
}
.editorTextBox {
  font-family: 'Source Sans Pro', sans-serif;
  margin-right: 60px;
  margin-bottom: 20px;
  font-size: 16px;
  height: 20px;
  width: 160px;
  border: 2px solid darkGray;
  border-radius: 6px;
}
.editorTextBox:focus {
  outline: 0;
}
input[type = "radio"]:after {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  top: -12px;
  right: 6px;
  margin-right: 50px;
  background-color: darkGray;
  content: "";
  position: relative;
  display: inline-block;
}
input[type = "radio"]:hover {
  cursor: pointer;
}
input[type = "radio"]:checked:after {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background-color: orange;
  top: -12px;
  right: 6px;
  content: "";
  position: relative;
  display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <link rel="icon" href="Logo.ico">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
        <title>HTML Hub</title>
        <link href="index.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
      <center>
        <table cellpadding="0" cellspacing="0" border="0" style="background: none; border-width: 0px; border: 0px; margin: 0; padding: 0;">
          <tr>
            <td>
              <center>
                <img src="https://vignette2.wikia.nocookie.net/mafiagame/images/2/23/Unknown_Person.png/revision/latest?cb=20151119092211" id="image" title="Picture to be displayed">
              </center>
            </td>
            <td class="spacer"></td>
            <td rowspan="4">
              <hr>
            </td>
            <td class="spacer"></td>
          </tr>
          <tr>
            <td>
              <center>
                <div id="fullName">Billy Staples</div>
              </center>
            </td>
          </tr>
          <tr>
            <td>
              <center>
                <div id="job"><i id = "jobText">Programmer</i></div>
              </center>
            </td>
          </tr>
          <tr>
            <td>
              <center>
                <div id="jobLocationText">at <b id="jobLocation">My Company</b></div>
              </center>
            </td>
          </tr>
        </table>
        <table id="contactInfo" cellpadding="0" cellspacing="0" border="0" style="background: none; border-width: 0px; border: 0px; margin: 0; padding: 0;">
          <tr>
            <td>
              <div id="emailAddress"><span class="otherText">Email: </span><span id="emailAddressText">email@domain.com</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="phoneNumber"><span class="otherText">Phone: </span><span id="phoneNumberFirst">111</span>-<span id="phoneNumberSecond">222</span>-<span id="phoneNumberThird">3333</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="officePhoneNumber"><span class="otherText">Office Phone: </span><span id="officePhoneNumberFirst">444</span>-<span id="officePhoneNumberSecond">555</span>-<span id="officePhoneNumberThird">6666</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="address"><span class="otherText">Address: </span><span id="addressText">1379 Philadelphia Avenue</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="website"><span class="otherText">Website: </span><span id="websiteText">example.com</span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra1"><span class="otherText" id="extra1Label"></span><span id="extra1Text"> </span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra2"><span class="otherText" id="extra2Label"></span><span id="extra2Text"> </span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra3"><span class="otherText" id="extra3Label"></span><span id="extra3Text"> </span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra4"><span class="otherText" id="extra4Label"></span><span id="extra4Text"> </span></div>
            </td>
          </tr>
          <tr>
            <td>
              <div id="extra5"><span class="otherText" id="extra5Label"></span><span id="extra5Text"> </span></div>
            </td>
          </tr>
        </table>
      </center>
      &nbsp;
      <p></p>
      <table id = "editTable" cellpadding="0" cellspacing="0" border="0" style="background: none; border-width: 0px; border: 0px; margin: 0; padding: 0;">
          <tr>
            <td>
              <div id = "signatureEditorText">Signature Editor</div>
            </td>
          </tr>
          <tr>
            <td>
              <div class = "editorTextInfo">Name</div>
            </td>
            <td>
              <div class = "editorTextInfo">Job</div>
            </td>
          </tr>
          <tr>
            <td>
              <input id = "editorTextInfoName" type = "text" class = "editorTextBox">
            </td>
            <td>
              <input id = "editorTextInfoJob" type = "text" class = "editorTextBox">
            </td>
          </tr>
          <tr>
            <td>
              <div class = "editorTextInfo">Company</div>
            </td>
            <td>
              <div class = "editorTextInfo">At / At the</div>
            </td>
          </tr>
          <tr>
            <td>
              <input id = "editorTextInfoCompany" type = "text" class = "editorTextBox">
            </td>
            <td>
              <input name = "radio" id = "editorRadioInfoCompany1" type = "radio" class = "editorRadio"> &nbsp;&nbsp;&nbsp;
              <input name = "radio" id = "editorRadioInfoCompany2" type = "radio" class = "editorRadio">
            </td>
          </tr>
        </table>
    </body>
</html>