小编Nek*_*oru的帖子

Ruby - 单引号和双引号之间的区别是什么?

所以我正在关注这个Ruby教程:以艰难的方式学习Ruby.

在练习16(上面链接)中,您编写了一个将行写入文件的脚本.相关代码是:

print "line 1: "; line1 = STDIN.gets.chomp()
print "line 2: "; line2 = STDIN.gets.chomp()
print "line 3: "; line3 = STDIN.gets.chomp()

puts "I'm going to write these to the file."

target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
Run Code Online (Sandbox Code Playgroud)

然而,作为我的懒惰屁股,我最初使用最后六行中的单引号键入示例,而不是教程告诉您使用的双引号.

这对文件有影响.当我使用单引号时,文件看起来像这样:

this is line 1\nthis is line 2\nthis is line 3
Run Code Online (Sandbox Code Playgroud)

将这些引号切换为双引号后,该文件看起来像预期的那样:

this is line 1
this is line 2
this is line 3
Run Code Online (Sandbox Code Playgroud)

有人能告诉我究竟是为什么吗?单引号字符串只是忽略转义字符,如\n\t

ruby

12
推荐指数
1
解决办法
6347
查看次数

如何在CSS中创建动态宽度箭头?

我需要编写一个页面底部有一个全宽箭头的页面.因此,我使用以下HTML:

<div id="footer_wrap">
    <div id="footer_left"></div>
    <div id="footer_right"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

相关的CSS是:

#footer_wrap{
width: 100%;
}

#footer_left{
background: url('../img/arrow_bg1.png') repeat-x;
width: 100%;
height: 183px;
position: absolute;
left: 0;
}

#footer_right{
display: inline-block;
background: url('../img/arrow_bg2.png') no-repeat;
width: 250px;
height: 183px;
position: absolute;
right: 0;
}
Run Code Online (Sandbox Code Playgroud)

理论上,当我使用具有固定背景颜色的图像时,这应该有效 - 事实上,它确实有效.然而,我的客户要求他们保持透明,不幸的是,这显示了我黑客背后的丑陋真相 - 箭头的"轴"从箭头头部偷看.我能做些什么呢?

包含箭头的图像是1x183px"轴"纹理,其在箭头的整个长度(或者,在这种情况下,整个页面[width: 100%])重复,并且箭头是250x183px矩形.

箭头需要占用整个页面,并且需要使用透明图像,因此这些解决方案立即就在窗外.我认为类似的东西是width: 100%-250px可以接受的,但CSS中不支持这些恶作剧.

html css

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

标签 统计

css ×1

html ×1

ruby ×1