Updating table using PHP is overriding CSS formatting - php

I am using PHP to call data from a Microsoft SQL Database. That functionality is working, however when PHP updates the table's data it is overriding some of the formatting. One big specification I wanted was to have a max-height of 400px and once it crosses that the table becomes scroll-able.
Some context: I am running this on a local PHP server.
I have tried adding !important tags but that did not work.
<table id = 'tbl' class='table'>
<thead id = 'heading'>
<tr>
<td scope="col" >Applicant ▼</td>
<td scope="col">Grantee EIN</td>
<td scope="col">State</td>
<td scope="col">FAC Accepted Date</td>
<td scope="col">Expenditures</td>
<td scope="col">Prior Finding</td>
<td scope="col">Audit</td>
</tr>
</thead>
<div id = 'scrollbody'>
<tbody>
<?php
$result = array();
do {
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){
echo '
<tr>
<td>'.$row["AUDITEENAME"].'</td>
<td>'.$row["EIN"].'</td>
<td>'.$row["STATE"].'</td>
<td>'.$row["FACACCEPTEDDATE"].'</td>
<td>'.$row["TOTFEDEXPEND"].'</td>
<td>'.$row["PYSCHEDULE"].'</td>
<td><input type="checkbox" oninput=""></td>
</tr>
';
}
} while (sqlsrv_next_result($stmt));
// sqlsrv_free_stmt($stmt);
// sqlsrv_close($conn); //Close the connnectiokn first
// echo json_encode($result); //You will get the encoded array variable
?>
</tbody>
</div>
</table>
#tbl {
margin: auto;
top: 0px;
height: 100%;
max-height: 400px;
position: relative;
font-family: 'Segoe UI';
box-shadow: 0px 0px 5px 2px rgb(240, 240, 240);
perspective: 1px;
border-radius: 0px 0px 20px 20px;
white-space: nowrap;
width: 100%;
z-index: 1;
}
What I want to see is a table of 400px height, but instead a table of much longer height is being displayed.

So, there are 2 options:
Wrap the table in with a wrapper and give the max-height to that element.
<div id="table-wrapper">
<table>
{Your stuff...}
</table>
</div>
Give the thead, tbody a display: block property. With which again your CSS styles will come into use.

First you need to know how a browser works.
The browser will not show anything until this steps are made:
Your browser request a file like html or php first.
Then it will check the styling (CSS/SCSS).
Checking for JavaScript.
checking for source like an image or other media.
Only then it will display the page.
So if you want to style after this process, you will need JavaScript.
JavaScript is invented to manipulate or modify the DOM (document object Model).
That means, you can point to an element and style it, remove it, add a new element etc.
For a better format I prefer jQuery.
jQuery is another way to code JavaScript. (jQuery = JavaScript, just in another form) jQuery calls the JS library.

you can't set header of a table, a table height is based on his content, if you need a table with a specific height you need to change the display type and add overflow rule:
#tbl {
margin: auto;
top: 0px;
height: 100px;
max-height: 400px;
position: relative;
font-family: 'Segoe UI';
box-shadow: 0px 0px 5px 2px rgb(240, 240, 240);
perspective: 1px;
border-radius: 0px 0px 20px 20px;
white-space: nowrap;
width: 100%;
z-index: 1;
display:block;
overflow:auto;
}
Here a live fiddle https://jsfiddle.net/g7fuLhyp/

Related

How a textarea can display an svg file

Trying to insert some svg's in my chat app. If I use them as PHP files, it's ok they will display in the chat#div but in the text area it's the full code of the svg's. When I'm trying to display them as svg the only thing I can see in the chat is this [object XMLDocument] both in text area and in #div
here's the code for the textarea
<textarea id="comment" style="width: 280px; margin-top: 10px; box-shadow:
inset 0 -15px 35px -5px rgba(0,0,0,0.3); height: 40px; overflow: auto;
pointer-events: all;">
</textarea>
and here is the javascript for the svg
function test(){
$.ajax({
url:"emoticons/cloudda3.svg",
success:function(result){
$("#comment").val(result);
}
})
}
A div Element has a contenteditable attribute, setting it to true will allow the user to enter and modify the data in the div. The best thing: the div can contain rich text including images.
.textarea {
font-family: monospace;
outline: none;
background: #efefef;
border: #888 1px solid;
display: block;
position: relative;
resize: both;
overflow: auto;
font-size: 9pt;
}
img {
height: 9pt;
}
<div class="textarea" contenteditable="true">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/90/Perry-miniature-donkey-in-Palo-Alto-CA-2016.jpg/800px-Perry-miniature-donkey-in-Palo-Alto-CA-2016.jpg" />
</div>
Note: The <img> tag in the <div> can be replaced with any valid image or SVG.
As a sidenote, #emaillenin is correct in saying that textareas are only for text. Also I'm noticing you using the val function to insert, that would mean that the value of the element is updated, not it's innerHTML. This would result in a behaviour similar to what you are seeing now. If you want to get just the text from the div, use the text function.

