首页 > 其他分享 >CSS: width height

CSS: width height

时间:2023-09-26 23:55:41浏览次数:65  
标签:body aside height width offsetHeight div document offsetWidth CSS

 

 

<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body {
        width: 2000px;
        height: 2000px;
        border: 1px solid violet;
        padding: 10px 20px 30px 40px;
        margin: 10px 20px 30px 40px;
        background-color: silver;
        word-break: keep-all;
        /* white-space: nowrap; */
    }

    html {
        /* border: 10px dashed maroon;
        padding: 10px 20px 30px 40px;
        margin: 10px 20px 30px 40px; */
        background-color: lightcoral;
    }

    :where(dt, dd) {
        display: inline-block;
    }

    blockquote {
        font-weight: bolder;
    }
</style>

<body>
    <fieldset>don't set margin border padding on html</fieldset>
    <blockquote></blockquote>
    <blockquote></blockquote>
    <blockquote>document.body</blockquote>
    <dl></dl>
    <blockquote>document.documentElement</blockquote>
    <dl></dl>
    <script>
        function setup() {
            document.querySelector('blockquote:nth-of-type(1)').innerHTML = `
            innerWidth: ${innerWidth}
            `
            document.querySelector('blockquote:nth-of-type(2)').innerHTML = `
            innerHeight: ${innerHeight}
            `
            let body = document.querySelector('dl:nth-of-type(1)')
            body.innerHTML = `
            <figure>
                <dt>clientWidth:</dt><dd>${document.body.clientWidth}</dd>
            </figure>
            <figure>
                <dt>offsetWidth:</dt><dd>${document.body.offsetWidth}</dd>
            </figure>
            <figure>
                <dt>scrollWidth:</dt><dd>${document.body.scrollWidth}</dd>
            </figure>
            <figure>
                <dt>clientHeight:</dt><dd>${document.body.clientHeight}</dd>
            </figure>
            <figure>
                <dt>offsetHeight:</dt><dd>${document.body.offsetHeight}</dd>
            </figure>
            <figure>
                <dt>scrollHeight:</dt><dd>${document.body.scrollHeight}</dd>
            </figure>
            `
            let documentElement = document.querySelector('dl:nth-of-type(2)')
            documentElement.innerHTML = `
            <figure>
                <dt>clientWidth:</dt><dd>${document.documentElement.clientWidth}</dd>
            </figure>
            <figure>
                <dt>offsetWidth:</dt><dd>${document.documentElement.offsetWidth}</dd>
            </figure>
            <figure>
                <dt>scrollWidth:</dt><dd>${document.documentElement.scrollWidth} document.body.offsetWidth + marginLeft</dd>
            </figure>
            <figure>
                <dt>clientHeight:</dt><dd>${document.documentElement.clientHeight}</dd>
            </figure>
            <figure>
                <dt>offsetHeight:</dt><dd>${document.documentElement.offsetHeight}</dd>
            </figure>
            <figure>
                <dt>scrollHeight:</dt><dd>${document.documentElement.scrollHeight} document.body.offsetHeight + marginTop + marginBottom</dd>
            </figure>
            `
        }
        setup()
    </script>
</body>

</html>

 

 

<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,
        body {
            height: 100%;
        }

        div {
            width: 500px;
            height: 500px;
            padding: 30px;
            border: 20px dashed maroon;
            margin: 10px;
            background-color: plum;
            position: relative;
            overflow-x: scroll;
            overflow-y: scroll;
            display: flow-root;
        }

        aside {
            width: 100px;
            height: 800px;
            padding: 30px;
            border: 20px dotted coral;
            margin: 10px;
            background-color: peru;
            position: absolute;
            top: 50px;
        }

        blockquote {
            font-weight: bolder;
        }

        :where(dt, dd) {
            display: inline-block;
        }
    </style>
</head>

