小编Rob*_*ert的帖子

python中的字母位置

新手在这里...尝试编写一个函数,该函数接受一个字符串并将所有字符替换为其各自的字典值。这是我所拥有的:

def alphabet_position(text):

    dict = {'a':'1','b':'2','c':'3','d':'4','e':'5','f':'6','g':'7','h':'8':'i':'9','j':'10','k':'11','l':'12','m':'13','n':'14','o':'15','p':'16','q':'17','r':'18','s':'19','t':'20','u':'21','v':'22','w':'23','x':'24','y':'25','z':'26'}
    text = text.lower()
    for i in text:
        if i in dict:
            new_text = text.replace(i, dict[i])
    print (new_text)
Run Code Online (Sandbox Code Playgroud)

但是当我运行时:

alphabet_position("The sunset sets at twelve o' clock.")
Run Code Online (Sandbox Code Playgroud)

我得到:

the sunset sets at twelve o' cloc11.
Run Code Online (Sandbox Code Playgroud)

这意味着它只更改字符串中的最后一个字符。有任何想法吗?非常感谢任何输入。

python

3
推荐指数
1
解决办法
6205
查看次数

CSS 背景图像带旋转、重复和不透明度

我正在尝试用图像制作一个漂亮的背景,但我希望重复图像以填充屏幕,不透明度设置为 0.5 并旋转 45 度。我尝试了很多方法来实现这一目标,但没有成功。有人有主意吗?

在此 Codepen 中,我将图像旋转且不透明,但无法使背景重复工作。

.background {
  height: 500px;
  width: 500px;
  position: relative;
  display: inline-block;
  padding: 100px;
  border: black 3px solid;
}

.background::before {
  content: "";
  position: absolute;
  overflow: hidden;
  width: 100px;
  height: 100px;
  left: 0;
  top: 0;
  z-index: -1;
  opacity: 0.5;
  background: url(https://cambridgewords.files.wordpress.com/2019/11/funny.jpg);
  background-size: contain;
  transform: rotate(45deg);
  background-repeat: repeat;
  opacity: 0.5;
}
Run Code Online (Sandbox Code Playgroud)
<span class='background'>HElloWorld</span>
Run Code Online (Sandbox Code Playgroud)

html css background-image

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

background-image ×1

css ×1

html ×1

python ×1