簡體   English   中英

重疊頭像:將SCSS轉換為CSS,將PUG轉換為HTML

[英]Overlapping avatars: convert SCSS to CSS and PUG to HTML

我正在嘗試在HTML和CSS中創建重疊的頭像。 它基於此代碼段。 僅此片段在SCSS和PUG中創建。 如何將PUG轉換為HTML,如何將SCSS轉換為CSS? 我遇到一個問題,化身彼此距離很遠,並且當您將鼠標懸停在化身上時,該名稱沒有出現。

在這里檢查代碼。

import React from 'react';
import { render } from 'react-dom';

import './style.css';

class App extends React.Component {
  constructor() {
    super();
    this.state = {
     todos: 
          [
            {name:'Tobias', avatar: 'https://vignette.wikia.nocookie.net/arresteddevelopment/images/7/77/2x01_The_One_Where_Michael_Leaves_%28098%29.png/revision/latest?cb=20121126025806'},
            {name:'Lindsey', avatar: 'https://vignette.wikia.nocookie.net/arresteddevelopment/images/1/16/Season_3_Character_Promos_-_Lindsay_Bluth_F%C3%BCnke_01.jpg/revision/latest?cb=20111027201233'},
            {name:'Buster', avatar: 'https://vignette.wikia.nocookie.net/arresteddevelopment/images/b/be/Season_3_Character_Promos_-_Buster_Bluth_01.jpg/revision/latest?cb=20111027201440'},
            {name:'George Michael', avatar: 'https://vignette.wikia.nocookie.net/arresteddevelopment/images/c/c3/Season_1_Character_Promos_-_George_Michael_Bluth_02.jpeg/revision/latest?cb=20120429230332'},
            {name:'Gob', avatar: 'https://vignette.wikia.nocookie.net/arresteddevelopment/images/0/02/Season_1_Character_Promos_-_G.O.B.jpeg/revision/latest?cb=20120429230530'},
            {name:'Michael', avatar: 'https://vignette.wikia.nocookie.net/arresteddevelopment/images/1/10/1x01_Pilot_%2839%29.png/revision/latest?cb=20120301050056'}
          ],
    };
  }

  render() {
    let todos = this.state.todos.map((todo, index) =>
      <Todo
        key={index}
        index={index}
        todo={todo}

      />
    )
    return (
      <div>
        <ul>{todos}</ul>
      </div>
    );
  }
}

class Todo extends React.Component {
  render() {
    const  Background = this.props.todo.avatar;
    const  name = this.props.todo.name;


const profile = {
    "&:hover&:after": {
      position: "absolute",
      content: `attr(${name})`,
      background: "rgba(255, 255, 255, .95)",
      color: "inherit",
      fontSize: "10px",
      padding: "4px",
      width: "auto",
      bottom: "-0.5rem",
      right: "-0.5rem",
      boxShadow: "0px 5px 12px rgba(0, 0, 0, .12)",
      opacity: "0",
      borderRadius: "0.15rem",
      animation: "fade 100ms ease 750ms forwards"
    } 
  }

    return (
      <ul className="c-profile__list">
        <li style={profile} className="c-profile" style={{backgroundImage: `url(${Background})`}}></li>
      </ul>
    );
  }
}

render(<App />, document.getElementById('root'));

的CSS

html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}
html, body {
  width: 100%;
  height: 100%;
}
body {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui;
  flex-direction: column;
  color: #2c2c54;
  font-size: 1.6rem;
}
.c-profile {
  width: 70px;
  height: 70px;
  border: 4px solid white;
  border-radius: 50%;
  box-shadow: 0px 3px 8px rgba(44, 44, 84, .2);
  display: inline-block;
  background: white;
  cursor: pointer;
  background-size: cover;
  background-position: center center;
  transition: all 200ms ease;
}
.c-profile:nth-of-type(n+2) {
  margin-left: -42px;
}
.c-profile:hover {
  transform: scale(1.2);
  box-shadow: 0px 8px 20px rgba(44, 44, 84, .2);
}
.c-profile:hover:after {
  position: absolute;
  content: attr(username);
  background: rgba(255, 255, 255, .95);
  color: inherit;
  font-size: 10px;
  padding: 4px;
  width: auto;
  bottom: -0.5rem;
  right: -0.5rem;
  box-shadow: 0px 5px 12px rgba(0, 0, 0, .12);
  opacity: 0;
  border-radius: 0.15rem;
  animation: fade 100ms ease 750ms forwards;
}
.c-profile__list {
  display: flex;
  position: relative;
  width: auto;
  padding-top: 1rem;
  padding-bottom: 1rem;
}
.c-profile__list:hover .c-profile:nth-of-type(n+2) {
  margin-left: 7px;
}
article {
  width: 100%;
  max-width: 600px;
}
@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

ul {
  list-style: none;
  display: inline;
}

從短視...

您正在將ul標簽包裝在父ul 快速解決:

https://stackblitz.com/edit/react-ctuy4n?file=index.js

Todo ,您需要刪除每個項目周圍的其他<ul>標簽,並將您的name添加為title道具:

return (
        <li style={profile} className="c-profile" title={name} style={{backgroundImage: `url(${Background})`}}></li>
    );

暫無
暫無

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

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