<body>
    <div>
        <aside></aside>
    </div>
    <blockquote>div</blockquote>
    <dl></dl>
    <blockquote>aside</blockquote>
    <dl></dl>
    <script>
        function setup() {
            const div = document.querySelector('div')
            const aside = document.querySelector('aside')
            let d1 = document.querySelector('dl:nth-of-type(1)')
            d1.innerHTML = `
                <figure>
                    <dt>clientWidth:</dt><dd>${div.clientWidth}</dd>
                </figure>
                <figure>
                    <dt>offsetWidth:</dt><dd>${div.offsetWidth}</dd>
                </figure>
                <figure>
                    <dt>scrollWidth:</dt><dd>${div.scrollWidth}</dd>
                </figure>
                <figure>
                    <dt>clientHeight:</dt><dd>${div.clientHeight}</dd>
                </figure>
                <figure>
                    <dt>offsetHeight:</dt><dd>${div.offsetHeight}</dd>
                </figure>
                <figure>
                    <dt>scrollHeight:</dt><dd>${div.scrollHeight}</dd>
                </figure>
                `
            let d2 = document.querySelector('dl:nth-of-type(2)')
            d2.innerHTML = `
                <figure>
                    <dt>clientWidth:</dt><dd>${aside.clientWidth}</dd>
                </figure>
                <figure>
                    <dt>offsetWidth:</dt><dd>${aside.offsetWidth}</dd>
                </figure>
                <figure>
                    <dt>scrollWidth:</dt><dd>${aside.scrollWidth}</dd>
                </figure>
                <figure>
                    <dt>clientHeight:</dt><dd>${aside.clientHeight}</dd>
                </figure>
                <figure>
                    <dt>offsetHeight:</dt><dd>${aside.offsetHeight}</dd>
                </figure>
                <figure>
                    <dt>scrollHeight:</dt><dd>${aside.scrollHeight}</dd>
                </figure>
                `
        }
        setup()
    </script>
</body>

</html>

 

标签:body,aside,height,width,offsetHeight,div,document,offsetWidth,CSS
From: https://www.cnblogs.com/dissipate/p/17731607.html

相关文章

  • CSS 入门 - Box Model 盒模型
    CSS入门-BoxModel盒模型网页布局:先学习BoxModel,然后Flexbox/Grid/Float三选一即可搞定网页布局,推荐Flexbox!BOXModel四大属性:Content、Padding、Border、MarginContent:内容Border:边框线padding:内容与边框的距离margin:边框与其他元素的距离margin与padding......
  • 前端显示数据库中的换行文本:HTML和CSS解决方案
    在项目中经常会出现要显示数据库中的大段文本内容,如说明或备注等信息,当其中存储有换行符的时候,前端通常会忽略这个换行,直接在一行显示,那么怎么解决呢?解决方案一:使用HTML<br>标签HTML的<br>标签是一种简单而直观的方法,它可以将文本中的换行符正确地呈现在浏览器中。示例代码......
  • 实现不同屏幕自适应【postcss-px-to-viewport】
    效果图未转换前:转换后:背景平常开发的时候使用px作为样式单位,但是在不同的屏幕尺寸下不能自适应,我们希望项目中所有使用到的px单位都转换成vw单位使用步骤安装npmipostcss-px-to-viewport-D在项目根目录下创建postcss.config.jsmodule.exports={plugins:{......
  • 基于CSS实现回到页面顶部的几种写法(从实现到增强)
    前面整理了一个JS实现回到顶部的功能,但没有给出具体的界面样式,这次从网上找几个好看的参考,自己动手也实现一下,后续打算结合这两篇文章,根据JS和CSS使用油猴来实现一下。效果图如下: 代码如下:<!DOCTYPEhtml><htmllang="cn"><head><metacharset="UTF-8"><title>......
  • vscode vue 插件与 emmet、tailwind css 插件冲突的解决方案
    今天使用vscode开发nuxt3项目,发现在vue文件中,emmet提示功能不可用。emmet提示功能,如下图所示:百度、google一阵子,发现是个全球性存在的问题,是vue插件volar导致的vscode自带的emmet提示功能不可用。如果在vscode中不安装vue插件,那么想要在vue文件中启用emmet......
  • XPATH&CSS规则
    css定位规则 css定位示例 xpath定位规则  xpath定位示例 ......
  • 01-React-组件-CSS模块化
    CssModule(推荐)React的脚手架已经内置了cssmodules的配置:.css/.less/.scss等样式文件都修改成.module.css/.module.less/.module.scss等;在以前我们的文件是这样的index.css如果使用了CSS的模块化之后,在之前的文件的基础上在加上.module即可,如,index.module.cs......
  • CSS的表格属性
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>Document</title>......
  • CSS的文本属性
    1.指定元素文件的水平对齐方式:text-align(leftrightcenter)2.text-decoration:文本修饰(underline下划线overline上划线line-through删除线)3.text-transform:控制文本的大小写:(captialize开头大写 uppercase所有字母大写lowercase所有字母小写)4.text-indent:规定文......
  • css继承,position:fixed固定定位
    CSS继承是指元素可以继承其父元素的某些样式属性值。当一个元素应用了某个样式属性值,而其子元素没有显式地指定该属性值时,子元素会从父元素继承该属性值。以下是一些常见的CSS属性可以被继承的例子:1.字体样式属性:font-family、font-size、font-weight、font-style、line-heig......