用字符实现上下箭头

今天看了http://www.zhangxinxu.com/wordpress/2011/08/%e5%b0%8f%e5%8d%96%e5%bc%84%ef%bc%9a%e5%ad%97%e7%ac%a6%e4%b8%8a%e4%b8%8b%e5%8d%8a%e6%88%aa%e7%9a%84%e9%ab%98%e4%ba%ae%e6%98%be%e7%a4%ba/

发现点子确实不错, 但是作者的兼容性没做好, 多浏览器下一塌糊涂(包括ff4). 于是决心自己写一遍. 折腾了两个小时, 蛋疼...


代码贴出来, 以兹参考.

有关css hack部分, 我发现这篇真的很有帮助.http://blog.csdn.net/sunxing007/article/details/6598327

效果图:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Diamond arrow</title>
<style>
	.diamond{
		/**是内部两个子元素位置参考的基石**/
		position: relative; 
		font-family: simsun;
		font-size: 12px;
		height: 15px;
		width: 12px;
		/**使整个diamond像字符一样显示, 有利于与前后的元素水平对齐排版**/
		display: inline-block;
		vertical-align: middle;/**这个你懂的**/
	}
	/**触发ie6, ie7的layout,使之像inline-block那样**/
	.diamond{
		*display: inline;
	}
	
	.diamond-top{
		position: absolute;
		height: 6px;
		/*for ie6*/
		*height: 8px;
		overflow: hidden;
		border-bottom: solid #fff 3px;
		/*for ie6,ie8*/
		border-bottom: solid #fff 2px\9;
		
	}

	/*for ie7*/
	*+html .diamond-top{
		height: 6px;
	}
	
	.diamond-bottom{
		position: absolute;
		top: 4px;
		/*for ie6*/
		top: 3px\9;
	}
	
	.diamond .sorted{
		color: red;
	}
	

</style>   
</head>

<body>
	<br /><br /><br />
	Price <div class="diamond">
		<span class="diamond-bottom">◆</span>
		<span class="diamond-top sorted">◆</span>	
	</div>  Price
	<div class="diamond">
		<span class="diamond-bottom sorted">◆</span>
		<span class="diamond-top">◆</span>	
	</div>
</body>
</html>

您提到的图案似乎是在描述一种字符串转换过程,其中每个字符按照箭头的方向移动到下一个位置,并且有特定的限制,比如@记号的数量不超过10个。为了编写这样的函数,我们需要更多的具体规则,例如: 1. 箭头的方向(左、右、上、下还是混合) 2. 当字符到达边界时的行为(是否翻转、循环、停止等) 3. @记号的特殊处理规则 假设箭头指示的是简单的上下左右四个方向移动,我们可以创建一个二维数组来存储变换后的结果,并根据输入的源字符串和移动规则进行逐个字符的处理。这里是一个基础的Python函数示例,但我们需要具体的规则才能写出完整的函数: ```python def transform_string(input_str, rules): # rules应该包含移动方向和@的位置规则 if len('@') > 10: return "Error: Too many '@' symbols." transformed_array = [[' ' for _ in range(len(input_str))] for _ in range(2)] # 初始化两行数组 direction_dict = {'U': (-1, 0), 'D': (1, 0), 'L': (0, -1), 'R': (0, 1)} # 上下左右对应偏移量 for char in input_str: if char == '@': transformed_array[1][transformed_array[0].index(char)] = char # 将@直接放到第二行对应的位 else: current_index = (0, 0) # 初始化当前位置 for move_dir in rules: current_index = tuple(map(sum, zip(current_index, direction_dict[move_dir]))) if current_index[0] < 0 or current_index[1] < 0 or \ current_index[0] >= len(transformed_array[0]) or current_index[1] >= len(transformed_array[1]): break # 边界处理,如超出则停止 transformed_array[1][current_index] = char # 移动并替换字符 return transformed_array # 使用示例: input_str = "@AABCD" rules = ['U', 'R', 'D', 'L'] # 假设箭头指示这些方向 output_array = transform_string(input_str, rules) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值