Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前端面试题集: No.0001 使用 js 对 CSS 的 ::before & ::after 伪元素进行操作 #2

Open
xgqfrms opened this issue Aug 11, 2022 · 0 comments
Labels
高级 高级

Comments

@xgqfrms
Copy link
Owner

xgqfrms commented Aug 11, 2022

前端面试题集: No.0001 使用 js 对 CSS 的 ::before & ::after 伪元素进行操作

试题难度

高级

考察点

  1. 高级 API 的掌握情况
  2. 知识面广度与深度

demo

<a href="https://cdn.xgqfrms.xyz/logo/icon.png" class="logo"></a>
a::before {
  box-sizing: border-box;
  display: block;
  width: 300px;
  height: 300px;
  font-size: 37px;
  font-weight: bold;
  color: #000;
  padding-top: 30px;
  text-align: center;
  content: "xgqfrms's logo";
  background: url('https://cdn.xgqfrms.xyz/logo/icon.png') no-repeat;
}
const dom = document.querySelector('a');
const url = getComputedStyle(dom, ':before').getPropertyValue('background-image');
console.log(`::before url =`, url);

/*
"::before url =" "url('https://cdn.xgqfrms.xyz/logo/icon.png')"
*/

codepen live demo

https://codepen.io/xgqfrms/pen/OJvojyJ

试题来源/试题出处

https://stackoverflow.com/questions/44342065/how-to-get-a-dom-elements-before-content-with-javascript

@xgqfrms xgqfrms added the 高级 高级 label Aug 11, 2022
@xgqfrms xgqfrms changed the title 使用 js 对 CSS 的 ::before & ::after 伪元素进行操作 前端面试题集: N0001. 使用 js 对 CSS 的 ::before & ::after 伪元素进行操作 Aug 11, 2022
@xgqfrms xgqfrms changed the title 前端面试题集: N0001. 使用 js 对 CSS 的 ::before & ::after 伪元素进行操作 前端面试题集: No.0001 使用 js 对 CSS 的 ::before & ::after 伪元素进行操作 Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
高级 高级
Projects
None yet
Development

No branches or pull requests

1 participant