前端三剑客 —— CSS ( 坐标问题 、定位问题和图片居中 )

本文主要是介绍前端三剑客 —— CSS ( 坐标问题 、定位问题和图片居中 ),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前期内容回顾:

1.常见样式

        text-shadow x轴 y轴 阴影的模糊程度 阴影的颜色

        box-shadow

        border-radio 实现圆角

        margin 内边距

        padding 外边距

        background

2.特殊样式

        媒体查询:@media

        自定义字体:@font-face {

                                font-family:自定义名称;

                                src:url(“字体的路径”);

                                }

                                选择{

                                        font-family:自定义名称;

                                        }

        转换:transform

        移动:translate()

        旋转:rotate()

        缩放:scale()

        翻转:skew()

        综合:matrix()

        过渡:transition   属性  时间  效果(默认值:ease)  延迟(默认值:0)

        动画:@keyframes      animate

          @keyframes  自定义动画名称{

        帧名称1{

                        属性名:值

                        }

        帧名称2{

                        属性名:值

                        }

                        …..

                }

        选择器{

                        animate:自定义动画名称;

                        }

                属性有:动画名称(animate-name)、动画时长(animate-duration)、延迟、次数(默认值:1)、方向、状态

                渐变:background-image:linear-gradient(direction,color-stop1,color-stop2,…)

                        background-image:radius-gradient(direction,color-stop1,color-stop2,…)

                多列:column-count

                字体图标:

                变量:定义变量使用 --名称:值;    使用变量:   属性名:var(--名称);

                倒影: -webkit-box-reflect   了解

3.页面布局

                table 布局     了解

                div+css  盒子模型    左外边距  左边线  左内边距   内容 右内边距 右边线  右外边距

                box-sizing:border-box;

坐标问题

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>坐标问题</title>

    <style>

        * {

            margin: 0;

            padding: 0;

        }

        div {

            width: 130px;

            height: 50px;

            text-align: left;

            padding-left: 10px;

        }

        div:nth-child(1) {

            background: #DAE8FC;

            position: absolute;

            left: 100px;

            top: 100px;

        }

        div:nth-child(2) {

            background: #D5E8D4;

            position: absolute;

            top: 100px;

            right: 100px;

        }

        div:nth-child(3) {

            background: #FFE6CC;

            position: absolute;

            left: 100px;

            bottom: 100px;

        }

        div:nth-child(4) {

            background: #FFF2CC;

            position: absolute;

            right: 100px;

            bottom: 100px;

        }

    </style>

</head>

<body>

<div>left: 100px;<br>top: 100px;</div>

<div>right: 100px;<br>top: 100px;</div>

<div>left: 100px;<br>bottom: 100px;</div>

<div>right: 100px;<br>bottom: 100px;</div>

</body>

</html>

定位问题

CSS中定位有以下几种:

1.相对定位

相对定位的参考位置:如果是第一个元素,那么它相对的就是 body(父元素) 的位置;如果是第二个元素开始,它相对的就是前一个元素的位置。

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>相对定位</title>

    <style>

        * {

            margin: 0;

            padding: 0;

        }

        .container {

            width: 100%;

            height: 400px;

            background-color: #cccccc;

            position: relative;

            left: 30px;

            top: 30px;

        }

        .box {

            width: 100px;

            height: 100px;

            background-color: #317FE5;

            position: relative; /* 相对定位 */

            left: 10px;

            top: 10px;

        }

        .haha {

            width: 100px;

            height: 100px;

            background-color: #8B0000;

            position: relative;

            left: 10px;

            top: 10px;

        }

    </style>

</head>

<body>

<div class="container">

    <div class="box"></div>

    <div class="haha"></div>

</div>

</body>

</html>

2.绝对定位

绝对定位就已经脱离了文档流我们只需要给它固定 x轴坐标(left 或 right 值)以及 y 轴坐标(top 或 bottom 值)就可以了。

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>绝对定位</title>

    <style>

        * {

            margin: 0;

            padding: 0;

        }

        .container {

            width: 800px;

            height: 500px;

            background-color: #eeeeee;

            position: relative;

        }

        .box {

            width: 150px;

            height: 150px;

            background-color: #317FE5;

            position: absolute; /* 绝对定位 */

            /*left: 500px;*/

            /*top: 300px;*/

            left: 500px;

            bottom: 50px;

        }

    </style>

</head>

