padding

计算每行所占字符个数,并格式化输出

删除回忆录丶 提交于 2019-11-27 04:09:33
import scala.io.Source def widthOfLength(s: String) = s.length.toString.length // 计算字符串长度的位数,比如长度为:136,则位数为:3(三位数) if (args.length > 0 ) { val lines = Source.fromFile(args(0 )).getLines.toList val longestLine = lines.reduceLeft( (a, b) => if (a.length > b.length) a else b ) val maxWidth = widthOfLength(longestLine) for (line <- lines) { val numSpaces = maxWidth - widthOfLength(line) val padding = " " * numSpaces println(padding + line.length + "|" + line) } } else Console.err.println( "Please enter filename") 转载于:https://www.cnblogs.com/ivan0626/p/4201620.html 来源: https://blog.csdn.net/weixin

Material组件之MaterialApp、Scaffold、AppBar学习笔记

人盡茶涼 提交于 2019-11-27 03:33:40
一、MaterialApp flutter的路由方式有两种:新建路由和注册路由 1.1 新建路由 Navigator.push负责将新建的路由添加到Navigator管理的route堆栈的栈顶,Navigator.pop用于弹出route堆栈最顶层的Route。其中页面进入动画是向上滑动并淡出,退出动画是向下滑动并淡出。 import 'package:flutter/material.dart' ; void main ( ) = > runApp ( MyApp ( ) ) ; class MyApp extends StatelessWidget { @override Widget build ( BuildContext context ) { return MaterialApp ( title : 'Flutter Demo' , home : FirstPage ( ) , ) ; } } class FirstPage extends StatelessWidget { @override Widget build ( BuildContext context ) { // TODO: implement build return Scaffold ( appBar : AppBar ( title : Text ( '这是第一页' ) , ) , body :

前端学习 之 CSS(三)

∥☆過路亽.° 提交于 2019-11-27 02:49:12
九 :浮动 浮动是 css 里面布局最多的一个属性,也是很重要的一个属性。 float :表示浮动的意思。 属性值: none: 表示不浮动,默认 left: 表示左浮动 right :表示右浮动 例: html 内容: <div class="box1">第一个div</div> <div class="box2">第二个div</div> <span>一个span</span> View Code css 内容: *左浮动*/ .box1 { width: 300px; height: 300px; background-color: red; float: left; } /*右浮动*/ .box2 { width: 400px; height: 400px; background-color: green; float: right; } /*左浮动*/ span { float: left; width: 100px; height: 200px; background-color: yellow; } View Code 效果图: 出现的效果图,三个元素并排显示, .box1 和 span 因为是左浮动,紧挨在一起,这种现象贴边。 .box2 盒子因为右浮动,所以紧靠着右边。 浮动四大特性的学习是必不可少的: 1. 浮动的元素脱标 2. 浮动的元素互相贴靠 3.

How do I prevent the padding property from changing width or height in CSS?

房东的猫 提交于 2019-11-27 02:25:00
I am creating a site with DIV s. Everything's working out except when I create a DIV. I create them like this (example): newdiv { width: 200px; height: 60px; padding-left: 20px; text-align: left; } When I add the padding-left property, the width of the DIV changes to 220px, and I want it to remain at 200px. Let's say I create another DIV named anotherdiv exactly the same as newdiv , and put it inside of newdiv but newdiv has no padding and anotherdiv has padding-left: 20px . I get the same thing, newdiv 's width will be 220px. How can I fix this problem? Pramod Add property: -webkit-box-sizing

Padding a swift String for printing

我怕爱的太早我们不能终老 提交于 2019-11-27 02:03:04
问题 I'm trying to print a list of Strings all padded to the same width. In C, I would use something like printf("%40s", cstr), where cstr is a C string. In Swift, the best I could come up is this: line += String(format: "%40s",string.cStringUsingEncoding(<someEncoding>)) Is there a better way ? 回答1: For Swift >= 3 line += string.padding(toLength: 40, withPad: " ", startingAt: 0) For Swift < 3 NSString has the stringByPaddingToLength: method: line += string.stringByPaddingToLength(40, withString:

Center text in div?

混江龙づ霸主 提交于 2019-11-27 01:45:48
问题 I have a div 30px high and 500px wide. This div can contain two lines of text one under the other, and is styled (padded) accordingly. But sometimes it only contains one line, and I want it to be centered. Is this possible? 回答1: To center horizontally, use text-align:center . To center vertically, one can only use vertical-align:middle if there is another element in the same row that it is being aligned to. See it working here. We use an empty span with a height of 100%, and then put the

Get rid of spaces between spans

那年仲夏 提交于 2019-11-27 01:28:13
问题 I'm trying to emulate a tab bar with HTML. I'd like the width of each tab to be set according to the text length (that is, no fixed width) and to word wrap in case it exceeds the screen width. I've almost achieved it: <html> <head> <style type="text/css"> #myTabs .tab { float: left; } #myTabs .tab_middle { margin: 0; padding: 0; border: none; background-image:url('images/tabs/tab_middle.png'); } #myTabs .tab_left { margin: 0; padding: 0; border: none; background-image:url('images/tabs/tab

盒子两种模型

♀尐吖头ヾ 提交于 2019-11-27 00:55:14
什么是盒子模型? 盒子模型(框模型)是css部分非常重要的一部分知识,CSS在处理网页的时候,认为每个元素都处在一个不可见的盒子中。盒子模型的构想,把所有的元素都想象成盒子,那么对网页进行布局的时候就可以理解为对盒子进行排列。至于要将相应的盒子摆放到网页相应的位置中即可完成页面布局。CSS 盒子模型 (Box Model) 规定了元素框处理元素内容、内边距,边框和外边距的方式盒子模型包括width宽度,height高度,border边框,padding内边距,margin外边距,content内容这几个部分。 这些属性我们可以用日常生活中的常见事物——盒子作一个比喻来理解,所以叫它盒子模式。 盒子模型能够为我们解决什么问题? 盒子模型主要是针对页面布局的时候来使用,它规范我们的页面的所有元素的一个布局标准是由外向内进行布局。 盒子模型由外向内:margin(外边距)—>border(边框)---->padding(内边距)---->content(元素) 上面所说的盒子模型是基于W3C标准的盒子模型,大多数浏览器都采用标准盒模型。而还有一种怪异盒子模型,这种怪异模式主要表现在IE内核的浏览器。 在标准模式下,一个块的总宽度 = 内容的width + padding(左右) + border(左右) + margin(左右) 在怪异模式下,一个块的总宽度 = 内容的width +

-webkit-margin adds unwanted margin on texts

白昼怎懂夜的黑 提交于 2019-11-27 00:43:56
This hadn't hit me until now (and this is not only in webkit browsers). On all texts in like p tags, h1 tags etc... there's an extra space over and below the text. In chrome I found this: user agent stylesheet -webkit-margin-before: 1em; -webkit-margin-after: 1em; -webkit-margin-start: 0px; -webkit-margin-end: 0px; This makes the alignment wrong in some places. And yes I'm using a reset stylesheet and no padding or margin are added. Pretty much a basic setup. Why is this and how do I solve it? You can also directly modify those attributes like so: -webkit-margin-before:0em; -webkit-margin

String Padding in C

為{幸葍}努か 提交于 2019-11-27 00:25:15
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000". char *StringPadRight(char *string, int padded_len, char *pad) { int len = (int) strlen(string); if (len >= padded_len) { return string; } int i; for (i = 0; i < padded_len - len; i++) { strcat(string, pad); } return string; } It works but has some weird side effects... some of the other variables get changed. How can I fix this? Tom Leys It might be helpful to know that printf does padding for you, using %-10s as the format string will pad the input right in a field 10 characters long printf("|%-10s|"