第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

帶箭頭的語音氣泡

帶箭頭的語音氣泡

明月笑刀無情 2019-06-18 15:26:25
帶箭頭的語音氣泡我有一個(gè)項(xiàng)目需要插入語音氣泡/消息框..我想要達(dá)到的總體目標(biāo)是:.bubble {  height: 100px;  width: 200px;  border: 3px solid gray;  background: lightgray;  position: relative;  cursor:pointer;}.triangle {  width: 0;  border-top: 20px solid black;  border-left: 20px solid transparent;  border-right: 20px solid transparent;  cursor:pointer;}<div class="bubble">Speech bubble</div><div class="triangle"></div>這目前沒有通過命中測試,因?yàn)橥该鞯倪吙蛞彩强牲c(diǎn)擊的。目標(biāo)命中框(可點(diǎn)擊/懸停區(qū)域)需要堅(jiān)持形狀的邊界(這里的透明邊界也是懸停的,使之無效)。我需要在不同的內(nèi)容上顯示形狀(圖像,食草動(dòng)物,文本.),問題我在處理這個(gè)形狀時(shí)遇到的主要問題是:有能力在語音氣泡周圍移動(dòng)三角形根據(jù)它所指元素的位置(上/左/右/底)在需要強(qiáng)調(diào)時(shí),在其周圍添加邊框或框影。是否有解決這些問題的辦法?
查看完整描述

3 回答

?
30秒到達(dá)戰(zhàn)場

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊

為了實(shí)現(xiàn)這一點(diǎn),您應(yīng)該考慮修改您的標(biāo)記,以使您的html更有效率。這可以使用偽元素來實(shí)現(xiàn)。我將逐一闡述每一點(diǎn),并在回答的最后把所有的內(nèi)容放在一起。

首先,

使用偽元素避免額外的元素

您可以使用一個(gè)偽元素來刪除額外的.triangle迪夫。這不僅減少了div的數(shù)量,而且還有助于定位,因?yàn)槟梢允褂?/trans>top: left: right:bottom:CSS屬性,以便根據(jù)主元素進(jìn)行定位。如下所示:

.oneAndOnlyDiv {

  height: 100px;

  width: 200px;

  border: 3px solid gray;

  background: lightgray;

  position: relative;

}

.oneAndOnlyDiv:before {

  content: "";

  position: absolute;

  top: 100%;

  left: 20px;

  width: 0;

  border-top: 20px solid black;

  border-left: 20px solid transparent;

  border-right: 20px solid transparent;

}

<div class="oneAndOnlyDiv">Main div</div>

命中測試

為了創(chuàng)建您的“命中測試”,您可能希望使用一個(gè)旋轉(zhuǎn)元素,而不是邊框黑客。

類似于:

div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor:pointer;}div:before {
  content: "";
  position: absolute;
  top: 100%;
  left: 20px;
  height: 20px;
  width: 20px;
  background: black;
  transform: rotate(45deg);
  transform-origin:top right;}
<div>Only element</div>

或者使用扭曲的偽元素:


div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor:pointer;}div:before {
  content: "";
  position: absolute;
  top: 90%;
  left: 20px;
  height: 30%;
  width: 20px;
  background: black;
  transform: skewY(-45deg);
  transform-origin:bottom left;
  z-index:-1;}
<div>Only element</div>

它只在正方形或主元素懸停時(shí)顯示指針。但等等,那會(huì)搞砸定位嗎?你怎么能應(yīng)付得來?

有幾個(gè)解決辦法。其中之一是使用calcCSS屬性

div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor:pointer;}div:before {
  content: "";
  position: absolute;
  top: -webkit-calc(100% - 10px); /*may require prefix for old browser support*/
  top: calc(100% - 10px); /*i.e. half the height*/
  left: 20px;
  height: 20px;
  width: 20px;
  background: gray;
  transform: rotate(45deg);}
<div>Only element</div>

添加邊框

現(xiàn)在可以很容易地添加邊框,只需將邊界聲明添加到主元素,并將border-bottomborder-right的偽元素的inherit

邊界

div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor:pointer;
  border:3px double black;}div:before {
  content: "";
  position: absolute;
  top: -webkit-calc(100% - 10px); /*may require prefix for old browser support*/
  top: calc(100% - 10px); /*i.e. half the height*/
  left: 20px;
  height: 20px;
  width: 20px;
  background: gray;
  transform: rotate(45deg);
  border-bottom:inherit;
  border-right:inherit;
  box-shadow:inherit;}
<div>Only element</div>

方框陰影:

為了有一個(gè)盒子陰影,我使用了:after偽元素,以便將方框陰影隱藏在另一個(gè)偽元素上,使元素看起來像一個(gè)單一元素。