css transitions not working while loop

On my site i have a list of tables that set a bunch of training for athletes on specific dates.
I want to add the ability to input how they did. I would like it to work in a way so that when you hover or click on the training a div would scroll down showing what was achieved.
I currently have the following code in the while loop:
$sessTable .= '<table border = "1px solid black" style="width:100%; border-collapse: collapse">
<tr>
<td colspan="2" style="background-color:#E8E8E8 ">' .$newDate. '' .$attendBtn. '</td>
</tr>
<tr>
<td><div style=" float:left" >' .$session. '</div>' .$editBtns. '</td>
</tr>
</table>
<div class="diary">
testing the div theory.<br/>
to see if it<br/>
will slide up and down
</div>';
The CSS
.diary {
width: 100%;
height: 10px;
background: #FFF;
-webkit-transition: width 2s; /* For Safari 3.1 to 6.0 */
transition: height 2s;
font-size:0px;
}
.diary:hover {
height: 300px;
font-size:12px;
background:#CCC
}
It seemed to work fine when i tried it on a single div but when i put it in the while loop the hover works fine but seems to ignore the initial .diary state and also just jumps straight to the hover state with no transition.
My question is is this possible for multiple divs or is there a better way to achieve what i need.
Because you set transition only for height
.diary {
width: 100%;
height: 10px;
background: #FFF;
-webkit-transition: height 2s,background 2s;;
/* For Safari 3.1 to 6.0 */
transition: height 2s,background 2s;;
font-size: 0px;overflow:hidden
}
.diary:hover {
height: 300px;
font-size: 12px;
background: #CCC
}
<div class="diary">
testing the div theory.
<br/>to see if it
<br/>will slide up and down
</div>

How to define table cell height (CSS/HTML)

I'm using standard CSS/HTML for designing my website. Using a table for the navigation, I assign my "#nav table" with a width of 100% and my "#nav th" with a height of 50px.
My issue is that it's not actually setting itself to what I define. I had assumed it was as easy as just saying height: 50px but even when I define it as 0px it remains at 90.5px. In the HTML I did define my cells and what the table was, etc.
How can I fix this? Right now my site header is outrageously large because my table cells won't adjust to what I define them.
Using just PHP, HTML, and CSS.
CSS:
#nav table {
margin: 15px;
width: 100%;
position: fixed;
}
#nav th {
height: 0px;
border: 5px black solid;
padding: 25px;
text-align: center;
white-space: nowrap;
letter-spacing: 0px;
word-spacing: 5px;
}
HTML:
<center>
<table id="nav">
<tr>
<th><h1>LINK</h1></th>
<th><h1>LINK1</h1></th>
<th><h1>LINK2</h1></th>
<th><h1>LINK3</h1></th>
<th><h1>LINK4</h1></th>
<th><a href="LINK5><h1>LINK5</h1></a></th>
</tr>
</table>
</center>
<p>
Page Directory:
Using the code #nav table assumes an element with the ID "nav" with a table inside, and not a table element with the id "nav".
<style type="text/css">
/* For a table with the id of 'nav'. You could equally remove 'table'. */
table#nav {
margin: 15px;
width: 100%;
position: fixed;
}
#nav th {
height: 0px;
border: 5px black solid;
padding:0 25px;
text-align: center;
white-space: nowrap;
letter-spacing: 0px;
word-spacing: 5px;
}
th h1 {
margin:0;
}
</style>
<center>
<table id="nav">
<tr>
<th><h1>LINK</h1></th>
<th><h1>LINK1</h1></th>
<th><h1>LINK2</h1></th>
<th><h1>LINK3</h1></th>
<th><h1>LINK4</h1></th>
<!-- Don't forget to close all hrefs with a double-quote: -->
<th><h1>LINK5</h1></th>
</tr>
</table>
</center>
https://jsfiddle.net/cz1o8a2n/1/
Note that if you have an element inside of your th that is 90.5px tall, you will not be able to make the table header less tall using CSS (unless you use CSS to decrease the height of that element).
Edit: Consider using the more moder nav instead, with list-items. Plus, you'll have an easier time making your site responsive if you like. :)
<style type="text/css">
nav {
margin: 15px;
width: calc(100% - 30px);
position: fixed;
text-align:center;
}
nav ul {
padding-left:0;
list-style:none;
}
nav li {
display:inline-block;
border: 3px black solid;
padding:0 20px;
text-align: center;
white-space: nowrap;
letter-spacing: 0px;
word-spacing: 5px;
margin:2px 0;
}
</style>
<nav id="nav">
<ul>
<li>LINK</li>
<li>LINK1</li>
<li>LINK2</li>
<li>LINK3</li>
<li>LINK4</li>
<li>LINK5</li>
</ul>
</nav>
https://jsfiddle.net/cz1o8a2n/2/
HTML
You're missing a " for LINK5.
<center>
<table id="nav">
<tr>
<th><h1>LINK</h1></th>
<th><h1>LINK1</h1></th>
<th><h1>LINK2</h1></th>
<th><h1>LINK3</h1></th>
<th><h1>LINK4</h1></th>
<th><h1>LINK5</h1></th>
</tr>
</table>
</center>
CSS
If you want to apply css to a table with the id set to nav your selector needs to be table#nav. As for the table headings being larger than you like, the issue is the h1 tag inherently has a pretty big margin. This big margin is making your table headings larger than you'd like.
table#nav {
margin: 15px;
width: 100%;
position: fixed;
}
#nav th {
height: 50px;
border: 5px black solid;
text-align: center;
white-space: nowrap;
overflow: hidden;
}
#nav th h1 {
margin: 0;
}

