html - 在 CSS 中更改边框高度?

标签 html css

我试图将 siginimage 的左边框设置为 40px,但是由于 signinimage 的高度是 25px,因此边框高度也被设置为 25px.

.top-header {
    float: left;
    border-left: 2px solid #CCCCCC;
    height: 30px;
    margin-top: 0px;
}

#signinimage {
    padding-top: 6px;
    padding-left: 10px;
    height: 25px; 
    width: 25px;
}
<img src="images/signinimage.png" class="top-header" id="signinimage">

最佳答案

两种方法。

  1. 要么创建一个容器并将图像放入其中

In your question, you said you wanted to extend the border to the left (but I mean that's just a matter of simple float:, but you can apply this approach in general

img {
  width: 100px;
  height: 100px;
  float: right;
}

#container {
  border: 3px solid black;
  width: 150px;
  height: 100px;
}
<div id ="container">
    <img src=https://i.imgur.com/QIsNrpM.png/>
</div>

  1. 另一种选择,如果您坚持只使用一个元素而不是两个元素,您可以将图像设置为不同大小的 divbackground-image >

    #imganddiv {
      border: 3px solid black;
      width: 150px;
      height: 100px;
      
      background-image: url('https://i.imgur.com/QIsNrpM.png');
      background-size: 100px 100px;
      background-repeat: no-repeat;
      background-position: right center;
    }
<div id="imganddiv"></div>

我个人更喜欢第一个选项,因为它更直观一些,而且通常被认为是处理容器(元素内的元素)的常见做法。

关于html - 在 CSS 中更改边框高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50728111/

相关文章:

javascript - 单击具有父类条件的动态子 DOM

html - 在 IE 中列出元素渲染错误?

html - 删除手机屏幕中的图片链接

html - CSS:padding-top 后的一些空间事件:0% 甚至

html - SCSS Transitions 上的文本重叠

javascript - CSS 属性更新不适用于鼠标单击

jQuery 单击事件在 Internet Explorer 中不起作用

html - Bootstrap 3 页脚在没有 <h2> 的情况下无法工作

没有框架的javascript css

css - 纯CSS : Colorate divs behind a particular div