【问题标题】:How to add border line using HTML/CSS [duplicate]如何使用 HTML/CSS 添加边框线 [重复]
【发布时间】:2019-10-02 07:03:09
【问题描述】:

我正在尝试为正在工作的小部件添加边框,但它没有捕获整个 wigets 字段,只有一半正在绘制一条线

enter image description here

HTML:

    <p class="solid">
   <img src="log.jpg" width="20" height="20"/>

    <div class="input-group">
      <input type="text" ng-model="c.data.message" class="form-control" aria-label="...">
      <div class="input-group-btn">
        <button type="submit" ng-click="c.add()" class="btn btn-primary">Search</button>
      </div>
    </div>

 </p>

CSS:

p.solid {border-style: solid;}

【问题讨论】:

  • 您不能将div 嵌套到p 中,这是无效的HTML。浏览器的纠错是通过在遇到div 的起始标记时立即关闭p 元素来修复您的错误。
  • 你要关闭

    标签吗?

标签: html css


【解决方案1】:

段落不打算作为其他块元素的包装。渲染引擎会在打开后面的&lt;div&gt;之前自动关闭&lt;p&gt;标签,因此渲染一个没有高度的空段落,导致只有一个边框没有其他任何东西。将段落更改为&lt;div&gt;(或任何其他语义上可行的元素),它将起作用。

.solid {
  border-style: solid;
}
<div class="solid">

  <div class="input-group">
    <input type="text" ng-model="c.data.message" class="form-control" aria-label="...">
    <div class="input-group-btn">
      <button type="submit" ng-click="c.add()" class="btn btn-primary">Search</button>
    </div>
  </div>

</div>

【讨论】:

  • 谢谢康斯坦丁。一个快速的问题,为什么我们在 css 中使用 .solid ?什么 。参考?
  • . 是类选择器。当您添加class="solid" 时,您可以通过.solid 在CSS 中选择它,就像您可以通过#something 使用id="something" 一样。我建议您找到一个解释基本知识的 CSS 初学者教程。 :-)
  • 如果您的问题涉及为什么决定使用该符号 - 我也不知道。也许你可以在网上找到一个解释,否则你必须问 CSS 的发明者为什么他们决定使用点和哈希。 ;)
猜你喜欢
  • 2021-10-14
  • 1970-01-01
  • 2021-04-20
  • 1970-01-01
  • 2019-06-10
  • 2021-12-04
  • 2015-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多