在这篇文章中,我们将带领您了解HTML5中的画布宽度和高度的全貌,包括h5画布大小的相关情况。同时,我们还将为您介绍有关easyui的combobox设置宽度和高度自动适应,并指定最大最小宽度和高度和
在这篇文章中,我们将带领您了解HTML5 中的画布宽度和高度的全貌,包括h5画布大小的相关情况。同时,我们还将为您介绍有关easyui 的 combobox 设置宽度和高度自动适应,并指定最大最小宽度和高度和拷贝元素 clone 来循环生成 dom 节点、HTML – SEO对响应式网站指定图像宽度和高度的影响?、html – 为什么CSS中的font-size不等于宽度和高度?、html – 为什么内联元素在浮动时接受宽度和高度?的知识,以帮助您更好地理解这个主题。
本文目录一览:- HTML5 中的画布宽度和高度(h5画布大小)
- easyui 的 combobox 设置宽度和高度自动适应,并指定最大最小宽度和高度和拷贝元素 clone 来循环生成 dom 节点
- HTML – SEO对响应式网站指定图像宽度和高度的影响?
- html – 为什么CSS中的font-size不等于宽度和高度?
- html – 为什么内联元素在浮动时接受宽度和高度?
HTML5 中的画布宽度和高度(h5画布大小)
canvas
是否可以修复 HTML5元素的宽度和高度?
通常的方法如下:
<canvas id="canvas" width="300" height="300"></canvas>
答案1
小编典典canvas
DOM 元素具有.height
与 和.width
属性相对应的和height="鈥�"
属性width="鈥�"
。在
JavaScript 代码中将它们设置为数值以调整画布大小。例如:
var canvas = document.getElementsByTagName(''canvas'')[0];canvas.width = 800;canvas.height = 600;
请注意,这会清除画布,但您应该遵循ctx.clearRect( 0, 0, ctx.canvas.width,ctx.canvas.height);
处理那些未完全清除画布的浏览器。您需要在大小更改后重绘您想要显示的任何内容。
进一步注意,高度和宽度是用于绘图的逻辑画布尺寸,与CSS属性 不同。 如果不设置 CSS 属性,画布的固有尺寸将用作其显示尺寸;如果您确实设置了 CSS
属性,并且它们与画布尺寸不同,则您的内容将在浏览器中缩放。例如:style.height``style.width
// Make a canvas that has a blurry pixelated zoom-in// with each canvas pixel drawn showing as roughly 2x2 on screencanvas.width = 400;canvas.height = 300; canvas.style.width = ''800px'';canvas.style.height = ''600px'';
请参阅放大 4 倍的画布的 实时示例。
var c = document.getElementsByTagName(''canvas'')[0];var ctx = c.getContext(''2d'');ctx.lineWidth = 1;ctx.stroke#f00'';ctx.fill#eff'';ctx.fillRect( 10.5, 10.5, 20, 20 );ctx.strokeRect( 10.5, 10.5, 20, 20 );ctx.fillRect( 40, 10.5, 20, 20 );ctx.strokeRect( 40, 10.5, 20, 20 );ctx.fillRect( 70, 10, 20, 20 );ctx.strokeRect( 70, 10, 20, 20 );ctx.stroke#fff'';ctx.strokeRect( 10.5, 10.5, 20, 20 );ctx.strokeRect( 40, 10.5, 20, 20 );ctx.strokeRect( 70, 10, 20, 20 );body { background:#eee; margin:1em; text-align:center }canvas { background:#fff; border:1px solid #ccc; width:400px; height:160px }<canvas width="100" height="40"></canvas><p>Showing that re-drawing the same antialiased lines does not obliterate old antialiased lines.</p>
easyui 的 combobox 设置宽度和高度自动适应,并指定最大最小宽度和高度和拷贝元素 clone 来循环生成 dom 节点
jsp:
<table class="table" style="width: 100%;" id="myTable">
<TBODY>
<tr>
<th style="text-align: center;width: 50%">旧取费类别</th>
<th style="text-align: center;;width: 50%">新取费类别 </th>
</tr>
</TBODY>
<s:iterator value="oldCostTypeMap" var="column">
<TBODY class="cloneDiv">
<tr>
<td style="text-align: center;">
<input type="hidden" class="myKey"
value="<s:property value="key"/>"/>
<span class="myValue">
<s:property value="value"/><br>
</span>
</td>
<td style="text-align: center;">
<s:select list="newCostTypeMap" uname=''${key}'' theme="simple"
cssClass="myCombobox selfCombobox" cssStyle="width:200px"
data-options
="required:true,editable:false,panelHeight:''auto''" />
</td>
</tr>
</TBODY>
</s:iterator>
</table>
var $cloneDiv = undefined;//拷贝元素
$(function() {
//把拷贝的元素存起来,后面动态生成table数据的时候需要使用到
$cloneDiv = $($(''.cloneDiv'')[0]).clone(true);
initCombobxFun()
});
function initCombobxFun(){
$(''.myCombobox'').combobox({
panelWidth:''auto'',
panelHeigth:''auto'',
onShowPanel:function(){
//改变div的显示方式,做一行显示
$(this).combobox(''panel'').css(''display'',''inline-block'').width(''auto'');
var width = $(this).combobox(''panel'').width();
if (width > 500) {
$(this).combobox(''panel'').width("500");
} else if (width < 200) {
$(this).combobox(''panel'').width("200");
} else {
$(this).combobox(''panel'').width(width + 5);
$(this).combobox(''panel'').parent().width(''auto'');
}
//默认面板高度自适应,如果超出,则指定
var height = $(this).combobox(''panel'').height();
if (height > 200) {
$(this).combobox(''panel'').height("200");
}else{
//$(this).combobox(''panel'').height("auto");
}
//if (height > (document.body.clientHeight - 40)) {
//$(this).combobox(''panel'').height(document.body.clientHeight - 40);
//}else{
//$(this).combobox(''panel'').height("auto");
//}
},
onChange:function(newValue,oldValue) {
if($(this).hasClass(''myFlag'')){
reloadTableFun(newValue);
}
}
});
}
function reloadTableFun(oldTemplateId){
var url = ''./iface/findCostTypeMap'';
var postData = {};
postData["queryParam"] = oldTemplateId;
$.post(url,postData,function(data){
$.easyui.loaded({topMost: false });
var obj=eval(''(''+data+'')'');
if (obj && obj.returnCode==1)
{
//请求后台返回table左侧的循环的数据
var oldCostTypeMap = obj.data;
$(''.cloneDiv'').remove();//清除表格利用<s:iterator>循环生成的原有内容
var appendTd = '''';
for(var key in oldCostTypeMap){
//拷贝<s:iterator>中获取一个循环的dom元素
var $addDiv = $cloneDiv.clone(true);
$addDiv.find(''.myKey'').val(key);//改变左侧隐藏的值
$addDiv.find(''.myValue'').html(oldCostTypeMap[key]);//改变左侧显示的值
//仿照<s:iterator>改变下拉框右侧的uname的值
$addDiv.find(''select[uname]'').attr(''uname'',key).addClass(''easyui-combobox'');
//在<s:iterator>原标签处加入新的元素
$(''#myTable'').append($addDiv.html());
}
$.parser.parse($(''.selfCombobox'').parent());//渲染重新添加的easyui的combobox
initCombobxFun();//设置easyui-combobox的下拉框的自动使用宽和高
return;
}
top.$.messager.alert(''提示'',obj.message,''error'');
});
}
页面显示效果:
当动态切换了费率模板之后,下方的 table 里面的元素除了表头之外,其他的都会重新生成
让 div 排成一行 ===>inline-block 的兼容性
https://www.cnblogs.com/mrxiaohe/p/5234986.html
行内元素,排列在一行,但是不能设置它的 width、height、margin、padding 属性,即使设置了,也是不生效的。
快元素独占一行,如下的这个例子,before div、in div1、in div2、after div 分别占一行,也就是说,块元素前后都不能有行内元素和文本节点。
before div<div style="display:inline-block">in div1</div> <div style="display:inline-block">in div2</div> after div
那么如何让 div 可以排列在一行呢?
用如下的方式:
div{ display:inline-block;//如果网站只兼容谷歌和火狐,这样写就可以 } div{ display:inline-block;//但是IE不支持inline-block,需要这么写,这样写3个浏览器//就可以都兼容了 *display:inline;//添加*号为了兼容ie6和ie7,*代表是专给ie6/7写的,引文它们不能兼容display:inline-block *zoom=1; }
而且:当我们对 div 设置成了 inline-block 的时候,同样可以对其设置 width、height 属性,如果要让其居中,就不需要 margin:0 auto; 了,因为他具有了 inline 的特性,所以用 text-align:center 就行了。
例子:如下代码,执行之后,里面的 div 就是居中的,有宽,有高。
<div style="border:solid;width:500px;height:400px;text-align:center;"> <div style="border: solid; width: 300px; height: 200px;display:inline-block;">inline-block div</div> </div>
当我们对一个行内元素 <span> 设置成 inline-block 的时候,它也是可以有宽有高的(当我们不设置成 inline-block 的时候,它默认是 inline,给他设置宽高,没效果)
<span style="border: solid; width: 300px; height: 200px;">The Span hava width and height</span>
CSS 的 inline、block 与 inline-block 的详细解释
https://segmentfault.com/a/1190000015202771?utm_source=tag-newest
HTML – SEO对响应式网站指定图像宽度和高度的影响?
<img src="http://www.example.com/images/free-size.jpg" width="200" height="400" alt="random image" />
虽然我仍然可以使用height:auto;覆盖内联设置.
因此,在不同的显示平台上,图像可以正确地重新调整大小
但就在我继续这样做之前,只想确保这些陈述是否属实.就我个人而言,我觉得修复内联维度和使用外部CSS覆盖有点怀疑,对我来说听起来有点hacky …..
解决方法
I was told that specifying inline width and height for all images will
be good for SEO and also helps the site load faster.
是.传统上这是真的(至少“网站加载更快”部分).
通过指定< img>的高度和宽度属性浏览器保留与图像的那些维度匹配的空间,同时继续解析HTML文档的其余部分.然后,当浏览器加载图像时,预留空间正在等待,并且不需要reflow the document.
提供此大小调整数据可以加快渲染速度.
相反,如果省略width和height属性,浏览器将不会知道图像的大小,直到下载完成,这会强制浏览器重排文档,从而减慢渲染过程.
现在想象一个包含50个图像的页面,没有定义的宽度和高度属性.性能打击可能非常明显.
上述做法代表了traditional view of image loading.
相比之下,some people are now saying应该避免响应式设计的宽度和高度属性.
Responsive Design does not normally use any width or height attributes
The majority of responsive websites do not use width or
height because they want the images to adapt to the screen size and by
using fixed width and height using<img>
which would dampen user
experience and Google has declared this one of the most important
factors.source: 07003
因此,双方都存在争议,而决定很可能取决于您的个案.当你在这里做出决定时,会有更多细节:
> Specifying image dimensions to improve browser performance
> Image width/height as an attribute or in CSS?
html – 为什么CSS中的font-size不等于宽度和高度?
我有以下HTML代码:
和以下CSS:
p {
border-style: solid;
border-color: black;
border-width: 1em;
font-size: 1em;
height: 1em;
width: 1em;
padding: 0em;
}
为什么内容框的高度和宽度不等于font-size.为什么字母H和边框之间存在间隙,如下面的输出所示.
Output
最佳答案
这是因为那不是字体的设计方式.例如,字母a在顶部包含相当大的空白块,嗯,同样的事情发生在那个H.你可以在实际选择文本时看到它. H的形状不是形成角色的轮廓.它是由字体设计者定义的虚构框.
字体不仅仅是形状,还包含形状.字体设计师花时间考虑字体在多行上的外观,因此他们也会计算字体中的一些间距.
这导致类型的可预测性较低,但更适合于眼睛类型.这就是为什么许多字体将被调整为看起来恰到好处,但数学上它们不是.最好的例子是看看圆形字母实际上是如何从底部突出的,仅仅因为我们的眼睛看到它是错误的.这意味着您的盒子也不会从基线开始.
检查这个图像是否有帮助(是的,有些东西可以像行高一样调整,但实质上这个图像显示你认为你拥有的盒子和实际存在的盒子):
简而言之,字体设计清晰易读,不易计算.
更新:另一张图片
只是添加,@ Paulie_D在这个问题的评论中有一个很好的例证,并且为了将来的参考,看看它也可能是好的:http://www.smashingmagazine.com/wp-content/uploads/2010/05/type-002.gif
html – 为什么内联元素在浮动时接受宽度和高度?
我知道它内联元素所以它不接受宽度和高度,但为什么它适用于我漂浮它?
span.first { width: 500px; height: 500px; border: 1px solid #000; float: right; } span.second { width: 500px; height: 500px; border: 1px solid #000; }
<spanhttps://www.jb51.cc/tag/irs/" target="_blank">irst">with float</span> <span>without float</span>
https://codepen.io/kemozzz/pen/KvVrXj
解决方法
来自MDN:
关于HTML5 中的画布宽度和高度和h5画布大小的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于easyui 的 combobox 设置宽度和高度自动适应,并指定最大最小宽度和高度和拷贝元素 clone 来循环生成 dom 节点、HTML – SEO对响应式网站指定图像宽度和高度的影响?、html – 为什么CSS中的font-size不等于宽度和高度?、html – 为什么内联元素在浮动时接受宽度和高度?的相关知识,请在本站寻找。
本文标签: