Horizontal Forms instead of vertical - html

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 }

Related

input tag inside p tag using jquery

$Option = "<p>6 < x < 8</p>" //For demo I have assigned directly, in reality the value will come from MySQL database.
I want to display this value something like:
But I am getting it like:
I know the reason why it is like that because the input tag is out of paragraph tag.
<input type="radio" name="<?php echo $i; ?>" value="A"><?php echo $Option; ?>
What can I do so that the radio button is inside paragraph tag?
p elements are block elements by default. You can make them inline elements by setting the display property value to inline:
$Option = '<p style="display:inline">6 < x < 8</p>';
Update: If you are not able to change the value of the variable then you can try using external or internal CSS:
input[type=radio] + p{
display: inline;
}

Styles using CSS issue

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.

Display list horizontally is not working with display inline

I'm trying to print out my list horizontally but it isn't working with display inline. I also used float: left; and position:center but then it isn't centered horizontally.
PHP
foreach ($memberinfo as $info)
{
echo "<ul><li><a href='profile.php?user_id=" . $info['user_id'] . "'><img class='group_member_img' src='uploads/" . $info['avatar'] . "'/><br>" . $info['surname'] . " " . $info['name'] . "</a></li></ul><br>";
}
CSS
.groupmember ul
{
margin:0;
list-style-type: none;
text-align:center;
}
.groupmember ul li
{
display:inline;
}
You are creating a new unordered list ul for every $memberinfo, so the display:inline is working, but the ul's remain like block elements.
Create the ul tag before the foreach and close it after it, so your list items will be displayed like you want:
echo "<ul>";
foreach ($memberinfo as $info) {
echo "<li><a href='profile.php?user_id=" . $info['user_id'] . "'><img class='group_member_img' src='uploads/" . $info['avatar'] . "'/><br>" . $info['surname'] . " " . $info['name'] . "</a></li>";
}
echo "</ul>";
By the way, the break line br tag is unnecessary because you want to put every li one beside the other.
Using display: inline-block as suggests probably the right solution here.
.groupmember ul li {
display:inline;
}
display: inline is not really useful for anything but elements that have no nested elements inside them.
display:inline is very limited and doesn't allow any block-level styling to added to it.
You're better off using display:inline-block or using float:left.
Keep in mind that if you use floats then you need to set the overflow of the parent element to overflow:auto (use visible for IE < 8) and this should work. Use inline-block first.

css - minumum margin between labels and their values

I need to apply a style class that will make a minumum margin to the right of labels. The tag is shown here with class "label-format":
echo '<p><span class="label-format">Make: </span>' . $term->name . '</p>';
echo '<p><span class="label-format">Model: </span>' . $term->name . '</p>';
echo '<p><span class="label-format">Condition: </span>' . $term->name . '</p>';
and I need to make it so that the values are pushed to the right like so (the periods represent whitespace):
Make:.........Ford
Model:........Focus
Condition:...New
the best I can get with margins is:
Make:...Ford
Model:...Focus
Condition:...New
A more maintainable option would simply be to use a table. For the <td>s containing the properties of $term, you could set text-align: left; and it will look the same.
You may use inline-block and whidth:
p span {
display:inline-block;
width:5em; /* here set width that you want*/
}
float:left; works too :)

How to display different colours in a select box for different options

I have part of a code where it displays a Multi Select box and displays the options depending on the if statement:
$moduleSELECT = '<select name="moduletextarea" id="moduleselect" size="10">'.PHP_EOL;
if($modulenum == 0){
$moduleSELECT .= "<option disabled='disabled' value=''>No Modules currently on this Course</option>";
}else{
while ( $currentmodstmt->fetch() ) {
$moduleSELECT .= sprintf("<option disabled='disabled' value='%s'>%s - %s</option>", $dbModuleId, $dbModuleNo, $dbModuleName) . PHP_EOL;
}
}
$moduleSELECT .= '</select>';
Now from doing some research on the internet I think it is bad practice to include tags inside option tags. So my question is that if the if statement is true where number of records in 0, how can I display the text for "<option disabled='disabled' value=''>No Modules currently on this Course</option>"; in red colour and if the else statement is met how can I display these options sprintf("<option disabled='disabled' value='%s'>%s - %s</option>", $dbModuleId, $dbModuleNo, $dbModuleName) . PHP_EOL; in black colour text?
Thanks
just set a css style to the select (if there are no options), in this case color: red;
you can also have different colors for the options as well, just set different colors on each option. example fiddle here: http://jsfiddle.net/kennypu/CP8Xf/1/
I don't believe you can style individual <option> tags with CSS, but you could style the entire <select> as #kennypu points out.
Another way to achieve the results you want with a better/more intuative UI might be to only output the <select> tag when you actually have data to put inside it. When $modulenum == 0 maybe you should just output some different HTML that you can style properly.
HTML
<div class='no-data'>No Modules currently on this Course</div>
CSS
.no-data{
background-color: #CCC;
color: red;
padding: 5px;
}