简体   繁体   English

边框不顶部内联,边框底部内联

[英]Border-top not inline, border-bottom inline

I have a simple image which I want to give a border-top and border bottom. 我有一个简单的图像,我想给它上边框和下边框。 This is my code: 这是我的代码:

<div class="details-big">
    <img src="../images/full/full21.jpg" alt="title" />
</div>

The CSS: CSS:

.details-big {
    border-top: 8px solid #f0f0f0;
    border-bottom: 8px solid #f0f0f0;
}

The problem is that the border-top cuts off a part of the image, while the border-bottom does the opposite, and adds white padding even before the border-bottom is displayed. 问题在于,边框顶部会截去图像的一部分,而边框底部会截取相反的部分,甚至在显示边框底部之前都会添加白色填充。

I would simply like the borders to be added neatly to the border without any spaces or parts of the image being cut off. 我只是希望将边框整齐地添加到边框,而不会切除图像的任何空格或部分。 Is this possible with CSS? CSS有可能吗?

In fact it's not cut off at the top, it just has a space at the bottom, which is rendered by the inline img . 实际上,它并没有在顶部被切断,它在底部只有一个空间,由内联img呈现。 If your div contains only the image, you can just set font-size:0 for your div. 如果div仅包含图像,则可以为div设置font-size:0 Also you can set the border for your img instead: 您也可以为img设置边框:

.details-big {
  border-top: 8px solid #f0f0f0;
  border-bottom: 8px solid #f0f0f0;    
  font-size:0;
}

You can also set display:block for your img : 您也可以为img设置display:block

.details-big > img {
  display:block;
}

Demo. 演示。

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

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