Background-image moves when zooming also can't align text in a table

That's how the page looks like currently: http://i.imgur.com/nEHLFUX.png[1] and there are couple of bugs that I would love you to help me with. 2 main ones I want the spell names to be aligned to the right next to little icons of spells and second of all there is a background picture and when I zoom the site out it moves downwards and to the left and I want it to always stay at the same place.
Now code:
class spell {
function do_spell($spellicon, $spellname, $spelltext, $changeinpower) {
echo '
<div class="spellrow">
<table class="spelltable" cellpadding="0" cellspacing="0">
<tr>
<td ><img class="spellimage" src="/abilities/'.$spellicon.'"></td>
<td class="spellname">'.$spellname.' - </td>
<td class="spelldesc">'.$spelltext.'</td>
<td class="changeinpower"><img src="/icons/'.$changeinpower.'"></td>
</tr>
</table>
</div>
';
}
}
patch.php part
$karthus = new splash;
$laywaste1 = new spell;
$laywaste2 = new spell;
$karthus->do_splash('Karthus','cropkarthus','Karthus_0.jpg');
$laywaste1->do_spell('64px-Lay_Waste.jpg','Lay Waste (Q)','Added a new indicator that shows the full area of effect','new.png');
$laywaste2->do_spell('64px-Lay_Waste.jpg','Lay Waste (Q)','Added crit-style combat text and a unique sound effect for double-damage Qs','new.png');
Some css:
.spellrow {
width: 900px;
padding: 0;
margin-bottom: 3px;
background-color: #ffffff;
box-shadow: 1px 1px #cccccc; }
.spelltable {
width: 100%;}
.spellimage {
width: 32px;
height: 32px;
padding-left: 5px;}
.spellname {
white-space: nowrap;
padding: 0 5px;
width: 10px;}
.spelldesc {
font-size: 15px;
line-height: 1.05em;}
.changeinpower {
width: 60px;}
/* And now the img in the background part */
.season2014
{
background-color:#f1f1f1;
background-image: url('/season_graphic/SEASON2014_2.png');
background-repeat: no-repeat;
background-position: 20% 50%;
background-origin: content-box;
background-position: fixed; }
<body class="season2014";>
PS. any kind of mistakes in code I would love you to point out I'm really new to the web-designing thingy
The problem with the background moving is from the background-position: fixed. This fixed value is not valid CSS. Try playing with the values available for the property to get the desired effect. More info on the Mozilla Dev Network for CSS with the background-size property.
About the name, I haven't seen any text-align: left in your CSS, that's maybe what you're looking for in your .spellname property. But more than that, the alignment problem comes from the width which is just width: 10px; in the .spellname property.
Because you fixed the total row width to 900px, why not use pixels all the way to define all the widths ? Like so:
.spellrow {
width: 900px;
padding: 0;
margin-bottom: 3px;
background-color: #ffffff;
box-shadow: 1px 1px #cccccc;
}
.spelltable {
width: 100%;
}
.spellimage {
width: 32px;
height: 32px;
padding-left: 5px;
}
.spellname {
white-space: nowrap;
padding: 0 5px;
text-align: left;
width: 150px; /* Adapt to your needs */
}
.spelldesc {
font-size: 15px;
line-height: 1.05em;
text-align: left;
width: 658px; /* Adapt to your needs */
}
.changeinpower {
width: 60px;
}
And the corresponding HTML code
<div class="spellrow">
<table class="spelltable" cellpadding="0" cellspacing="0">
<tr>
<td class="spellimage">IMG</td>
<td class="spellname">Name</td>
<td class="spelldesc">Text with plenty of info here</td>
<td class="changeinpower">IMG</td>
</tr>
</table>
</div>
On a side note, doing one table per item is loosing the whole purpose of tables: one item is one row of the table. You should have one table per category and each spell being a row in the according table.

HTML overflow:hidden doesn't format text correctly

I'm working on a website for an American Football team. They have these newsitems on their front page which they can manage through a CMS system. I have a problem with alligning the text inside those news items. Two of the news items look like this:
As you can see, the right newsitem text are displayed nicely. But the left cuts it off really bad. You can only see the top half of the text at the last sentence. I use overflow: hidden; to make sure the text doesn't make the div or newsitem bigger. Does anyone have any idea how to solve this through HTML and CSS or should I cut it off serverside with PHP?
Here's my code (HTML):
<div class="newsitem">
<div class="titlemessagewrapper">
<h2 class="titel" align="center"><?php echo $row['homepagetitel']; ?></h2>
<div class="newsbericht">
<?php echo $row['homepagebericht']; ?>
</div>
</div>
<div class="newsfooter">
<span class="footer_author"><?php echo get_gebruikersnaam_by_id($row['poster_id']); ?></span> <span class="footer_comment">Comments <span>todo</span></span>
Lees meer
</div>
</div>
And here is the CSS:
.newsitem{
float: left;
height: 375px;
width: 296px;
margin: 20px 20px 0px 20px;
background-color: #F5F5F5;
}
.newsitem .titel{
color:#132055;
font-size:1.2em;
line-height:1.3em;
font-weight:bold;
margin:10px 5px 5px 5px;
padding:0 0 6px 0;
border-bottom:1px dashed #9c0001;
}
.titlemessagewrapper{
height: 335px;
overflow: hidden;
}
.newsitem .newsbericht{
padding:5px 5px 5px 5px;
font-size: 0.8em;
margin-bottom: 5px;
}
.newsitem .newsfooter{
width: 100%;
height: 25px;
background-color: #132055;
margin: 0px auto;
font-size: 0.8em;
padding-top: 5px;
margin-top: 10px;
border: 1px solid #9c0001;
}
You should not rely on the user to enter <cut> !
User Input = error
What if the user forgets to enter <cut>? Will your news item now look unprofessional?
What would be the point of a user creating a news item to find that some of it was cut off?
If the div can only fit a fixed string length you should validate the max length of the news item Input body instead of relying on <cut>. This can be simply achieved using maxlength attribute.
<textarea id="userinput" maxlength="150">Enter your news</textarea>
If you do use <cut> you should also add in overflow: hidden; to ensure that the content is not unprofessionally displayed if no cut tag is present.
If you want to display the all text and keep the div the same fixed height
Replace
overflow: hidden;
with
overflow:auto;
(Scroll bar won't appear when content is smaller than the div)
Otherwise validate the length of the string / content in your div or remove the CSS height attribute to allow all the content appear with no scroll bars.
Hope this helps
Remove the height attribute on the .titlemessagewrapper. Its this height attribute which is causing the cut off.
If you want the boxes to remain the same height: Take the whole string, perform substr and save in a new variable and echo that.
Eg.
<?php
$str = "abcdefghijkl";
$new_strsubstr($str, 0, 8); // abcdef
// will return abcdefhi
?>

Categories