繁体   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