Styles using CSS issue - html

I want my comments input text box to be bigger than other fields in the form. I have got the following code in my add form:
<div class="divm centerdiv">
<?php echo $this->Form->create('Call'); ?>
<fieldset>
<legend><?php echo __('Add Call Details'); ?></legend>
<?php
echo $this->Form->input('call_date',array('required'=>false,'id'=>'datepicker','type'=>'text'));
echo $this->Form->input('call_time', array('required'=>false));
echo $this->Form->input('comments', array('required'=>false, 'id'=> 'comments'));
echo $this->Form->input('next_call_date',array('required'=>false,'id'=>'datepicker2','type'=>'text'));
echo $this->Form->input('customers_id', array('label' =>'Customer Name','options'=>$customers, 'label'=>'Customer Name', 'required'=>false));
echo $this->Form->input('employees_id', array('label' =>'Employee name','options'=>$employees, 'label'=>'Employee name', 'required'=>false));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
I have added an ID for the comments and my style sheet as follows:
//some code
.divm
{
width: 50%;
}
.centerdiv
{
margin: 50px auto;
}
divm.comments{
height: 20px;
width: 20px;
}
//some code
I want to change the size of the text box of comments to a bigger size than the other fields. I have tried to do this by adding the "divm.comments{}" parts in the style sheet adn it doesn't seem to work.Can someone help?

You are using the wrong (in this case invalid) selector. It should just be
#comments {
height: 20px;
}
For information, the syntax you used to trying to select an element with a tag name of divm (no such thing) that has a class name = comments
What you may have been thinking is select input with id = comments inside div with class = divm in which case it should have been .divm #comments (note the space) however it always more performant to select elements with id (they - or at least should be - unique)

You can use # for element IDs. . is for classes. Your new style sheet would be as follows:
.divm
{
width: 50%;
}
.centerdiv
{
margin: 50px auto;
}
#comments
{
height: 20px;
width: 20px;
}
Note: IDs must pertain to only one element so if you want to have multiple comments fields your original css would be correct (apart from the missing . before divm.comments) but you'd have to set comments as the class in php.

Related

Deconfiguration of images by applying length and height to them

I'm trying to present 3 images within 3 divs. I'm working on the server side, so I use HTML string. I'm using ajax to communicate from server to web page. Then I use append to a div, in the web page to display the image.
Everything works fine until I apply the size that the image has to have.
My code for one image:
$html_2 = "<div class=\"box--test-item\"";
$html_2 = $html_2."<img class=\"main-img\" src=\"data/photos/datateste_".$idtest."/photo.jpg\" alt=\"test\" style= \"{height: 280px; width: 180px;}\">";
//Html string with information about the image.
$html_2 = $html_2."</div>";
In my error console:
element {
{
height: 280px;
width: 100px;
}: ;
The part underlined is error (invalid property value).
The visual bug it's related to the height of the image.
Since your using HTML string, the inline style attribute need not have curly braces {}.
Instead just style="height: 280px; width: 180px;" should work.
No change in rest of the code.
php code here
<?php
$html_2 = '<div class="box--test-item">';
$html_2 .= '<img class="main-img" src="data/photos/datateste_"'.$idtest.'"/photo.jpg" alt="test" style="height: 280px; width: 180px;">';
//Html string with information about the image.
$html_2 .= '</div>';
?>

CSS values from dynamic HTML attribute or class in order to avoid inline styles?

As we all know inline styles are not good practice and they are not compatible with e.g. the Content Security Policy.
This is what I want to achieve without inline styles:
<?php
$spacer_height = 390; // this is a dynamic value from user input could be any integer
?>
<div class="spacer" style="height:<?php echo $spacer_height; ?>"></div>
This is what I want:
HTML:
<?php
$spacer_height = 390; // this is a dynamic value from user input
?>
<div class="spacer spacerheight-<?php echo $spacer_height; ?>" data-height="<?php echo $spacer_height; ?>"></div>
External Stylesheet:
.spacer {
height: spacer_height + "px"; // this line is dummy code
}
Is where a way to achieve this with CSS only. No JavaScript. No Polyfill.
What I have already found is this 5 year old question: CSS values using HTML5 data attribute
However is there a solution meanwhile or is there a CSS solution not using attributes? Is there at least a solution for integers?
Edit: Even a working polyfill may be a welcome answer if there is no other solution.
As you can't do this CSS only (yet, since the attr() function only returns string value), here is a simple script that will do something similar what attr() does, though this parse the data and sets it dynamically using cssText.
Let me know if I got this right
window.addEventListener("load", function() {
var mb = isMobile();
var el = document.querySelectorAll('[data-css]');
for (i = 0; i < el.length; i++) {
var what = el[i].getAttribute('data-css');
if (what) {
what = what.split(',');
el[i].style.cssText = what[0] + ': ' + ((mb) ? what[2] : what[1]) + 'px';
}
}
});
function isMobile() {
//function that check if user is on mobile etc.
return false; // return false for this demo
}
html, body {
margin: 0;
}
div {
background-color: lightgreen;
padding: 10px 0;
height: auto;
box-sizing: border-box;
}
div ~ div {
margin-top: 10px;
}
<div data-css="height,60,30"></div>
<div></div>
<div></div>
<div data-css="height,60,30"></div>
<div></div>
Another option would be to run something server side, where you simply create the CSS rule and class and insert it into CSS file and markup respectively, before sending to the client
You might consider moving the dynamic part from being inline to being referenced in a <style>.
<style>
.spacer {
height:<?php echo $spacer_height; ?>
}
</style>
<?php
$spacer_height = 390; // this is a dynamic value from user input could be any integer
?>
<div class="spacer"></div>

Getting a variable inside a external css file

i have a case in which the two values of the following should be changing according to the data in database.
In a external css file i have this.
#wow-container1 {
zoom: 1;
position: relative;
width: 100%;
max-width:960px;
max-height:360px;
margin:0px auto 0px;
z-index:90;
border:2px solid #FFFFFF;
text-align:left;
font-size: 10px;
}
my requirement is i need to change the max-height:max-width: when the height and width stored in database is changed.Is there any possible solution.?
Try this using jQuery .css()
var width = "value from DB";
var height = "value from DB";
$('#wow-container1').css({ 'max-width' : width, 'max-height' : height });
you can get max-height,max-width from db,
Example in php:
<?php
$max_height='300px';//you have to get the value form db
$max_width='300px'; //you have to get the value form db
?>
then write beloved css part after calling your external css file
<style>
#wow-container1 {
max-width:<?php echo $max_width; ?>;
max-height:<?php echo $max_height; ?>;
}
</style>
You can do it in your programming language.
.css() jquery is the best solution for this. If you want to change it using css,
you have to put database value in inline css written in same page. like this :
<style>
#wow-container1 {
max-width:<?php echo $width; ?>;
max-height:<?php echo $height; ?>;
}
</style>
If you want to use jquery .css(), it will be like this :
var width = "width from database";
var height = "height from database";
$('#wow-container1').css({ 'max-width' : width, 'max-height' : height });
When you learn http://VueJS.org you can use 'v-blind' to do that, very simple!

