我想让白色指针从右浮动段落中伸出。 这是我到目前为止所取得的成就。它远非完美,因为当我调整屏幕大小时,指针不想粘在边框上。 解决办法是什么?
#batu {
float: none;
clear: both;
position: relative;
background: url(https://pp.userapi.com/c836431/v836431507/5a2cd/Zc9FsOzRLdY.jpg) no-repeat;
max-width: 1170px;
background-size: cover; /* Never used this before */
}
#batu::after {
content: '';
display: block;
float: none;
clear: both;
overflow: nidden;
}
#batu .overlay-content {
float: right;
width: 40%;
height: 100%;
background-color: rgba(255, 255, 255, 0.8);
min-height: 517px; /* the height of the background image*/
}
.pointer {
position: absolute;
top: 48%;
left: 48%;
width: 10px;
height: 24px;
background: url(https://s8.hostingkartinok.com/uploads/images/2017/08/96ad387742f9e8fce21c53f42fe45984.png) no-repeat;
}
<div id="batu">
<div class="pointer"></div>
<div class="overlay-content">
<h4>Batu</h4>
<p>blablablablablablablablablablablabla
blablablablablablablablablablablablablb
blablablablablablablablablablablablabla
blablablablablablablablablablablablablb
</p>
</div>
</div>
最佳答案
如果您可以将指针设置为overlay-content
内的after
psuedo元素,那就更容易了:
将
position:relative
添加到overlay-content
psuedo
after
元素可以如下所示:#batu .overlay-content::after { content: ''; position: absolute; top: 50%; left: 0; transform: translate(-100%, -50%); width: 10px; height: 24px; background: url(https://s8.hostingkartinok.com/uploads/images/2017/08/96ad387742f9e8fce21c53f42fe45984.png) no-repeat; }
请参阅下面的演示:
#batu {
float: none;
clear: both;
position: relative;
background: url(https://pp.userapi.com/c836431/v836431507/5a2cd/Zc9FsOzRLdY.jpg) no-repeat;
max-width: 1170px;
background-size: cover;
/* Never used this before */
}
#batu::after {
content: '';
display: block;
float: none;
clear: both;
overflow: hidden;
}
#batu .overlay-content {
float: right;
width: 40%;
height: 100%;
background-color: rgba(255, 255, 255, 0.8);
min-height: 517px;
/* the height of the background image*/
position: relative;
}
/*
.pointer {
position: relative;
top: 48%;
left: 48%;
float: right;
width: 10px;
height: 24px;
background: url(https://s8.hostingkartinok.com/uploads/images/2017/08/96ad387742f9e8fce21c53f42fe45984.png) no-repeat;
}
*/
#batu .overlay-content::after {
content: '';
position: absolute;
top: 50%;
left: 0;
transform: translate(-100%, -50%);
width: 10px;
height: 24px;
background: url(https://s8.hostingkartinok.com/uploads/images/2017/08/96ad387742f9e8fce21c53f42fe45984.png) no-repeat;
}
<div id="batu">
<!--<div class="pointer"></div>-->
<div class="overlay-content">
<h4>Batu</h4>
<p>blablablablablablablablablablablabla blablablablablablablablablablablablablb blablablablablablablablablablablablabla blablablablablablablablablablablablablb
</p>
</div>
</div>
关于html - 使元素与 float 元素的边框相邻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45821763/