我想在小窗口中显示图像,但我需要节省图像的比例(我仍然希望人们可以知道它是什么).例如,假设图像是1000X200像素,并且有一个div定义为:height:100px; 宽度:100px; 所以我希望图像会像这样写:
<img src="asd.jpg" height=20 width=100 />
Run Code Online (Sandbox Code Playgroud)
并不是
<img src="asd.jpg" height=100 width=100 />
Run Code Online (Sandbox Code Playgroud)
或不
<img src="asd.jpg"/>
Run Code Online (Sandbox Code Playgroud)
然后是卷轴..
我可以使用百分比,但我该怎么做..(它甚至可以单独使用百分比吗?)
Twitter有一个很好的功能,允许您使用以下格式预加载状态消息:
http://twitter.com/?status=@HelloWorld Hello World
Run Code Online (Sandbox Code Playgroud)
或者:
http://twitter.com/?status=%40HelloWorld%20Hello%20World
Run Code Online (Sandbox Code Playgroud)
我正在尝试在我的iPhone应用程序中添加一个按钮,该按钮将打开Safari以上预先填充的推文.
但是我遇到了百分号被双重逃逸的问题.
这是我尝试过的代码:
NSString* urlText = @"http://www.twitter.com/home?status=@HelloWorld";
NSURL *url = [NSURL URLWithString: urlText];
if (![[UIApplication sharedApplication] openURL:(NSURL*)url])
NSLog(@"%@%@",@"Failed to open url:",[url description]);
Run Code Online (Sandbox Code Playgroud)
此代码的作用类似于魅力和输出:
http://twitter.com/?status=%40HelloWorld
Run Code Online (Sandbox Code Playgroud)
NSString* urlText = @"http://www.twitter.com/home?status=@HelloWorld Hello World";
NSURL *url = [NSURL URLWithString: urlText];
if (![[UIApplication sharedApplication] openURL:(NSURL*)url])
NSLog(@"%@%@",@"Failed to open url:",[url description]);
Run Code Online (Sandbox Code Playgroud)
这会创建一个null NSURL.我只能假设因为URLWithString不接受带有空格的文本.
所以我尝试了这段代码:
NSString* urlText = @"http://www.twitter.com/home?status=@HelloWorld%20Hello%20World";
NSURL *url = [NSURL URLWithString: urlText];
if (![[UIApplication sharedApplication] openURL:(NSURL*)url])
NSLog(@"%@%@",@"Failed to open url:",[url description]);
Run Code Online (Sandbox Code Playgroud)
但是,这会创建URL:
http://twitter.com/?status=%40HelloWorld%2520Hello%2520World
Run Code Online (Sandbox Code Playgroud)
所以我已经逃过了我的百分号%,这当然不是我想要的.
当然人们一直在谈论使用函数:stringByAddingPercentEscapesUsingEncoding
所以我写了这段代码: …
当在变量中保持百分比值时,将它们保持为整数与分数之间存在偏好.那个变量应该保持0到100之间或0.00到1.00之间的数字吗?在任何一种情况下,保存值的变量都是十进制类型.
我正在与之交互的数据库恰好将它们存储为0到100的整数.
注意:我使用"整数"这个词来表示0到100范围内的值,尽管这些值可能包含小数分量(例如,25.75).我不知道如何描述两个百分比值范围之间的差异
我正在读关于CSS的文章.我发现许多作者建议使用%值来表示div的宽度或高度.
我一直在使用像素.
为什么我应该使用%的值来表示div的宽度或高度而不是像素?
有什么好处?
我正在尝试使用jQuery获取元素的CSS(顶部和左侧):
$(element).css('top');
Run Code Online (Sandbox Code Playgroud)
但不是像它应该的"12%",我得到了像素.
我如何获得百分比?
HTML:
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<style type="text/css">
.parWrapper {
position:absolute;
top: 40%
}
</style>
</head>
<body>
<div>
<div id="crap" class="parWrapper" style="left:50%">
Wrap1
</div>
<div class="parWrapper">
Wrap2
</div>
<div class="parWrapper">
Wrap3
</div>
<div class="parWrapper">
Wrap4
</div>
<div class="parWrapper">
Wrap5
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud) 在处理jQuery UI范围滑块时,我主要使用chrome进行调试.我需要让范围有一个限制所以我会抓住其中一个手柄的左侧位置,如下所示:
$el.css('left');
哪个会给我左边的位置百分比:84%.但是,当我在Firefox中测试时,它返回的值以像素为单位.
有谁之前经历过这个吗?基于在Firebug中查看DOM,Firefox确实识别基于百分比的左侧定位,但它似乎并未将其作为值返回.这是Firefox的默认行为吗?在IE中也是如此吗?
我有一些存储在数据库中的十进制数,需要使用PHP计算两个数字之间的百分比增加(或减少).
两个数字的一个例子是:111.0516和111.9052,将增加0.7628%
我在某个地方找到了以下代码.不幸的是它似乎不适用于十进制数并将它们四舍五入:
$num_amount = 111.0516;
$num_total = 111.9052;
function percent($num_amount, $num_total) {
$count1 = $num_amount / $num_total;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
echo $count;
}
percent($num_amount, $num_total);
Run Code Online (Sandbox Code Playgroud)
理想情况下,我需要计算两位小数的百分比,给出0.77%的答案.
这可能用PHP吗?我很难过.我的PHP或数学技能都不足以解决问题.
我有一个由两个数字的差异产生的,但它返回例如0,77为7%和0,5为50%我只想修复到达这些goar,如15,2%13%等等上.我怎样才能做到这一点?c#有什么东西嵌入CLR才能做到这一点吗?
如何调试css的方向:Chrome Developer工具中的肖像?
我写的内容 (orientation:portrait)无法通过Firebug和Chrome Developer工具动态编辑.它始终显示正常的属性.
/*normal styles here */
#wrap {
width:1024px;
}
@media only screen and (orientation:portrait){
/* portrait styles here */
#wrap {
width:768px;
}
}
Run Code Online (Sandbox Code Playgroud) 我在firefox上检索确切的css属性值(在'%'中)时遇到问题.
假设我们有这个非常简单的标记:
<div id="box">box</div>
Run Code Online (Sandbox Code Playgroud)
这个css:
#box{
width:200px;
height:200px;
left:10%;
position:absolute;
background:red;
}
Run Code Online (Sandbox Code Playgroud)
而我想找回左侧位置被JS(在"%")
使用mootools很简单(演示 - > http://jsfiddle.net/steweb/AWdzB/):
var left = $('box').getStyle('left');
Run Code Online (Sandbox Code Playgroud)
或jQuery(演示 - > http://jsfiddle.net/steweb/RaVyU/):
var left = $('#box').css('left');
Run Code Online (Sandbox Code Playgroud)
或者通过普通的js(演示 - > http://jsfiddle.net/steweb/tUAKA/):
function getStyle(el,styleProp){ //from ppk's quirksmode
var x = document.getElementById(el);
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;
}
var left = getStyle('box','left');
Run Code Online (Sandbox Code Playgroud)
但是如果你在firefox(8.0.1)上尝试它,你会发现结果不正确(应该是10%,但它是91px).问题是:这个较新版本的Firefox有没有错误?有谁知道这是一个已知的错误?难道我做错了什么?
谢谢 :)
更新:我也尝试过较旧的firefox版本,并且它不正确(它总是返回px值)..为了完整性,它在IE上正常工作