CSS background images in WordPress

前端 未结 14 1833
长情又很酷
长情又很酷 2020-12-09 03:44

Is it possible to get a background image in CSS like you normally do in HTML when working with WordPress. I\'ve tried doing this but it doesn\'t work.

backgr         


        
14条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 04:26

    PHP code cannot run in .css file, however you can use inline style, such as:

    ");">

    or

    
    

    The above would be useful when working with custom fields for dynamic image paths.

    If the image is located in the theme directory, PHP won't be needed, let's say the image folder is directly under the theme folder /theme-name/images, and the stylesheet is /theme-name/style.css, then you can just add the background image to the css file as follows:

    .class-name {
      background-image: url("images/file.jpg")
    }
    

提交回复
热议问题