gpt4 book ai didi

javascript - 使用 CSS 按固定值调整大小

转载 作者:太空狗 更新时间:2023-10-29 15:07:11 24 4
gpt4 key购买 nike

我正在使用 CSS resize:both; 属性让用户调整我的内容的大小。请参阅下面的代码。

.foo {
resize: both;
min-width: 250px;
width: auto;
text-align: center;
min-height: 30px;
border: 1px solid #515151;
border-radius: 6px;
position: absolute;
padding: 0;
overflow: hidden;
text-shadow: 1px 1px 1px rgba(0,0,0,0.33);
box-shadow: 5px 5px rgba(0,0,0, 0.1);
}
.thClass {
margin-left: -3px;
text-align: center;
box-shadow: 0 2px 2px rgba(0,0,0,0.26);
-webkit-box-shadow: 0 2px 2px rgba(0,0,0,0.26);
-moz-box-shadow: 0 2px 2px rgba(0,0,0,0.26);
margin-top: -2px;
min-height: 30px;
line-height: 30px;
font-size: 19px;
cursor: move;
}
.header{
margin-left: 17px;
}
.tableBody {
display: block;
min-height: 25px;
text-align: center;
width: 102%;
margin-left: -2px;
cursor: default;
}
.foo tbody tr td {
display: block;
line-height: 25px;
text-align: center;
border-bottom: 1px solid rgba(0,0,0,0.2);
}
#displaySizes {
list-style: none;
padding: 0;
margin-top: 0;
}
.disp tbody tr th {
border: 1px solid black;
}
.disp tbody tr td {
display: table-cell;
}
<table class="foo disp elementTable">
<tr class="tableHeader">
<th class="thClass" colspan="5">
<span class="header">Device</span>
</th>
</tr>
<tr>
<td rowspan="4" id="sizeContainer">
<ul id="displaySizes">
<li>4:3</li>
<li>16:9</li>
<li>Clock</li>
</ul>
</td>
<td>$100</td>
<td>February</td>
<td>February</td>
<td>February</td>
</tr>
<tr>
<td>February</td>
<td>February</td>
<td>February</td>
<td>February</td>
</tr>
<tr>
<td>February</td>
<td>February</td>
<td>February</td>
<td>February</td>
</tr>
<tr>
<td>February</td>
<td>February</td>
<td>February</td>
<td>February</td>
</tr>
</table>

有没有办法使用 CSS 逐步调整此表格的大小,例如 [10,10] 像素? JavaScript 也可以。我在网上搜索过,但找不到任何东西。这是工作 fiddle供您玩代码。

最佳答案

这是我放在一起的一个解决方案,它将在调整大小时捕捉到给定的网格(在本例中为 20 像素。)

它使用“跨浏览器调整大小事件监听器”,另一位开发人员已将其放在一起(source):

基本上它只是监听调整大小事件,然后使用 javascript 设置宽度和高度的样式。

在这里 fiddle :

https://jsfiddle.net/treetop1500/co8zbatz/

// utility function for rounding (20px in this case)
function round20(x)
{
return Math.ceil(x/20)*20;
}

// Attach listener
var myElement = document.getElementById('resize'),
myResizeFn = function(){
h = round20(parseInt(this.style.height,10));
w = round20(parseInt(this.style.width,10));
this.style.height = h + "px";
this.style.width = w + "px";
};

addResizeListener(myElement, myResizeFn);

关于javascript - 使用 CSS 按固定值调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47792712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com