css中resize属性有什么用

这篇文章主要介绍了css中resize属性有什么用,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

resize是已知的css属性。resize是CSS3中新增的一个属性,用于指定一个元素是否是由用户调整大小的;resize属性允许用户通过拖动的方式,来*缩放元素的尺寸。

css resize属性

resize属性可以指定一个元素是否是由用户调整大小的。

resize是CSS3中新增的一个属性,它允许用户通过拖动的方式,来*缩放元素的尺寸,用以增强用户体验。这在以前只能通过Javascript 编写大量脚本来实现,费时费力,效率低下。

resize属性可以用于根据用户需要以及在哪个方向上调整元素的大小。 resize属性可以采用4个值。

句法:

    Element{
        Resize : none|both|vertical|horizontal;
    }

让我们看一下每个属性...

1) resize : none

当用户不想调整元素的大小时, none值不会应用于resize属性 。 也是默认值。

句法:

    Element{
        resize:none;
    }

例:

<!DOCTYPE html>

<html>

<head>
    <style>
        p {
            border: 3px solid;
            padding: 15px;
            width: 300px;
            resize: none;
        }
    </style>
</head>

<body>
    <h2>The resize Property</h2>
    <p>
        <p>None value doesn’t allow resizing of this p element.</p>
    </p>
</body>

</html>

输出

css中resize属性有什么用

在上面的示例中,您无法调整p元素的大小。 它是静态的。

2) resize : both

当用户希望其元素在宽度和高度的两侧都可调整大小时, 两个值都将应用于resize属性

句法:

    Element{
        resize:both;
    }

例:

<!DOCTYPE html>

<html>

<head>
    <style>
        p {
            border: 3px solid;
            padding: 15px;
            width: 300px;
            resize: both;
            overflow: auto;
        }
    </style>
</head>

<body>
    <h2>The resize Property</h2>
    <p>
        <p>click and drag the bottom right corner to resize the height and width of this p element.</p>
    </p>
</body>

</html>

输出

css中resize属性有什么用

在上面的示例中,要调整大小,请单击并拖动此p元素的右下角。

3) resize : vertical

当用户要根据需要调整元素的高度时,将垂直值应用于resize属性

句法:

    Element{
        resize:vertical;
    }

例:

<!DOCTYPE html>

<html>

<head>
    <style>
        p {
            border: 3px solid;
            padding: 15px;
            width: 300px;
            resize: vertical;
            overflow: auto;
        }
    </style>
</head>

<body>
    <h2>The resize Property</h2>
    <p>
        <p>click and drag the bottom right corner to resize the height of this p element.</p>
    </p>
</body>

</html>

输出

css中resize属性有什么用

在上面的示例中,用户可以单击并拖动此p元素的右下角以调整其高度。

4) resize : horizontal

当用户要根据需要调整元素的宽度大小时,将水平值应用于resize属性

句法:

    Element{
        resize:horizontal;
    }

例:

<!DOCTYPE html>

<html>

<head>
    <style>
        p {
            border: 3px solid;
            padding: 15px;
            width: 300px;
            resize: horizontal;
            overflow: auto;
        }
    </style>
</head>

<body>
    <h2>The resize Property</h2>
    <p>
        <p>click and drag the bottom right corner to resize the width of this p element.</p>
    </p>
</body>

</html>

输出

css中resize属性有什么用

在上面的示例中,用户可以单击并拖动此p元素的右下角以调整其宽度。

感谢你能够认真阅读完这篇文章,希望小编分享css中resize属性有什么用内容对大家有帮助,同时也希望大家多多支持亿速云,关注行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!