<body>

<div class="container">

    <div class="box"></div>

</div>

</body>

</html>

3.固定定位

固定定位固名思意就是它的位置不会随滚动条的变化而发生变化

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>固定定位</title>

    <style>

        * {

            margin: 0;

            padding: 0;

        }

        body {

            height: 3000px;

        }

        .box {

            width: 100%;

            height: 60px;

            background-color: #317FE5;

            box-shadow: 5px 5px 10px #999999;

            position: fixed;

            left: 0;

            top: 0;

        }

        .aside {

            width: 60px;

            height: 300px;

            background: #8B0000;

            position: fixed;

            left: 0;

            top: 100px;

        }

        .footer {

            width: 100%;

            height: 80px;

            background: #eeeeee;

            position: fixed;

            left: 0;

            bottom: 0;

        }

    </style>

</head>

<body>

<div class="box"></div>

<div class="aside"></div>

<div class="footer"></div>

</body>

</html>

图片居中

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>图片居中问题</title>

    <style>

        .box {

            width: 200px;

            height: 200px;

            border: 1px solid #8B0000;

            position: relative;

        }

        img {

            width: 100px;

            height: 100px;

            position: absolute;

            /*left: 25%;*/

            /*top: 25%;*/

            left: 50px;

            top: 50px;

        }

    </style>

</head>

<body>

<div class="box">

    <img src="image/logo.png">

</div>

</body>

</html>

这篇关于前端三剑客 —— CSS ( 坐标问题 、定位问题和图片居中 )的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/877991

相关文章

解决IDEA报错:编码GBK的不可映射字符问题

《解决IDEA报错:编码GBK的不可映射字符问题》:本文主要介绍解决IDEA报错:编码GBK的不可映射字符问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录IDEA报错:编码GBK的不可映射字符终端软件问题描述原因分析解决方案方法1:将命令改为方法2:右下jav

MyBatis模糊查询报错:ParserException: not supported.pos 问题解决

《MyBatis模糊查询报错:ParserException:notsupported.pos问题解决》本文主要介绍了MyBatis模糊查询报错:ParserException:notsuppo... 目录问题描述问题根源错误SQL解析逻辑深层原因分析三种解决方案方案一:使用CONCAT函数(推荐)方案二:

Redis 热 key 和大 key 问题小结

《Redis热key和大key问题小结》:本文主要介绍Redis热key和大key问题小结,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、什么是 Redis 热 key?热 key(Hot Key)定义: 热 key 常见表现:热 key 的风险:二、

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

Android使用ImageView.ScaleType实现图片的缩放与裁剪功能

《Android使用ImageView.ScaleType实现图片的缩放与裁剪功能》ImageView是最常用的控件之一,它用于展示各种类型的图片,为了能够根据需求调整图片的显示效果,Android提... 目录什么是 ImageView.ScaleType?FIT_XYFIT_STARTFIT_CENTE

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊

Spring Boot中JSON数值溢出问题从报错到优雅解决办法

《SpringBoot中JSON数值溢出问题从报错到优雅解决办法》:本文主要介绍SpringBoot中JSON数值溢出问题从报错到优雅的解决办法,通过修改字段类型为Long、添加全局异常处理和... 目录一、问题背景:为什么我的接口突然报错了?二、为什么会发生这个错误?1. Java 数据类型的“容量”限制

关于MongoDB图片URL存储异常问题以及解决

《关于MongoDB图片URL存储异常问题以及解决》:本文主要介绍关于MongoDB图片URL存储异常问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录MongoDB图片URL存储异常问题项目场景问题描述原因分析解决方案预防措施js总结MongoDB图

SpringBoot项目中报错The field screenShot exceeds its maximum permitted size of 1048576 bytes.的问题及解决

《SpringBoot项目中报错ThefieldscreenShotexceedsitsmaximumpermittedsizeof1048576bytes.的问题及解决》这篇文章... 目录项目场景问题描述原因分析解决方案总结项目场景javascript提示:项目相关背景:项目场景:基于Spring

解决Maven项目idea找不到本地仓库jar包问题以及使用mvn install:install-file

《解决Maven项目idea找不到本地仓库jar包问题以及使用mvninstall:install-file》:本文主要介绍解决Maven项目idea找不到本地仓库jar包问题以及使用mvnin... 目录Maven项目idea找不到本地仓库jar包以及使用mvn install:install-file基