Keeping CSS elements inline when window shrinks - css

I have a form that wont stay aligned when I shrink the page. The div2 will move over to the left and intrude on div1 and the button positions become all jumbled. I have been reading up on css and thought the way to go was making a wrapper div then two child divs for my input types but it doesnt seem to work. I have tried all sorts of things I have found all to no avail. Ideally I would like the elements to all shrink proportionally and stay alaigned as the window shrinks. Absent that I would at least like the elements to just disappear off screen as it shrinks with scroll bars. Any help is musch appreciated.
HTML:
<form action="updated_tt.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo $id; ?>" />
<div id="wrap">
<div id="div1">
Trouble Report/Request:<br/>
<textarea class="tt_fld5" name="ud_problem" maxlength="300" rows="3" wrap=HARD ><?php echo $problem; ?></textarea> <br/>
</div>
<div id="div2">
Action Taken: <br/>
<textarea class="tt_fld5" name="ud_act_tkn" maxlength="300" cols="40" rows="3" wrap=HARD ><?php echo $act_tkn; ?></textarea>
</div>
</div>
<br/>
<br/>
<?php
/* Here we create an array of the drop down list choices, then go thru the array one by one and check for the "selected" attribute.
If the value retrieved from MySQL equals the ddown_options array element then construct <option> line with the "selected" value, else construct
a normal <option> line. Note We have to Make this a form here.*/
$option_to_preselect = $tkt_status;
$ddown_options = array
(
'Open',
'Referred',
'Closed',
);
echo '<span class=tt_fld>Ticket Status: ' . '</span>' . '<br />';
$arrlength=count($ddown_options);
print '<select name="ud_ticket_status" id="input_select">';
for ($x=0;$x<$arrlength;$x++)
{
if ($ddown_options[$x] == $option_to_preselect)
{
print ' <option value="' . $ddown_options[$x] . '"' . ' selected="selected">' . $ddown_options[$x] . '</option>';
}
else {
print ' <option value="' . $ddown_options[$x] . '">' . $ddown_options[$x] . '</option>';
}
}
print '</select>';
echo '<br />';
echo '<br />';
/* For Assigned Tech...*/
echo '<span class=tt_fld>Assigned To: ' . '</span>' . '<br />';
$option_to_preselect = $assgnd_tech;
$ddown_options = array
(
'Unassigned',
'***',
'***',
'***',
'***',
);
$arrlength=count($ddown_options);
print '<select name="ud_assgnd_tech" id="input_select">';
for ($x=0;$x<$arrlength;$x++)
{
if ($ddown_options[$x] == $option_to_preselect)
{
print ' <option value="' . $ddown_options[$x] . '"' . ' selected="selected">' . $ddown_options[$x] . '</option>';
}
else {
print ' <option value="' . $ddown_options[$x] . '">' . $ddown_options[$x] . '</option>';
}
}
print '</select>';
?>
<br />
<center><button type="submit" class="btn btn-primary btn-lg" onclick="updated.php">Update Trouble Ticket</button></center>
<br />
<!-- Indicates a dangerous or potentially negative action -->
<center><button type="button" class="btn btn-danger" onclick="Del_Function()">Delete Trouble Ticket</button></center>
</form>
CSS:
#wrap {
overflow: hidden;
padding: 2px 0 0 0;
width: 94%;
margin: 25 auto;
}
#div1 {
font-weight: bold;
font: x-large serif;
font-weight: bold;
float: left;
width: 47%;
margin-top: 10px;
}
#div2 {
font: large serif;
float: right;
width: 47%;
margin-top: 10px;
font-weight: bold;
font-size: x-large;
}

The float attribute is specifically used to allow content to flow around block content depending on page dimensions. Instead of floating your content divs, try relative positioning.

Here's the CSS that worked for me just for the record:
#wrap {
overflow: hidden;
padding: 2px 0 0 0;
width: 1200px;
min-height:150px;
margin: 25 auto;
}
#div1 {
font: large serif;
font-weight: bold;
position: relative;
left: 10px;
width: 300px;
font-size: x-large;
max-width:300px;
}
#div2 {
font: large serif;
font-weight: bold;
font-size: x-large;
position: relative;
left: 600px;
width: 300px;
bottom:155px;
}

Related

How to override CSS class over input[type]?

