帶有偽 css 的背景顏色層 (Background color layer with pseudo css)


問題描述

帶有偽 css 的背景顏色層 (Background color layer with pseudo css)

 .product‑item‑info::after {
            background‑color: #e3e3e3;
            content:" ";
           height:300px;
            width:300px;
        }

.product‑item‑info {
    height: 300px;
}
<div class="product‑item‑info"></div>

是否可以將顏色背景層創建為偽元素,我現在嘗試但不起作用

.product‑item‑info:after {
    background‑color: #e3e3e3;
    content:"";
    height:300px;
    width:400px;
}

參考解法

方法 1:

::before and ::after are display: inline by default. You'll want to set display: block for your width and height properties to be applied:

.product‑item‑info::after {
    background‑color: #e3e3e3;
    content:" ";
    height: 300px;
    width: 300px;
    display: block; /* this is what you need */
}

.product‑item‑info {
    height: 300px;
    background‑color: red; /* for demonstration purposes */
}
<div class="product‑item‑info"></div>

方法 2:

Here is an example of what you are trying to do.

Also for pseudo elements you should use "::"

.product‑item‑info {
  width: 300px;
  height: 300px;
  border: 1px solid red;
  position: relative;
}
.product‑item‑info::before {
  background‑color: lightgreen;
  content: " ";
  height: 150px;
  width: 150px;
  position: absolute;
  top: 0;
  left: 0;
}
.product‑item‑info::after {
  background‑color: lightblue;
  content: " ";
  height: 150px;
  width: 150px;
  position: absolute;
  bottom: 0;
  right: 0;
}
<div class="product‑item‑info"></div>

(by fefeAndré Diondimshik)

參考文件

  1. Background color layer with pseudo css (CC BY‑SA 2.5/3.0/4.0)

#css #pseudo-element






相關問題

在圖像上淡入文本 (Fade in text over an image)

可以使用 css3 轉換輪廓顏色 (possible to transition outline color with css3)

以背景色為條件的 if 語句 (If statement with background color as condition)

Nội dung từ <p> biến mất khi tôi quay lại trang (Content from <p> disappears when I return to the page)

當按鈕向右浮動時,ng-click 不起作用 (ng-click doesn't work when the button is floated to the right)

帶有偽 css 的背景顏色層 (Background color layer with pseudo css)

是否可以製作離線工作的網絡應用程序? (Is it possible to make a web-app which works offline?)

chrome中帶有省略號的多行文本問題 (issue with multiline text with ellipsis in chrome)

將字符串轉換為類的安全名稱 (Convert string to safe name for class)

絕對定位跨度收縮 (Absolute Positioned Span Shrinks)

如何設置單選按鈕的樣式,使其看起來像普通的可點擊按鈕? (How do I style a radio button to look like a normal clickable button?)

無法獲得白色和灰色的 CSS 進度條 (Not able to get the CSS progress bar with white and grey)







留言討論