0

So basically i have two php files, one with all the functions etc. and one with mixed php and html code.

<table>
   <?php echo read(); ?>            //This prints a full table with <tbody> etc.
</table>

My question: How do I access this PHP printed html code from my CSS style sheet? It s a seperate file and i have linked it correctly etc. (since it styles all the html code on the same file)

I have tried just putting

tbody { width:100px; padding: 20px;}

and all those normal ones, but for som reason it doesn't apply to the code the PHP prints out.

Suggestions? (new to PHP, be nice)

2
  • 1
    You can't style a tbody tag like that, you would need to put the width onto the table and the padding onto the cells. ps you're best giving your table an id and applying styles to that, otherwise all your tables will have the same style Commented Apr 17, 2014 at 10:55
  • The browser does not care one single bit whether the HTML code was created by PHP, or comes from a static file … Commented Apr 17, 2014 at 11:03

2 Answers 2

1

Add a class to the <table> tag like <table class="my-table"> and then try to add in your css file

.my-table{ width:100px; }

You should apply the css styles to the table tag.

Sign up to request clarification or add additional context in comments.

2 Comments

Did you tried adding the css in the browser console for the table tag? If it works, then you might have an error in the css file. Maybe you forgot to close a bracket. If everything is fine, check your html code. View the source in the browser and use a html validator to validate your html
@AndrewP is your css file loading? or are you getting a 404 error (press f12 and check your console in your browser)
0

So if anyone stumbles on this thread with the same problem, I managed to solve it by putting all the CSS info in the <table> tag like this:

<table
        style="
            width:480px;
            margin-left:10px;
            font-family: calibri;
            background-color:white;
            color:black;
            padding:5px;
            border:1px solid black;
        "
        >

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.