【问题标题】:Working with css before selector在选择器之前使用 css
【发布时间】:2015-11-24 14:35:20
【问题描述】:

我正在尝试将一个图像重叠在另一个图像上并从中制作一个圆形图像。

    <span onclick="someFunction()" id="swatch_123456" class="slider-color-swatches" style="background-image: url(anyImage.png);"></span>

.slider-color-swatches{
    position: relative;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-block;
    vertical-align: top;
    overflow: hidden;
    margin-bottom: 10px;
    margin-right: 10px;
}
.slider-color-swatches::before{
    content: '';
    position: absolute;
    background-image: url('anyOtherIamge.pnenter image description hereg');
    left: 20%;
    width: 100%;
    height: 200%;
    top: 0;
    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    transform: rotate(45deg);
}

Here are the images as to what I want to do and where Iam able to get so far

【问题讨论】:

标签: jquery html css css-selectors


【解决方案1】:

试试这个.. 可以工作..

{
    width: 28px;
    height: 28px;
    overflow: hidden;
    display: block;
    border-radius: 50%;
    -moz-border-radius: 50%;
    -webkit-border-radius: 50%;
    margin-bottom: 10px;
    -webkit-transition: all 0.3s ease-out;
    -moz-transition: all 0.3s ease-out;
    -o-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
    margin: 0 auto;
}

【讨论】:

    【解决方案2】:

    尝试将display: block; 添加到您的::before 元素中。 这样做会使您的宽度和高度生效。

    另外,添加margin: auto; 将使其居中。

    示例:

    .slider-color-swatches::before {
        content: '';
        position: absolute;
        display: block;
        margin: auto;
        background-image: url('anyOtherIamge.pnenter image description hereg');
        left: 20%;
        width: 100%;
        height: 200%;
        top: 0;
        -webkit-transform: rotate(45deg);
        -moz-transform: rotate(45deg);
        transform: rotate(45deg); }
    

    如果您想尝试不同的方法,请查看clipping and masking

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-08
      • 2021-12-23
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多