I am trying to override the input type
input[type="number"] {
width: 100px;
}
with the following css classes.
.choice_num{
width: 83px;
text-align:right;
padding: 2px;
font-weight: bold;
}
.choice_num_1{
width: 82px;
text-align:right;
padding: 2px;
font-weight: bold;
margin-right: 2px;
}
.float_nums{
width: 62px;
text-align:right;
padding: 2px;
font-weight: bold;
}
but it doesn't seem to work. Any ideas?
This is the code that you asked (sorry it didn't occur to me to add it.)
<input type="number" class="choice_num" step="<?php echo $epilogi['posotita']; ?>" min="<?php echo $epilogi['posotita']; ?>" value="<?php echo $epilogi['posotita']; ?>" onchange="calculate()" id="a1" name="posotita">
<input type="text" class="tmxs" value="KG" readonly="readonly" name="monmetr">
<input type="number" class="choice_num_1" value="<?php echo $epilogi['timi']; ?>" id="a2" readonly="readonly">
<?php } ?>
<input type="number" class="float_nums" value="<?php echo number_format((float)$sum, 2, '.', ''); ?>" id="a3" readonly="readonly">
Just add input before them, like this,
input[type="number"] {
background-color: orange
}
input.choice_num {
background-color: blue
}
input.choice_num_1 {
background-color: green
}
input.float_nums {
background-color: red
}
<input type="number" />
<input type="number" class="choice_num" />
<input type="number" class="choice_num_1" />
<input type="number" class="float_nums" />
By doing it the specificity of the later selectors increase and thus ur css works,
Just add more priority to it. Fast way to do it:
Instead of .choice_num select input.choice_num

Change css of radiolist in yii2

I have some radiolist in yii2 as following -
<?php
echo $form->field($model, 'wp_spost1')->radioList(['Yes'=>'Yes','No'=>'No','NA'=>'NA'])->label(false);
?>
It dissolves to following HTML
<div id="workpermit-wp_spost1" aria-required="true" aria-invalid="false"><div class="radio"><label><input type="radio" name="Workpermit[wp_spost1]" value="Yes" data-index="0"> Yes</label></div>
<div class="radio"><label><input type="radio" name="Workpermit[wp_spost1]" value="No" data-index="1"> No</label></div>
<div class="radio"><label><input type="radio" name="Workpermit[wp_spost1]" value="NA" checked="" data-index="2"> NA</label></div></div>
The css I'm trying to use is below -
.radio label
{
position:relative;
display: inline-block;
margin: 2px 2px;
padding: 2px;
width: 35px;
background: #ffffff;
border: 1px solid #008eff;
border-radius: 4px;
}
.radio input[type="radio"]:checked
{
box-shadow: 0 0 0 3px orange;
}
.radio input:checked {
color: red;
border: 10px solid #fff;
}
Current output
What I'm trying to achieve is that, when a radio button is checked, the border should be 10px wide and colour (of both the text and the border) should change. But I'm unable to target the border and the label.
Please help.
EDIT
I was trying different settings and made some changes in the HTML and css as below -
HTML - (Please note the label tag for earlier and now)
<div id="workpermit-wp_spost1" aria-required="true" aria-invalid="false">
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="Yes"><label>Yes</label></div>
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="No"><label>No</label></div>
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="NA"><label>NA</label></div>
</div>
CSS
.radio input[type="radio"]:checked
{
box-shadow: 0 0 0 3px orange;
}
.radio input[type="radio"]:checked + label {
color: red;
border: 10px solid #fff;
}
This combination is working. But unfortunately I cannot change the HTML manually. So the HTML I cannot change. can we anyway select the label on the earlier HTML setting.
You can change HTML. if you want at the end the code
<div id="workpermit-wp_spost1" aria-required="true" aria-invalid="false">
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="Yes"><label>Yes</label></div>
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="No"><label>No</label></div>
<div class="radio"><input type="radio" name="Workpermit[wp_spost1]" value="NA"><label>NA</label></div>
</div>
You can do something like this
echo $form->field($model, 'wp_spost1')->radioList(['Yes'=>'Yes','No'=>'No','NA'=>'NA'], ['item' => function($index, $label, $name, $checked, $value) {
if ($checked) {
$checkedText = 'checked="checked"';
} else {
$checkedText = '';
}
$return = '<div class="radio">';
$return .= ' <input id="workpermit-wp_spost1_' . $index . '" type="radio" name="' . $name . '" value="' . $value . '" ' . $checkedText . '>';
$return .= '<label for="workpermit-wp_spost1_' . $index . '">'. ucwords($label).' </label></div>';
return $return;
}
])->label(false);

How do I align this div to the bottom-right/left in the parent div?

So, I have been trying to get the < div with id="action"> to the bottom of the < div with class="right">. In the code you can see I tried to do it with position relative and bottom :0 but it doesn't do anything. I can float to the right so that fine so I just need to get it to the bottom. Right now it just keeps placing right below the text.
echo "<div class=\"product\">";
echo "<div class=\"left\">";
echo "<div style=\"width:225px;height:180px;background:#ccc\">" . $obj->product_img_name . "</div>";
echo "</div>";
echo "<div class=\"right\">";
echo "<form method='post' action='update.php'>";
echo "<h3>" . $obj->product_name . "</h3>";
echo "<p>" . $obj->product_desc . "</p>";
echo '<input type="hidden" name="action" value="add" />';
echo "<input type=\"hidden\" name=\"id\" value=\" $obj->id \" />";
echo "<div id=\"action\" style=\"position:relative;bottom:0;float:right;\">";
echo $obj->price;
echo <input type=\"text\" name=\"quantity\" />";
echo "<input type='submit' value ='Add To Cart'>";
echo "</div>";
echo "</form>";
echo "</div>";
I thought it couldn't because of the div being in the form but I tried to put a div below the form and see if relative works but it still wouldnt work.
The css:
.wrapper{
width:824px;
padding:10px 20px;
margin:0 auto;
background:#eeeeee;
}
.right{
height:200px;
width:550px;
float:right;
}
.right p{
font-size:0.95em;
}
.left{
width:250px;
float:left;
padding:20px 0 0;
}
.product{
height:200px;
margin-bottom:50px;
}
If .action can be absolutely positioned...
.right {
position: relative;
/* other code */
}
.action {
position: absolute;
right: 0;
bottom: 0;
/* other code */
}

