css - 如何在具有不同背景颜色的div中添加框?

标签 css

我的场景:

在下面提到的 div 中,我需要在 div 的右下角添加“查找更多”链接,该链接应包含不同的 bg-color,换句话说,最后一个带有箭头图像的框结构。

.answerbox
{
height: 150px; /*Specify Height*/
width:  150px; /*Specify Width*/
border: 1px solid black; /*Add 1px solid border, use any color you want*/
background-color: green; /*Add a background color to the box*/
text-align:center; /*Align the text to the center*/
}

它应该是什么样子:

enter image description here

最佳答案

你是说这样吗?这是一个 jsfiddle

通过将父级 (.answerbox) 设置为 position: relative,我可以将 .more 设置为 position :absolute 并将其放置在该框中我喜欢的任何位置;在本例中,容器的右下角。

HTML

<div class="answerbox">
    <a href="#" class="more">Find out more</a>
</div>

CSS

.answerbox {
    height: 150px; /*Specify Height*/
    width:  150px; /*Specify Width*/
    border: 1px solid black; /*Add 1px solid border, use any color you want*/
    background-color: green; /*Add a background color to the box*/
    text-align:center; /*Align the text to the center*/
    position: relative;
}
.more {
    background: red;
    position: absolute;
    bottom: 0;
    right: 0;
    padding: 0 10px;
    height: 30px;
}

编辑 - 如果您想要按钮上的箭头图像

Updated Fiddle

CSS

.more {
    background: url('http://dc390.4shared.com/img/AgV87Tvx/s7/arrow_small_right.png') no-repeat left center red;
    position: absolute;
    bottom: 0;
    right: 0;
    height: 30px;
    padding: 0 10px 0 20px; /* Extra padding left to make room for the button */
    line-height: 30px; /* Used to center the text vertically. Use the same value as the height.*/
}

编辑——让盒子随内容增长

Updated Fiddle

CSS

.answerbox {
    width:  150px; /*Specify Width*/
    border: 1px solid black; /*Add 1px solid border, use any color you want*/
    background-color: green; /*Add a background color to the box*/
    text-align:center; /*Align the text to the center*/
    position: relative;
    padding: 10px 10px 40px;
}

关于css - 如何在具有不同背景颜色的div中添加框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15947286/

相关文章:

ASP.NET 创建类似于 windows.com 的导航菜单样式

CSS 和图像错误 - 不显示图像

javascript - 在对话框中将我新克隆的 div 设置为只读

css - 灰度到黑色不透明度转换

css - 为什么悬停后移动图像 - 仅限 chrome

css - 在以纵向格式显示背景图像的移动设备上出现 CSS 问题

javascript - 如何捕获 :after content in IE8?

css - 网站中的固定宽度 div 强制相对宽度 div 与移动浏览器中的显示保持相同的宽度

html - 引用特定表的 th、tr 和 td

html - 网格,这样我就可以在不滚动的情况下适应整个移动屏幕