我想从正确浮动的段落中制作一个白色指针。 这就是我到目前为止所取得的成就。当我调整屏幕大小时,指针不想粘在边框上,这远非完美。 解决方案是什么?
#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>
&#13;
答案 0 :(得分:2)
如果你可以在after
中将指针设为overlay-content
伪造的元素,那就更容易了:
将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>
答案 1 :(得分:0)
我修改了你的代码。检查此https://jsfiddle.net/osxo2vzL/。
您需要在段落标记中添加word-wrap: break-word;
。