简体   繁体   English

如何获得两个并排的html输入字段,使其看起来小于小于输入字段高度的中间分隔符?

[英]How do I get two side by side html input fields to look combined with a middle separator that is less than the input field heights?

I want to achieve something like below 我想实现以下目标 在此处输入图片说明

How do I style the html and css? 如何设置HTML和CSS的样式?

Hello you can enclose the two input fields in a div then add margins inside. 您好,您可以将两个输入字段括在div中,然后在其中添加边距。 Here's a summary of what I did; 这是我所做的摘要;

  1. put input fields inside a div 将输入字段放入div
  2. remove borders from the input fields 从输入字段中删除边框
  3. add margin on top & bottom of the input fields (this would be the spacing on top and bottom of the separator) 在输入字段的顶部和底部添加边距(这将是分隔符顶部和底部的间距)
  4. add a border on the right of the first input field 在第一个输入字段的右侧添加边框

Do run the snippet below, thanks. 请运行下面的代码段,谢谢。

 $(".input-group-wrapper input").on("focus", function() { $(this).parent().addClass("focus"); }); $(".input-group-wrapper input").on("focusout", function() { $(this).parent().removeClass("focus"); }); 
 .input-group-wrapper { border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.1); display: inline-block; transition: 0.2s; width: 100%; } .input-group-wrapper>.first, .input-group-wrapper>.second { border: none; line-height: 30px; display: inline; margin: 6px 0px 6px 0px; padding: 0px 8px 0px 8px; } .input-group-wrapper>.first { width: 60%; border-right: 1px solid rgba(0, 0, 0, 0.1); } .input-group-wrapper>.second { width: 30%; } .input-group-wrapper>.first:focus, .input-group-wrapper>.first:active, .input-group-wrapper>.second:focus, .input-group-wrapper>.second:active { outline: none; } .focus { border: 2px solid rgba(0, 100, 200, 0.6); } 
 <div class='input-group-wrapper'> <input class='first' placeholder='eg Read every day p3 @goals #learning' /> <input class='second' value='Aug 4 2018' /> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

To achieve this look, you'll want to use a margin on one of them. 为了获得这种外观,您需要在其中一个上使用边距。 I have my code and a Code Pen linked below: 我在下面链接了我的代码和一支电笔:

  .modified{ height: 30px; border-radius: 2px; border: 1px solid lightgray; box-shadow: none; padding: 3px 6px; } .modified.right{ margin-left: -10px; width: 125px;/* Alternatively use % or vw */ } .modified.right::placeholder{ color: black; } 
 <input type="text" class="modified" placeholder="Just Test Me"/> <input type="text" class="modified right" placeholder="I Am Testing" /> 

Codepen Example Codepen示例

I hope this helps! 我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM