自学内容网 自学内容网

Javaweb之css

css的三种引入方式

1内行式

2.内嵌式

3.外部样式表

内行式和内嵌式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
            input{
                border: 1px solid green;
        width: 60px;
        height: 40px;
        background-color: aquamarine;
        color: black;
        font-size: 22px;
        font-family: '行书';
        border-radius: 5px;
            }

    </style>


</head>
<body>
    <!-- 
    
    
    
    -->
    <!-- <input  type="button" value="按钮"
     style=
        "border: 1px solid green;
        width: 60px;
        height: 40px;
        background-color: aquamarine;
        color: black;
        font-size: 22px;
        font-family: '行书';
        border-radius: 5px;
        "
    
    > -->
  


    <input type="button" value="按钮">
    <input type="button" value="按钮">


</body>
</html>

外部样式表

一个css的文件

input{
    border: 1px solid green;
width: 60px;
height: 40px;
background-color: aquamarine;
color: black;
font-size: 22px;
font-family: '行书';
border-radius: 5px;
}

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <link href="css/btn.css" rel="stylesheet">
</head>
<body>
    


<input type="button" value="按钮">
<input type="button" value="按钮">
<input type="button" value="按钮">

选择器

1元素选择器

2id选择器

3class选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

   
    <style>
        #六花{
            border: 1px solid green;
    width: 60px;
    height: 40px;
    background-color: aquamarine;
    color: black;
    font-size: 22px;
    font-family: '行书';
    border-radius: 5px;
        }


</style> -->



<!--
元素选择器

 <style>
            input{
                border: 1px solid green;
        width: 60px;
        height: 40px;
        background-color: aquamarine;
        color: black;
        font-size: 22px;
        font-family: '行书';
        border-radius: 5px;
            }


    </style>
     -->

    <style>
            .shapeClass{
                width: 60px;
                height: 40px;

            }
            .colorclass{
                background-color: aquamarine;
                color: black;
                border: 1px solid green;

            }
            .fontClass{
                font-size: 22px;
        font-family: '行书';
        border-radius: 5px;

            }


    </style>
    




</head>
<body>
    
    <input id="六花" class="colorclass shapeClass fontClass" type="button" value="按钮">
    <input  type="button" value="按钮">
    <input id="二奶" type="button" value="按钮">


    

</body>
</html>

浮动

float: 加上方位

如:float: right;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
            .outerdiv{
                background-color:burlywood ;
                height: 500px;
                width: 600px; 


            }

            .innerdiv{
                height:60px ;
                width: 100px;
                border: 1px solid black;



            }

            .d1{
                background-color: green;
                float: right;
            }
            .d2{
                background-color: red;
                float: right;
            }
            .d3{
                background-color: yellow;
                float: right;
            }



    </style>



</head>
<body>
    <div class="outerdiv" >
            <div class="innerdiv d1">diva</div>
            <div class="innerdiv d2">divx</div>
            <div class="innerdiv d3">divy</div>


        



    </div>

</body>
</html>

定位

 position

                    static 默认(不行动)

                    absolute  绝对  其他的会填充

                    relative  相对原来的位置  其他的不会填充

                    fixed   相对浏览器的窗口 其他的会填充

            top

            right

            left

            bottom

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
            .outerdiv{
                background-color:burlywood ;
                height: 500px;
                width: 600px; 


            }

            .innerdiv{
                height:60px ;
                width: 100px;
                border: 1px solid black;



            }

            .d1{
                background-color: green;
               position: static;
               top: 60px;
               left: 60px;
            }
            .d2{
                background-color: red;
                
            }
            .d3{
                background-color: yellow;
                
            }

          
    </style>



</head>
<body>
    <div class="outerdiv" >
            <div class="innerdiv d1">diva</div>
            <div class="innerdiv d2">divx</div>
            <div class="innerdiv d3">divy</div>


        



    </div>

</body>
</html>

  盒子模型

内边距 padding

外边距 margin

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
            .outerdiv{
                background-color:burlywood ;
                height: 500px;
                width: 600px; 
                margin: 0px auto;



            }

            .innerdiv{
                height:60px ;
                width: 100px;
                border: 1px solid black;
                float: left;
               


            }




            .d1{
                background-color: green;
                margin-right: 10px;
                padding-top: 20px;
                
            }
            .d2{
                background-color: red;
                margin-left: 10px;
            }
                
            .d3{
                background-color: yellow;
                
            }



    </style>



</head>
<body>
    <div class="outerdiv" >
            <div class="innerdiv d1">diva</div>
            <div class="innerdiv d2">divx</div>
            <div class="innerdiv d3">divy</div>


        



    </div>

</body>
</html>


原文地址:https://blog.csdn.net/2401_87232884/article/details/145283613

免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!