Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>while I have some knowledge of css, I don't know how you use it within php script.</p> </blockquote> <p>Okay. </p> <p>Your PHP script is a PHP script on the server, and results in a regular HTML page for the user. [See the bottom of the answer, I'll try to give you a quick overview]</p> <p>You can use CSS exactly as you would with a plain HTML page, and it will work just fine despite being backed by PHP.</p> <p>This means <strong>do not use style="$style"</strong>. Style attributes are Bad. </p> <p>As it looks like you want to construct your CSS conditionally, my suggestion is either:</p> <ul> <li>Change a class using PHP, and have an external stylesheet which acts on that class</li> <li>Put the styles you're conditionally changing inside <code>&lt;style&gt;</code> tags in your header, and change those with PHP.</li> </ul> <p><strong>This answer will use the first option</strong> (Edited to take into account new information)</p> <p>In your PHP code, before your links:</p> <pre><code>if($toggle) { $questions.='&lt;div id="frm1"&gt;'; } else { $questions.='&lt;div id="frm2"&gt;'; } </code></pre> <p>In your PHP code, after your links:</p> <pre><code> $questions .= "&lt;/div&gt;"; </code></pre> <p>And finally, in either your external stylesheet, or your in-head <code>&lt;style&gt;</code> tags:</p> <pre><code>#frm1 { ... } #frm2 { ... } </code></pre> <p><br><br> <strong>Quick overview of server-side languages</strong></p> <p>So, web programming. This is generally done in two ways. <strong>client side</strong> (read: javascript) and <strong>server side</strong> (in your case, read: php, but there's a lot more to this).</p> <p>With a client side language like javascript, the code actually gets sent to the web browser. The web browser then modifies the contents of the page according to what the script says for it to do. This means your users can see the code, even turn it off in their web browser or execute other javascript in its place. </p> <p>With a server side language, there's a different workflow. </p> <ol> <li>The user asks for your webpage (identified by its URL)</li> <li>The web server (read: your webhosting) receives this request, and looks up what the webpage is</li> <li>Finding that the webpage is a php page, the <strong>server</strong> executes the php code</li> <li>The php code gives the server an html page (which you have built, as you can see, your php script outputs HTML)</li> <li>The server sends <strong>the resulting html code</strong> to the user</li> </ol> <p>Note that the web browser, which is the component doing all of the processing of HTML and CSS, never sees the php. By the time your php script reaches your users, it's just an html page.</p> <p>Because the web browser only sees an HTML page, there is no functional difference between using CSS on your php script, and using CSS on a regular HTML page. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload