line break despite z-index? - php

hello i have a problem using z-index. i have a form with some input fields. beside them i have some error divs for echoing the php error messages. the problem i have is, that the error divs, that only will come up when a error is set, leads to a line break for the input fields.
.wrapper #mainframe #left #frame form fieldset ul .fr {
width: 180px;
float: left;
margin-bottom: 18px;
margin-left: 25px;
}
.wrapper #mainframe #left #frame form fieldset ul input.err {
width: 180px;
height: 18px;
line-height: 18px;
padding-left: 5px;
margin-top: 3px;
outline:none;
background-image: url(../images/error.png);
background-repeat:no-repeat;
background-position: 172px 50%;
}
.wrapper #mainframe #left #frame form fieldset ul .erl {
color: #FFF;
position: relative;
z-index: 1;
background-color: #f23;
width: 200px;
height: 30px;
font-family:Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
line-height: 30px;
text-align: center;
left: +217px;
top: 25px;
}
here is the html code:
<li class="fr">
<label for="a">a</label>
<?php if (isset($errors['a'])):?>
<input class="err" type="text" id="a" name="a" value="<?php echo isset ($_POST['a'])? $_POST['a'] : ''; ?>" tabindex="20" autocomplete="off"/>
<?php if ( isset($errors['a'])
&& empty($errors['a'][0]) == true ):?>
<?php echo "<div class='erl'>";
echo $errors['a'][0];
echo "</div>";
endif;?>
<?php endif;?>
so i dont understand why this is happening. i thought using z-index would be something like causing two layers (z-index:0 and z-index:1) so that there should be enough place left and right hand side on the second layer z-index:1. if there is someone who could tell me how to solve this i really would appreciate. thanks a lot.