div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor:pointer;
  box-shadow: 5px 5px 10px 2px black;}div:before,div:after {
  content: "";
  position: absolute;
  top: -webkit-calc(100% - 10px); /*may require prefix for old browser support*/
  top: calc(100% - 10px); /*i.e. half the height*/
  left: 20px;
  height: 20px;
  width: 20px;
  background: gray;
  transform: rotate(45deg);z-index:-1;
  box-shadow:inherit;}div:after{
  box-shadow:none;
  z-index:8;
  }
<div>Only element</div>

把一切都放在一起

還可以使用“邊框半徑”屬性將邊框半徑再次添加到消息框或語音氣泡中:


div {

  height: 100px;

  width: 200px;

  background: gray;

  position: relative;

  cursor:pointer;

  border:3px double black;

  border-radius:10px;

}

div:before {

  content: "";

  position: absolute;

  top: -webkit-calc(100% - 10px); /*may require prefix for old browser support*/

  top: calc(100% - 10px); /*i.e. half the height*/

  left: 20px;

  height: 20px;

  width: 20px;

  background: gray;

  transform: rotate(45deg);

  border-bottom:inherit;

  border-right:inherit;

  box-shadow:inherit;

}

<div>Only element</div>

這甚至允許你不僅創(chuàng)建一個(gè)三角形,還可以用一個(gè)圓來代替它嗎?


div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor:pointer;
  border:3px double black;
  border-radius:10px;}div:before {
  content: "";
  position: absolute;
  top: -webkit-calc(100% - 13px); /*may require prefix for old browser support*/
  top: calc(100% - 13px); /*i.e. half the height + border*/
  left: 20px;
  height: 20px;
  width: 20px;
  background: gray;
  transform: rotate(45deg);
  border:3px double transparent;
  border-bottom:inherit;
  border-right:inherit;
  box-shadow:inherit;
  border-radius:50%;}
<div>Only element</div>

如果您有內(nèi)容溢出的問題,并且隱藏在這個(gè)偽元素后面,并且您不擔(dān)心有一個(gè)邊框,您可以使用一個(gè)負(fù)的z索引來解決這個(gè)問題。

不喜歡用“魔法數(shù)字”?

如果您不喜歡使用calc值的想法,其中我的答案中的位置當(dāng)前正在使用(同時(shí)工作),則可以使用transform:translate(50%)

這將是一個(gè)更好的辦法,因?yàn)椋?/trans>

  • 您不需要知道邊框的大小,也不需要知道寬度的一半。
  • 您將使您的消息框/氣泡的定位更加動(dòng)態(tài),并將支持進(jìn)一步的大小。

div {

  height: 100px;

  width: 200px;

  background: gray;

  position: relative;

  cursor: pointer;

  border: 3px double black;

  border-radius: 10px;

}

div:before {

  content: "";

  position: absolute;

  top: 100%;

  left: 30px;

  height: 20px;

  width: 20px;

  background: gray;

  box-sizing:border-box;

  transform: rotate(45deg) translate(-50%);

  border-bottom: inherit;

  border-right: inherit;

  box-shadow: inherit;

}

<div>Only element</div>

想移動(dòng)它嗎?你可以的!

div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor: pointer;
  border: 3px double black;
  border-radius: 10px;}div:before {
  content: "";
  position: absolute;
  top: 100%;
  left: 10%;
  height: 20px;
  width: 20px;
  background: gray;
  box-sizing: border-box;
  transform: rotate(45deg) translate(-50%);
  border-bottom: inherit;
  border-right: inherit;
  box-shadow: inherit;
  transition: all 0.8s;}div:hover:before {
  left: 90%;}
<div>Only element</div>

想要一個(gè)對(duì)嗎?

div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor: pointer;
  border: 3px double black;
  border-radius: 10px;}div:before {
  content: "";
  position: absolute;
  top: 15%;
  left: 100%;
  height: 20px;
  width: 20px;
  background: gray;
  box-sizing:border-box;
  transform: rotate(45deg) translate(-50%);
  border-top: inherit;
  border-right: inherit;
  box-shadow: inherit;
  transition:all 0.8s;}div:hover:before{
  top:80%;
  }
<div>Only Element</div>

希望它是一個(gè)不同的三角形形狀?

div {
  height: 100px;
  width: 200px;
  background: gray;
  position: relative;
  cursor: pointer;
  border-radius: 10px;}div:before {
  content: "";
  position: absolute;
  top: 70%;
  left: 100%;
  height: 20px;
  width: 20px;
  background: gray;
  box-sizing:border-box;
  transform:  translate(-50%) skewX(45deg);
  box-shadow: inherit;
  transition:all 0.8s;
  z-index:-1;}div:hover:before{
  transform:  translate(-50%);
  border-radius:50%;
  top:20%;
  }
<div>Only Element</div>


查看完整回答
反對(duì) 回復(fù) 2019-06-18
  • 3 回答
  • 0 關(guān)注
  • 402 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)