简体   繁体   English

将箭头从一个 div go 插入另一个

[英]Have an arrow from one div go into another

I need to achieve something like this:我需要实现这样的目标:

representation表示

I have found similar issues but they do not completely cover my task.我发现了类似的问题,但它们并没有完全涵盖我的任务。 Here is an example of a thing I have found:这是我发现的一个例子:

 .blue-background { background-color: blue; border-radius: 5px; top: 3em; left: 230px; padding: 10px; font-family: Roboto, sans-serif; font-size: 14px; line-height: 22px; color: #313333; display: flex; align-items: center; width: 260px; }.blue-background::after { content: ' '; width: 0px; height: 0px; border-top: 25px solid transparent; border-left: 37px solid blue; border-bottom: 25px solid transparent; border-right: 0px solid transparent; position: absolute; top: 43%; left: 47%; }.child-image-wrapper { max-width: 260px; margin: auto; img { max-width: 260px; } }
 <div class="col-md-4 col-xs-12"> <div class="image-block"> <div class="blue-background"> <h2>Some Text <span class="arrow"></span></h2> </div> <div class="child-image-wrapper"> <img src="This is an image" /> </div> </div>

Now the problem with the above CSS is that this works only at particular screen size (like 585px or so) otherwise the arrow "detaches" from the left div and goes into the right div.现在上述 CSS 的问题在于,这只适用于特定的屏幕尺寸(如 585px 左右),否则箭头会从左侧 div 中“分离”并进入右侧 div。 What I need is for the blue arrow to be stuck to the left div even if the screen size changes.我需要的是即使屏幕尺寸发生变化,蓝色箭头也能粘在左边的 div 上。 Would it be possible to achieve this in some way?是否有可能以某种方式实现这一目标? Sorry I am pretty new to front-end design对不起,我对前端设计很陌生

You can do it like so:你可以这样做:

 .wrapper { width: 10em; height: 2em; /* Height needs to match.right::after height and width */ display: flex; }.left { background-color: lightblue; width: 50%; }.right { background-color: lightpink; border-left: 1px solid purple; width: 50%; position: relative; overflow: hidden; }.right:before { height: 2em; /* Match height above*/ width: 2em; /* Match height above*/ background-color: #b77681; position: absolute; top: 50%; left: 0%; content: ""; border: 1px solid #864954; transform: translate(-73%, -50%) rotate(45deg); }
 <div class='wrapper'> <div class='left'> </div> <div class='right'> </div> </div>

I encourage you to read more about the position property (in our case specifically absolute and relative ).我鼓励您阅读有关position属性的更多信息(在我们的例子中,特别是absoluterelative )。 here you can find some introduction.在这里你可以找到一些介绍。

As per your question change the top and left properties in .blue-background::after to fit the position for the arrow as you want.根据您的问题,更改.blue-background::after中的topleft属性,以根据需要将 position 用于箭头。

here is an example: https://jsfiddle.net/qa9un7fy/这是一个例子: https://jsfiddle.net/qa9un7fy/

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

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