I would look for things like padding and margin (http://css-tricks.com/the-css-box-model/) that may be adding unintended spacing and overall width.
Also, check to be sure that whatever elements you apply z-index have their position explicitly declared... also the positioning of the parent elements (http://tjkdesign.com/articles/z-index/teach_yourself_how_elements_stack.asp).
Finally, I would look at issues with the hasLayout property (http://www.satzansatz.de/cssd/onhavinglayout.html). This may be what Vinny is talking about, since Z-index does not change the way the document flows so much as the stack order. Try using position:absolute on your error messages to remove them from the overall flow of the document.

To avoid line-breakage, you will need to remove the error element from the flow of the document. The z-index attribute has absolutely nothing to do with that; it only effects the stack order of the element, otherwise it is position-agnostic.
Which is why I referred you to this jsfiddle; an alternative to help fix your woes.

Try this:
HTML:
<li class="fr">
<label for="a">a</label>
<input class="err" type="text" id="a" name="a" value="" tabindex="20" autocomplete="off"/>
<div class='erl'> Error text</div>
<div class="sp"></div>
</li>
CSS:
//for label
.fr label, .fr .err, .fr .erl {
float:left;
}
.fr .sp {
clear:both;
}

Related

Checkbox array (square brackets) - all have the same name and 'checked' is not working

I have a number of checkboxes that return an array of data to PHP. They are all named 'Plans[]' but with different IDs.
I have a CSS checkbox styler that replaces the usual HTML checkbox with something more fancy...
When the page is displayed, there is one (or several) that are 'checked', but they don't display as checked (I think one does but that is hidden usually).
I am assuming that the problem is caused by them all having the same name and so somehow they are the checked attribute is not getting acted on for all of them for this reason.
I have tried wrapping each of them in their own forms (as I saw this suggested elsewhere) but to no avail.
Here's an example of what it looks like:
<style type="text/css">
.checkOpt input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create a custom radio button */
.checkmark {
position: absolute;
top: -.3em;
right: 5%;
height: 25px;
width: 25px;
background-color: #fff;
border-radius: 20%;
border: 1px;
border-color: #1e62d0;
border-style: dashed;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
font-weight: 900;
color: blue;
margin-top: -11px;
margin-left: -3px;
font-family: Arial, Helvetica, sans-serif;
font-size: 28px;
content: "\2714";
position: absolute;
display: none;
}
/* Style the indicator (dot/circle) */
.checkOpt .checkmark:after {
top: 8px;
left: 9px;
width: 8px;
height: 8px;
border-radius: 50%;
/* background: white; */
text-shadow: -1px -1px 0 #7f7f7f, 1px -1px 0 #7f7f7f, -1px 1px 0 #7f7f7f, 1px 1px 0 #7f7f7f;
}
/* Show the indicator (dot/circle) when checked */
.checkOpt input:checked~.checkmark:after {
display: block;
}
/* On mouse-over, add a grey background color */
.checkOpt:hover input ~ .checkmark {
background-color: #97c4fe;
}
/* When the radio button is checked, add a blue background */
.checkOpt input:checked ~ .checkmark {
background-color: #2196F3;
}
.checkOpt input:disabled ~ .checkmark {
background-color:#b0c7df; pointer:default;
}
.test {
position: relative;
height:60px;
}
</style>
<div class="test">
<div class="checkOpt" style="top:20px;">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line - OFNL" id="12" value="0.00" checked="checked" >
<span class="checkmark"></span>
</label>
</div>
</div>
<div class="test">
<div class="checkOpt" >
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Paper Bill" id="35" value="2.00" >
<span class="checkmark"></span>
</label>
</div>
</div>
<div class="test">
<div class="checkOpt">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line " id="12" value="0.00" checked="checked" disabled="disabled">
<span class="checkmark"></span>
</label>
</div>
</div>
...only one of these (the first) is showing as checked - the rest are not.
Does anyone have any ideas what I might do to get round this (without coding changes to the subsequent data collection if possible!)
tried everything I can think of and would welcome any suggestions....
UPDATE - I tried updating the page so that the checkboxes have different names ('Plans[0]', 'Plans[1]' etc.) and the checkmarks suddenly started to appear in the right places.
The issue is now that there is (legacy) JQuery code that doesn't work, i.e.
$("input[name='plans[]']:checked").each(function(){
var thisPlan= $(this).attr('id'); var thisVal = $(this).attr('value');
plans.push(thisPlan);
planValues.push(thisVal);
// ....
// ....
}
I guess this would work if the Plans list were just POSTed and picked up by PHP, but in fact it is intercepted by Javascript, processed and re-posted via Ajax to the next (PHP) page (where it is picked up quite simply by $_POST['plans']). It's a real mess, but Ihave inherited it...
Anyone have any idea how I could work round this without breaking all the legacy (Javascript/JQuery) code?
SOLVED. I have discovered that there is actually a bit of Javascript/JQuery code that is overwriting the 'checked' attribute and this is causing the problem. The 'name' duplication was a red herring - by changing the names (from 'plans[]') I just stopped the code working (it used $('input[name="plans[]"]').each(function ()).
Thanks for your suggestions and help - Sorry to waste anyone's time. It's a bit of a nightmare trying to unravel someone else's mucky code!
Now I just have to get the functionality to work without that code...
The issue is that you're absolutely positioning them as Quentin stated in the comments. There are a few other issues:
You have two elements with the same ID and this isn't permitted (12)
IDs should start with a letter
Your first element has the attributed disabled = "" but this will make the item disabled irrespective of the value of the attribute. It's not ideal, I know.
disabled element values are usually not sent with the form (see link in the bullet point above) which may explain why it's not getting to your server script. this might be the cause as the check box is ticked but also disabled and the browser may be just ignoring all disabled checkboxes when sending the form data.
It's the same for checked = "", if the checked attribute is present on in you input element it'll still be checked.
I've had a go at what I think you're trying to achieve and marked up any changes.
.checkOpt {
/* added this so the container has some size */
height: fit-content;
display: inline-block;
}
.checkOpt input {
/* added this, you're looking to make your checkbox invisible so just use display:none */
display:none;
/* removed this
position: absolute;
opacity: 0;
cursor: pointer;
*/
}
/* Create a custom radio button */
.checkmark {
/* removed this
position: absolute;
top: 0em;
/*
right: 5%;*/
/* added this so that the tick marks are positioned in the middle so you don't have to use
absolute positioning on them */
display: inline-flex;
align-items:center;
justify-content:center;
height: 25px;
width: 25px;
background-color: #fff;
border-radius: 20%;
border: 1px;
border-color: #1e62d0;
border-style: dashed;
cursor:pointer;
}
.checkb:checked ~ .checkmark:after {
/*if the checkbox is checked then make the tick appear by making it opaque */
opacity:1;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
font-weight: 900;
/*color: white;
margin-top: -11px;
margin-left: -3px;*/
font-family: Arial, Helvetica, sans-serif;
font-size: 28px;
content: "\2714";
/* added this - makes the tick mark transparent when it's not checked */
opacity: 0;
/*position: absolute;*/
/*display: none;*/
}
.checkb:disabled ~ .checkmark:after {
/* I noticed that you had the disabled attribute set in your HTML so I've styled this gray so you know it's
not click-able */
color:lightgray;
}
<div class="checkOpt">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line - OFNL" id="a12" value="0.00" checked="checked" disabled="" autocomplete="off">
<span class="checkmark"></span>
</label>
</div>
<div class="checkOpt">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Paper Bill" id="a35" value="2.00" autocomplete="off">
<span class="checkmark"></span>
</label>
</div>
<div class="checkOpt">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line " id="a12X" value="0.00" autocomplete="off" checked="checked" disabled="disabled">
<span class="checkmark"></span>
</label>
</div>

Why doesn't display:inline-block work for my HTML?

The display: inline-block technique to make div elements appear next to each other does not work with my dynamically-generated content cards.
My content cards are a modified version of a tutorial found on the w3schools website, which can be found here:
https://www.w3schools.com/howto/howto_css_cards.asp
Goal
I'm in the process of creating a relatively simple search engine for my website based on a query that checks a MySQL database for any potential matches. The results are returned in the form of a content card. If the system finds 3 matches, 3 content cards will be generated in the results. The code is being controlled by a for-loop (PHP) that generates a content card for each match found.
Problem
The corresponding content cards are generated for each match, however, they appear on separate lines below each other (vertically). I attempted to use the display: inline-block technique to force them next to each other with no results. I suspect the reason why is because the code for each content card must already be there for the effect to take place. If not, CSS & HTML assume that there was only ever one content card and doesn't align them properly.
HTML/CSS/PHP Code for Content Cards
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 300px;
margin: auto;
text-align: center;
font-family: arial;
width: 30%;
}
.card button {
border: none;
outline: 0;
padding: 12px;
color: white;
background-color: #000;
text-align: center;
cursor: pointer;
width: 20%;
font-size: 18px;
}
.card button:hover {
opacity: 0.7;
}
.shrink {
-webkit-transform: scale(0.8);
-moz-transform: scale(0.8);
-ms-transform: scale(0.8);
transform: scale(0.8);
}
<!-- Container -->
<div class="container" style="background-color: white; width:89%; padding-top: 400px;">
<!-- Generates 1 Content Card for each Match -->
<?php
for($x = 0; $x < count($title); $x++) {
?>
<!-- Content Card Design & Data -->
<div class="shrink">
<div class="card" style="background-color: white; border-radius: 2%; display: inline-block;">
<a href="#" data-toggle="modal" data-target="#ModalCarousel<?php echo " $x ";?>" style="text-decoration: none; color: black;">
<img src="listingimages/<?php echo "$firstListingImage[$x]";?>" style="width:100%; border-top-left-radius: 2%; border-top-right-radius: 2%;">
<h4><?php echo "$title[$x]";?></h4>
<hr>
<p><span class = "glyphicon glyphicon-cutlery"></span> <?php echo "$foodType[$x]";?></p>
<hr>
<p><span class = "glyphicon glyphicon-map-marker"></span> <?php echo "$city[$x]";?>, <?php echo "$state[$x]";?></p>
<hr>
<p style="font-size: 30px;"><b>$<?php echo "$price[$x]";?></b><span style="font-size: 15px;"> USD</span></p>
</a>
</div>
</div>
<?php } ?>
</div>
It is very easy just you need to add in the class .card {float:left} then it will work as you want
With inline-block for it to work you must also set a fixed width on .shrink, which is the repeated holder, and maybe vertical-align
The preferred way nowadays is by setting display:flex; flex-wrap:wrap on the container which is made just for this kind of box display. Also set width on .shrink with this solution.
Your .cards are nicely displayed as inline-blocks, but they're each wrapped inside a .shrink which are full blocks. That's why they're not lining up as you'd expect.

How can I get a value from a personalized dropdown?

All the people use the normal dropdown like:
<form>
<select>
<option> bla bla </option>
</select>
</form>
Like that I can get the selected value trough PHP. But if I use divs I can't get the values from the multiple dropdowns.
function select_best_plan(sel, _this) {
$parent = $(_this).closest('.select-general');
$parent.find('button font').html($(_this).find('font').html());
$parent.find('.select-menu .select-menu-option').removeClass('active');
$(_this).addClass('active');
}
.select-general {
display: inline-block;
overflow: hidden;
border-radius: 12px;
vertical-align: middle;
position: relative;
text-transform: uppercase;
background: #182045;
color: #FFFFFF;
width: 170px;
min-width: 160px;
text-align: left;
font-size: 15px;
max-width: 100%;
}
.select-general .select-button {
text-align: right;
font-size: 13px;
height: 38px;
line-height: 38px;
padding: 0px 13px;
border-radius: 12px;
color: #FFFFFF;
width: 100%;
}
.select-general .select-button font {
text-align: left;
width: calc(100% - 20px);
height: 100%;
overflow: hidden;
max-width: 340px;
text-overflow: ellipsis;
white-space: nowrap;
}
.select-general .select-menu {
padding: 0px;
overflow: hidden;
max-height: 0;
transition: max-height 0.15s ease-out, padding 0.15s ease-out;
}
.select-general .select-menu-option {
text-align: right;
font-size: 13px;
height: 38px;
line-height: 38px;
padding: 0px 13px;
color: #FFFFFF;
width: calc(100% - 26px);
cursor: pointer;
}
.select-general .select-menu-option font {
text-align: left;
}
.select-general .select-menu-option:hover {
background: #1A2A74;
}
.select-general .select-menu-option.active {
opacity: 0.5;
}
.select-general:hover .select-menu {
padding: 10px 0px;
max-height: 500px;
transition: max-height 0.15s ease-in, padding 0.15s ease-in;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="select-general" style="width: 250px;">
<button class="select-button">
<font class="float-left">Quantos Utilizadores Quer?</font><i class="icon small caret down"></i>
</button>
<div class="select-menu">
<div class="select-menu-option" data="1" onclick="select_best_plan(6, this)">
<font class="float-left">Apenas 1</font>
</div>
<div class="select-menu-option" data="3" onclick="select_best_plan(7, this)">
<font class="float-left">Até 3</font>
</div>
<div class="select-menu-option" data="5" onclick="select_best_plan(8, this)">
<font class="float-left">Até 5</font>
</div>
<div class="select-menu-option" data="10" onclick="select_best_plan(9, this)">
<font class="float-left">Até 10</font>
</div>
<div class="select-menu-option" data="15" onclick="select_best_plan(10, this)">
<font class="float-left">Até 15</font>
</div>
</div>
</div>
My idea is that the people select the first div "Apenas 1" and on submit I get that values on PHP.
I really can't find any tips that can help me or I'm just newbie on this..
Thanks.
Just add <input type="hidden" name="select" id="hidden-select" />
Change <div class="select-menu-option" data="5" to ... data-val="5"
and in: select_best_plan add
$('#hidden-select').val($(_this).data('val'))
There is lot of content available online explaining a lot of ways to implement this kind of a behavior.
One such link -
How to use FormData for ajax file upload
Set value of hidden field in a form using jQuery's ".val()" doesn't work
For more ways of implementation you can google with these key words -
Ajax calls
Submitting form with hidden input fields
How to build and submit Form using FormData. etc
Sorry for the first answer.
Well if you want to use customize select then use JavaScript to get the data. Normally only input tags select can be post or send automatically by form tag.
The submit button triggers a JavaScript function then get the value of the selected div then create a input tag containing the value of the div.
Ex:
<div class="select-general" style="width: 250px;">
<button class="select-button">
<font class="float-left">Quantos Utilizadores Quer?</font><i class="icon small caret down"></i>
</button>
<div class="select-menu">
<div class="select-menu-option" data="1" onclick="select_best_plan(6, this)">
<font class="float-left">Apenas 1</font>
</div>
function getselectedval(){
var data = $("div selected identifier here").attr("data");
$("container of passing input").append('<input name="name" val="'+ data +'" type="hidden">');
//submit the form
$("your form").submit();
}
This seems to be a cheat but hope this helps.

CSS/HTML Gap Issue

Ok, so when I see my div on my site and whenever I load it up there is always a someone significantly noticeable gap between the text and space above the text. I dont know if somethings wrong with my CSS and I have no clue how to fix this...
Here is a screenshot and code -
Thank you :-)
#box2
{
overflow:auto;
border: 10px solid #a1a1a1;
padding: 95px; 40px;
width: 180px;
height: 5px;
border-radius: 25px;
margin-left:auto;
margin-right:0;
}
HERE IS SOME HTML
<!---Bad Rats--->
<img src="" width="450" height="200" align="left"></img>
<div id="box2">
<div id="reviewtext">
</div>
</div>
I guess the problem is in the invalid CSS making padding from all sides 95px:
padding: 95px; 40px;
Make it look something like:
padding: 0 40px;
JSFiddle

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