html - 隐藏的输入弄乱了我的填充

标签 html css

我有一个 <li>有 4 个可点击按钮,我在它下面还有一个边框,当它被点击时显示,我也在那里隐藏了一个输入,但是它弄乱了我的右填充,看到这个 fiddle https://jsfiddle.net/9qy53L32/

它在“total”上看起来很正常,因为我删除了那里的隐藏输入只是为了显示,但在其他人身上,当点击时,边框底部停在文本在右侧的位置,所以填充有点搞砸了,这能修好吗?

代码:

<div class="holdLiftMenu">
   <ul class="holdLiftMenuUL">
      <li class="holdLiftMenuLI">
         <a class="holdLiftMenuA total current">Total
            <input type="hidden" name="hid4" id="hid4" value="4" />
         </a>
      </li>
      <li class="holdLiftMenuLI">
         <a class="holdLiftMenuA squat">Squat
            <input type="hidden" name="hid1" id="hid1" value="" />
         </a>
      </li>
      <li class="holdLiftMenuLI">
         <a class="holdLiftMenuA benchpress">Benchpress
            <input type="hidden" name="hid2" id="hid2" value="" />
         </a>
      </li>
      <li class="holdLiftMenuLI">
         <a class="holdLiftMenuA deadlift">Deadlift
            <input type="hidden" name="hid3" id="hid3" value="" />
         </a>
      </li>
   </ul>
</div>

脚本

$(document).ready(function () {
    $('.holdLiftMenu li a').on('click', function () {
        $('li a.current').removeClass('current');
        $(this).addClass('current');
    });
});

CSS

.holdLiftMenu {
    margin-top: 10px;
    background-color: white;
    padding: 10px;
}

.holdLiftMenuUL {
    margin:0;
}

.holdLiftMenuLI {
    display:inline-block;
}

.holdLiftMenuA {
    background-color:white;
    padding: 10px;
    cursor:pointer;
    color: black;
    font-weight:700;
    font-size: 16px;
    text-align:center;    
}

.current {
    border-bottom: 3px solid red;
}

最佳答案

根据我的评论,如果您添加 white-space: nowrap;应该修复它

.holdLiftMenuA {
    background-color:white;
    padding: 10px;
    cursor:pointer;
    color: black;
    font-weight:700;
    font-size: 16px;
    text-align:center;
    white-space: nowrap;
}

关于html - 隐藏的输入弄乱了我的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42554346/

相关文章:

javascript - 在 javascript 中提交表单后,IE 不会关闭窗口

css - -moz-column 在 rtl 方向上不能正常工作

php - 如何将 CSS 类添加到 Zend_Form_Element_Select 选项

html - 什么更容易访问,文本缩进 : -9999px or just using an img with an alt tag?

html - 放置 margin 时 Bootstrap 列不起作用

javascript - 如何使用纯 javascript 而不是 jquery 更新 iFrame 的 CSS

html - 选择元素有其他宽度而不是 silbling,bootstrap 间距过冲

jquery - 什么类型的 DOM 元素?

javascript - 通过JS将HTML插入HTML页面

javascript - Javascript 显示 block && 无重复问题