css - 选择选项未显示在移动设备上

标签 css styled-components

使用 react 和 styled-components 我已经设法编写了一个小组件来提问并显示一个包含 5 个选项/开始的栏供用户选择。

它应该是这样的:

enter image description here

它在桌面上一切正常,但在移动浏览器(Android 或 IOS)上查看时,用户会看到:

enter image description here

下面是我完整的 react 组件,知道我做错了什么吗?

import React, {Component} from 'react';
import styled from 'styled-components';
import _ from 'lodash';

class Question extends Component {
    constructor(props) {
        super(props);
        this.state = {
            value: props.value
        }
        this.handleChange = this.handleChange.bind(this);
    }
    handleChange(event) {
      this.setState({
          value: event.target.value
      });
      this.props.onChange(event);
    }
    render() {
      const {name, value, totalStars, caption} = this.props;
        return (
            <Container className="rateOptions">
                <Caption>{caption}</Caption>
                <Rating name={name} size={totalStars - 1} onChange={this.handleChange}>
                    {_.range(1, totalStars).reverse().map(function(object) {
                      if(object.toString() ===value)
                        return <option selected value={object.toString()} key={object.toString()}>☆</option>
                      return <option value={object.toString()} key={object.toString()}>☆</option>
                    })}
                </Rating>
                <RateValue>
                    {this.state.value}
                    / 5
                </RateValue>
            </Container>
        );
    }
}
export default Question;

const Rating = styled.select `
  background: none;
  font-size:30px;
  color: gold;
  unicode-bidi: bidi-override;
  direction: rtl;
  text-align: center;
  overflow: hidden;
  margin: 10px 0;
  height: 35px;
  outline: 0;
  border:none;
  float: left;
  -webkit-appearance: none;
  -moz-appearance: none;
  > option {
    display: inline-block;
    position: relative;
    cursor: pointer;
  }
  > option:hover, > option:hover ~ option, > option:checked, > option:checked ~ option {
     color: transparent;
  }
  > option:hover:before, option:hover ~ option:before, option:checked:before, option:checked ~ option:before {
     content: "★";
     position: absolute;
     color: gold;
     text-shadow: 2px 2px 1px #000;
  }
  > option:hover, option:checked, option:active, option:focus {
    box-shadow: 0 0 10px 100px #000 inset;
  }
  `;
const Container = styled.div `
  clear: both;
`;
const Caption = styled.div `
  font-size: 1.2em;
`;
const RateValue = styled.div `
  float: left;
  padding:20px 10px;
`;

最佳答案

您必须调用选择选项的刷新方法来更新其视觉样式。

希望这会奏效。

关于css - 选择选项未显示在移动设备上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45236118/

相关文章:

html - 将汉堡菜单对齐到屏幕右侧

html - 无法点击链接;考虑重叠(填充?边距?)

css - 无法使用样式化组件和 Next.js 导入 Google 字体

reactjs - 为什么在安装完 styled-components 后还需要安装 gatsby-plugin-styled-components

javascript - React 中有全局 onClick 函数吗?

javascript - D3 折叠树 : Scrollable container for tree

css - 我的 div 中的背景颜色未显示

html - 文本不在 div 内背景图像的中间

javascript - 带有样式组件的不受控制的子组件

typescript - 如何使用 Material UI 和 TypeScript 将自定义 Prop 传递给样式化组件?