html - 将元素放在固定元素内

标签 html css

我希望两个 td 的长度相等并保持在红色边框内。但文本框不止于此。

带有黑色边框的外部 div 的位置设置为“固定”。这是使该 div 在页面中居中所必需的。

即使我将 td 宽度分别设置为 50%,它也不起作用。我明白了,这是因为主div有一个固定的位置。那么在这种情况下如何解决。

CSS:

.loginBox
{
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 450px;
    height: 210px;
    margin: auto;
background-image: url(file:///C:/Users/HOME/Desktop/box-bg.jpg);
    background-repeat: repeat;
border: 1px solid rgb(18, 18, 18);
    box-shadow: 0px 6px 24px 12px rgba(0, 0, 0, 0.15);
}
.inner
{
border:1px solid red;
margin:20px;
width:91%;
}

HTML:

<div class="loginBox">    
  <div class="inner">
   <table width="100%">
    <tr>
     <td>
      Username
      <div><input type="text"/></div>
     </td>
     <td>
      Password
      <div><input type="text"/></div>
     </td>
    </tr>
   </table>
  </div>
</div>

enter image description here

最佳答案

将此添加到您的 CSS:

.inner td {
  width: 50%;
}

.inner td input{
  width: 100%;
}

更新:

您可以通过以下方式改进:

.inner td {
    width: 50%;
    white-space: nowrap;
}

.inner td input{
    width: 99%; /* decreased for border width */
    border: 1px solid #ddd;
}

关于html - 将元素放在固定元素内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21798235/

相关文章:

javascript - 对 D3 中可折叠树形图中父节点上的 "Number of child' s 进行编号

javascript - 如何从其来源获取iframe的高度

javascript - 为参数值不在当前范围内的元素创建 onclick

css - 在 CSS 选择器之后

javascript - 按内容对 div 进行排序

html - 绝对定位情况下的顶部底部填充

html - 我可以通过CSS指定折线的点吗

html - CSS - 两个并排自动宽度的 Div

css - 两个 CSS 声明实际上相同吗?

css - 在 ionic 3 上组织网格