简体   繁体   English

CSS 设计问题 - 在特定 position 中为 div 添加一个小的背景图像

[英]CSS design question - adding a small background-image for div in a specific position

To clarify, I made the following diagram:为了澄清,我做了下图:

图表

Basically I have a bordered div, which is clickable.基本上我有一个带边框的 div,它是可点击的。 After clicking it, I want to (through javascript) create a new div which has a protruding arrow shaped border into the clicked div.点击它后,我想(通过javascript)创建一个新的div,它在点击的div中有一个突出的箭头形边框。

Any ideas as to how I would create such a border?关于如何创建这样的边界的任何想法? I'm not worried about the javascript.我不担心 javascript。 Just how to actually create such a border.只是如何实际创建这样的边界。

You can use the CSS Triangle approach (Lots of examples online, here's one from CSS Tricks ), where you have an empty div inside your tooltip that uses some clever border manipulation to make the angle.您可以使用 CSS 三角形方法(网上有很多示例,这里有一个来自 CSS Tricks的示例),您的工具提示中有一个空div ,它使用一些巧妙的边框操作来制作角度。 Just position the div , and you're done!只需 position div ,就完成了!

Check out the below example, after clicking the link either you append the "after-click-div" or show it.看看下面的例子,点击链接后你 append “after-click-div” 或显示它。 The arrow div is positioned with negative margin over the border.箭头 div 以负边距定位在边框上方。

<div class="container">
  <a href="#">Link</a>
  <div id="after-click-div" style="border: 1px solid #000; position: relative;">
    <div class="arrow" style="background: #fff url(arrow.gif) no-repeat; position: absolute; top: -10px; right: 10px; width: 10px; height: 10px"></div>
   content
  </div>
</div>

Or you can save an image like this _ __ _ __ ^ _ and assign it as a background image to the after_click_div like background: url(arrow.gif) no-repeat top right或者您可以保存这样的图像_ __ _ __ ^ _ 并将其作为背景图像分配给 after_click_div 像background: url(arrow.gif) no-repeat top right

I tried to make it as close to your drawing beautiful diagram as possible, but I wasn't quite able to get the arrow's hrm... unique angle.我试图让它尽可能接近 绘制 的漂亮图表,但我不太能得到箭头的 hrm……独特的角度。

http://jsfiddle.net/WJtnM/ http://jsfiddle.net/WJtnM/

HTML HTML

<div id="b"> <span class="g">BEFORE CLICK</span>&nbsp; 
    <div id="f"> AFTER CLICK </div>
    <div class="c" id="d"></div>
    <div class="c" id="e"></div>
</div>

CSS CSS

#b
{
    position:relative;
    padding:28px 20px 12px 60px;
    width:170px;
    border:1px solid black;
}
.c
{
    position:absolute;
    bottom:100%;
    right:30px;

    width:0px;
    height:0px;
    border: 20px solid transparent;
}
.c#d
{
    border-bottom-color: black;
}
.c#e
{
    border-bottom-color: white;
    margin-bottom: -1px;
}

#f
{
    position:absolute;
    padding:35px 20px 12px 60px;
    width:170px;
    border:1px solid black;
    border-bottom-width: 0px;
    bottom:100%;
    left:-1px;
}

jQuery jQuery

$("#b").click(function(){

    $(".c,#f,.g").toggle();

})

The arrow border have to be an image and it have to take a z-index.箭头边框必须是图像,并且必须采用 z-index。

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

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