Adding two value to WP custom fields

I have a custom-field applied to specific posts, but I want to add two values to one field. How do I do that from the admin side?
CSS
.post-1 {
text-align: left;
padding-left: 50px;
background-position: left center;
float: left;
}
I want to add '.bgAlign' class to the value of ExtraCSS. I tried just adding it but doesnt seem to work.
You can simple append your class after post-1 with comma separator. It would be look like post-1,bgAlign,one-more-class.
Use this to output
<?php global $post; ?>
<div class="<?php echo str_replace(',', ' ', get_post_meta($post->ID, 'ExtraCSS', true)); ?>"></div>
Changing commas with spaces

Horizontal Forms instead of vertical

Language: PHP, HTML
Hi, I am having an issue with making some buttons that represent rooms.
Each button is labelled with a room number and I am trying to get the buttons to be side by side.
foreach($row1 as $row2)
{
echo "<form method='post' action='ss room details.php'>";
echo "<button>".$row2."</button>";
echo "<input type=hidden name=roomNum value=".$row2.">";
echo "</form>";
}
echo "</td>";
The buttons are listed vertically and make a new line for each button. How do I display it horizontally?
Thanks!
The buttons wouldn't probably end up next to each other horizontally, except for the fact that you're including each one in a separate form element. In your css, you can float the form left:
form {
float: left;
}
You could also float the buttons, too -- make sure to try it in different browsers. Wouldn't hurt to include a CSS reset template too.
You can either use float:left like #compeek has mention or you can use break tags like this:
foreach($row1 as $row2)
{
echo "<form method='post' action='ss room details.php'>";
echo "<button>".$row2."<br/>";
echo "<input type=hidden name=roomNum value=".$row2."><br/>";
echo "</form>";
}
echo "";
You want to float: left; (CSS) on each one.
However, floating acts kind of strange sometimes, so you'll definitely want to do some Googling to get a good idea of how it works.
So, to quickly show you with inline CSS, modifying your original code:
foreach($row1 as $row2)
{
echo "<form method='post' action='ss room details.php'>";
echo "<button style=\"float: left;\">".$row2."</button>";
echo "<input type=hidden name=roomNum value=".$row2.">";
echo "</form>";
}
echo "</td>";
EDIT: It's never a good idea to use inline CSS, though, so putting the CSS in your spreadsheet is a much better idea:
button {
float: left;
}
I would tend to use display: inline. This will make the form and the button behave like normal elements in the text flow. Do a line break <br> where necessary.
form { display: inline }
button { display: inline }