Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 添加变换比例后,我可以';t将截面设置为中心_Javascript_Html_Css - Fatal编程技术网

Javascript 添加变换比例后,我可以';t将截面设置为中心

Javascript 添加变换比例后,我可以';t将截面设置为中心,javascript,html,css,Javascript,Html,Css,如果我不使用javascript来监听resize事件。这是将div居中的方法吗 css结构包含3个状态。正常,低于900px,低于550px。 当宽度超过550px时。我可以将截面设置为中间。当屏幕低于550px时。我使用“缩放”缩小尺寸,但无法将其设置为中心 我尝试将位置更改为固定/相对、左/浮动/变换原点/平移/使用vw/边距/填充。。。 我必须使用javascript来调整窗口大小,然后更改该部分css的left属性 我的网站在 CSS: HTML: 最后,我使用javascript来

如果我不使用javascript来监听resize事件。这是将div居中的方法吗

css结构包含3个状态。正常,低于900px,低于550px。 当宽度超过550px时。我可以将截面设置为中间。当屏幕低于550px时。我使用“缩放”缩小尺寸,但无法将其设置为中心

我尝试将位置更改为固定/相对、左/浮动/变换原点/平移/使用vw/边距/填充。。。 我必须使用javascript来调整窗口大小,然后更改该部分css的left属性

我的网站在

CSS:

HTML:



最后,我使用javascript来处理。以下是我的解决方案。 我不确定这是否是最好的解决办法

$(window).resize(function(){
    if ($(window).width()<=550) {
        $('#tabs').trigger('customresize');
    }
});

$('#tabs').on('customresize',function(){
    myWidth=($(window).width() - 545)/2 +'px';
    $(this).css('left',myWidth);
});
$(窗口)。调整大小(函数(){

如果($(window).width(),请发布相关代码,不要期望所有人都删除您的所有标记。此外,您是否尝试过
转换原点:
属性?谢谢。我编辑了文章。我尝试过翻译()但未尝试变换原点。我将检查它。我尝试添加
变换原点:中心
。它不起作用。
    <section id="tabs">
  <article class="c_tab box" id="tab0" style="background: #A9D0F5;">
    testing
  </article>
</section>  
$(window).resize(function(){
    if ($(window).width()<=550) {
        $('#tabs').trigger('customresize');
    }
});

$('#tabs').on('customresize',function(){
    myWidth=($(window).width() - 545)/2 +'px';
    $(this).css('left',myWidth);
});