Text appearing outside of set width when echoing a variable

I've created an page where users can view images along with the image description although I'm having some issues with the CSS for the description. The description is retrieved via PHP and is shown as a echoed variable. The issue with this is that the descriptions seems to carry on along one single line when it should be carrying on within the div.
As shown below, it displays along one line when it should be wrapping below to the same width as the text area below the description.
I've tried changing the width of the .desc class to a set pixel width of 290px instead 100% (should still take the 290px from the image-desc class container) but I'm having no luck.
My current CSS:
.image-info {
width: 290px;
display: inline;
float: right;
}
.image-info .desc {
text-align: justify;
width: 290px;
margin: 10px 0px;
}
and the HTML:
<div class="image-info">
<? $desc = htmlentities($row['desc'], ENT_QUOTES, 'UTF-8'); ?>
← Back to Gallery
<div class="desc"><? echo $desc; ?></div>
<? if(empty($_SESSION['user'])) { } else { print '<i class="icon-chevron-down"></i>Options<br /><div class="slidingDes"><form action="admin/includes/edit-img.php?id=' . $id . '" method="post"> <textarea type="text" name="description" placeholder="' . $desc . '"></textarea> <br/><input type="submit" value="Change" class="btn btn-primary"/> </form><form action="admin/includes/cover-image.php?id=' . $id . '" method="post"> <input type="submit" value="Cover Photo" class="btn btn-danger"/> </form></div>';}?>
</div>
It seems that your content go beyond the limit when there is no white space in the word
so just add word-wrap:break-word; to imageInfo class
here is your css
.image-info {
width: 290px;
display: inline;
float: right;
word-wrap:break-word;
}
Take a look here in fiddle
Add the new CSS 3 word-break property:
word-break: break-word; /* Will prevent text from bleeding outside container */
Use the CSS3 word wrap
word-wrap:break-word;
This will force the text to go down

Css text spills out of div

I really dont know what to do.
I made a really simple guestbook, its ok and all, but when showing the comments
the text spills out from the div
I was trying with pre but didnt work
here is the css
.guestbook_content {
width: 100%;
height: 100%;
background: #FFE4E1;
padding: 5px;
font-size: 12px;
margin-bottom: 10px;
}
#box {
width: 628px;
height: 438px;
background: #fefefd ;
overflow-y: scroll;
overflow-x: hidden;
}
the html and php
<div id='box'>
<div id='box_title'></div>
<div id="box_text">
<?php
if(isset($_POST['mehet'])) {
$message= '';
$the_name= mysql_real_escape_string(strip_tags($_POST['nev']));
$comment = mysql_real_escape_string(strip_tags($_POST['comment']));
$date = date('Y.m.d H:i:s');
if(!empty($comment) && !empty($the_name)) {
//mysql_query("INSERT INTO vendeg (name, comment, date) VALUES ('$the_name', $comment', '$date')") or die(mysql_error());
mysql_query(" INSERT INTO guesstb(the_name, comment, date) VALUES ('$the_name', '$comment', '$date') ");
}else {
$message= '<b><font color="darkred">Pleasse fill out all inputs</b></font>';
}
}
?>
<?php echo $message; ?>
<form action='<?php echo the_permalink();?>' method='POST'>
<label for='nev' class='gbl'>Name:</label>
<input type='text' name='the_name' id='the_name' class='gbi'>
<label for='comm' class='gbl'>Comment:</label>
<textarea name='comment' id='comm' rows='5' cols='60' class='gbt'></textarea>
<input type='submit' class='submit' value='Beküld' name='mehet'>
</form>
<?php
$result = mysql_query("SELECT * FROM guesstbORDER BY date DESC");
while($row = mysql_fetch_array($result))
{
?><div class='guestbook_head'><span>sent by:</span> <b><?php echo $row['nev']; ?></b> <span> - date:</span> <?php echo $row['date']; ?> </div><?
?>
<div class='guestbook_content'><?echo $row['comment'];?></div>
<?
}
?>
could please someone could give me hint
.guestbook_content {
width: 100%; <-- drop this rule
height: 100%;
padding: 5px;
}
#box {
width: 628px;
}
You gave child div width: 100% + padding 5px, which makes = 100% of parent div :628px + 5px left padding + 5px right padding so child div is 638px wide. Just drop 100% width on child. All you need is padding.
Here is jsfiddle with your situation: http://jsfiddle.net/crg2U/2/
And here is with droped 100% width on child : http://jsfiddle.net/crg2U/3/

Resources