How to add background image in css?

后端 未结 4 1157
花落未央
花落未央 2021-01-15 15:21

I want to add background image in my css code but it\'s not loading. How to change or add background image in css please help I\'m written css code in notpad++

相关标签:
4条回答
  • 2021-01-15 16:08
    .Your class name {
    
    background-image: url("your image url");
    
    background-repeat: no-repeat;
    
    background-size: 100% 100%;
    
    float: left;
    
    width: auto;
    
    }
    

    Please try Above type of code in your css section.

    0 讨论(0)
  • 2021-01-15 16:21

    you can add that as this.

    if you have id

    #yourid{
       background-image: url("your image url(EX:imge.jpg)");
    
    
    }
    

    if you have class

    .yourclass_name{
    background-image: url("your image url(EX:imge.jpg)");
    
    }
    

    you can use background function also...if you add background css function,you should have to change width and height

        .yourclass_name {
         background: url("img_tree.png") no-repeat;
    height:500px or give to precentage(30% like that);
    width:1000px or give to precentage (70%);
        }
    
    0 讨论(0)
  • 2021-01-15 16:24

    This is the path u should specify, The way to copy the path is to go the directory where the image is present, then copy path there.

    body { background-image:url("C:\1.jpg");
    
    0 讨论(0)
  • 2021-01-15 16:24

    If you want to add an image as background-image in CSS, there are two ways of doing it:-

    1. If you want to add an image from the internet then, you can use background-image: url("your image url");

    example:

    background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQms3mJIPu3jlPy8b8cOmRg69qurCA82EBDofx6jaK11cUM6u4w");
    
    1. If you want to add an image from your pc, then you should write the image path i.e., background-image: url("your image path");

    example:

    background-image: url("C:\Users\Vimalendu Shekhar\Downloads\image.jpg");
    
    0 讨论(0)
提交回复
热议问题