簡體   English   中英

:after&:before背景img不顯示

[英]:after & :before background img not showing

我正在嘗試向div中添加框架設計,如下例所示:

金框div設計

我嘗試使用背景圖片進行此操作,但由於它必須具有響應性,因此無法正常運行。 現在,我嘗試使用(:before&:after)進行此操作,但是圖像不會出現。 我在后面留下一行代碼了嗎? 幫助贊賞!

問題:問題 圖片

// HTML

<div class="second-section">
<div class="container">
  <div class="purp-box">
    <h1>Welcome to my site!</h1>
    <p>Some text goes here.</p>
  </div>
</div>

// CSS

.purp-box {
  height: 303px;
  background: url(../images/box-background.png);
}

.purp-box:after,
.purp-box:before {
  content: '';
  position: absolute;
  top: 0;
}

.purp-box:before {
  width: 67px;
  height: 303px;
  background: url(../images/purp-left-border.png) no-repeat;
  right: 100%;
}

.purp-box:after {
  width: 67px;
  height: 303px;
  background: url(../images/purp-right-border.png) no-repeat;
  left: 100%;
}

我知道了,我要做的就是將(box-sizing:border-box;)&(position:relative;)添加到主div中。 謝謝您也建議使用圖像邊框。

.purp-box {
  height: 303px;
  background: url(../images/box-background.png);
  box-sizing: border-box;
  position: relative;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM