0

I make a slider for my website, I make 3 pictures in CSS file

code :

.banner1{
 background:url(../images/bnr1.png) no-repeat 0px 0px;
 background-size:cover;
 min-height:650px;
}
.banner2{
 background:url(../images/bnr2.jpg) no-repeat 0px 0px;
 background-size:cover;
 min-height:650px;
}
.banner3{
 background:url(../images/bnr3.jpg) no-repeat 0px 0px;
 background-size:cover;
 min-height:650px;
}

but I want to take the last 3 posts from the database and make them in slider

So, is there any method to make the php code into CSS file ?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Y.Saad
  • 15
  • 6
  • 1
    Yes, it's technically possible to make a css file beeing parsed an onterpreted as php, but I'd not recommend doing so. Looks like an [XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) to me. Can you explain more what you orininaly whant to achieve? – Jeff May 29 '16 at 00:22
  • use different slider code - code where you can pass in an array of images, and the code will accept that, then iterate through them all – user3791372 May 29 '16 at 01:26

1 Answers1

1

You wouldn't want to write the file references to a new .css file, better to echo them directly into a style tag like so:

</php
//PHP CODE
?>

<head>
<style>
    .banner1{
    background:url(<?php echo //FILE REFERENCE 1 ?>) no-repeat 0px 0px;
    background-size:cover;
    min-height:650px;
}
.banner2{
    background:url(<?php echo //FILE REFERENCE 2 ?>) no-repeat 0px 0px;
    background-size:cover;
    min-height:650px;
}
.banner3{
    background:url(<?php echo //FILE REFERENCE 3 ?>) no-repeat 0px 0px;
    background-size:cover;
    min-height:650px;
}
</head>
</style>

<?php 

//MORE CODE
Richard Guy
  • 470
  • 4
  • 12
  • this will be working, but is a very oldfashioned way of doing stuff like that. For a reason. Always try to seperate design from data and logic as much as possible. – Jeff May 29 '16 at 00:28
  • inline css is old fashioned? – But those new buttons though.. May 29 '16 at 01:22
  • This is not a great approach and my answer was intended to be as direct to the question as possible. The most common approach to this problem (in my experience) is to inject the background-image property directly into the style attribute of the target elements. – Richard Guy May 29 '16 at 01:33