I can not find where the error is. I need to change the color of the current month in select option(only world "(current)")
Instead of that font tag you can style the option itself.
<?php
/*Array of months*/
$months = Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
$gd = getdate();
echo "<select style='font-size:40px;width:50%;float:left'>";
for($i=1;$i<=12;++$i)
{
/*Specify which style you want to apply*/
$style = ($gd['mon']==$i)?"style='color:red;'":"";
echo "<option value='".$i."' $style>". $month[$i] ." (current)</option>";
}
echo "</select>";
?>
Anyway this will color entire option not only current. Because it is not possible for an option to hold anything apart from plain text. So without using native select you can try this. code is heavy sorry for that but you can achieve what you want.
<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<?php
$months = Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
$gd = getdate();
echo "<select id='selectbox1' style='font-size:40px;width:50%;float:left'>";
for($i=1;$i<=12;++$i)
{
if($gd['mon']==$i)
{
echo "<option class='container' value='".$i."'>".$months[$i]." (current) </option>";
}
else
{
echo "<option value='".$i."'>".$months[$i]."</option>";
}
}
echo "</select>";
?>
<script type="text/javascript">
// Iterate over each select element
$('select').each(function() {
// Cache the number of options
var $this = $(this),
numberOfOptions = $(this).children('option').length;
// Hides the select element
$this.addClass('s-hidden');
// Wrap the select element in a div
$this.wrap('<div class="select"></div>');
// Insert a styled div to sit over the top of the hidden select element
$this.after('<div class="styledSelect"></div>');
// Cache the styled div
var $styledSelect = $this.next('div.styledSelect');
// Show the first select option in the styled div
$styledSelect.text($this.children('option').eq(0).text());
// Insert an unordered list after the styled div and also cache the list
var $list = $('<ul />', {
'class': 'options'
}).insertAfter($styledSelect);
// Insert a list item into the unordered list for each select option
for (var i = 0; i < numberOfOptions; i++) {
$('<li />', {
html: $this.children('option').eq(i).text()
.split(' ').join(' <span style="color:red">'),
rel: $this.children('option').eq(i).val()
}).appendTo($list);
}
// Cache the list items
var $listItems = $list.children('li');
// Show the unordered list when the styled div is clicked (also hides it if the div is clicked again)
$styledSelect.click(function(e) {
e.stopPropagation();
$('div.styledSelect.active').each(function() {
$(this).removeClass('active').next('ul.options').hide();
});
$(this).toggleClass('active').next('ul.options').toggle();
});
// Hides the unordered list when a list item is clicked and updates the styled div to show the selected list item
// Updates the select element to have the value of the equivalent option
$listItems.click(function(e) {
e.stopPropagation();
$styledSelect.text($(this).text()).removeClass('active');
$this.val($(this).attr('rel'));
$list.hide();
/* alert($this.val()); Uncomment this for demonstration! */
});
// Hides the unordered list when clicking outside of it
$(document).click(function() {
$styledSelect.removeClass('active');
$list.hide();
});
});
</script>
<style>
body {
padding:50px;
background-color:white;
}
.s-hidden {
visibility:hidden;
padding-right:10px;
}
.select {
cursor:pointer;
display:inline-block;
position:relative;
font:normal 11px/22px Arial,Sans-Serif;
color:black;
border:1px solid #ccc;
}
.styledSelect {
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
background-color:white;
padding:0 10px;
font-weight:bold;
}
.styledSelect:after {
content:"";
width:0;
height:0;
border:5px solid transparent;
border-color:black transparent transparent transparent;
position:absolute;
top:9px;
right:6px;
}
.styledSelect:active,
.styledSelect.active {
background-color:#eee;
}
.options {
display:none;
position:absolute;
top:100%;
right:0;
left:0;
z-index:999;
margin:0 0;
padding:0 0;
list-style:none;
border:1px solid #ccc;
background-color:white;
-webkit-box-shadow:0 1px 2px rgba(0,0,0,0.2);
-moz-box-shadow:0 1px 2px rgba(0,0,0,0.2);
box-shadow:0 1px 2px rgba(0,0,0,0.2);
}
.options li {
padding:0 6px;
margin:0 0;
padding:0 10px;
color: green;
}
.options li:hover {
background-color:#39f;
color:white;
}
</style>
example fiddle is : http://jsfiddle.net/tintucraju/3u9fkyd3/
The code itself seems to be correct. But as it can't be copied because of the image, i'm not willing to write it again.
Your main problem seems to be the current is not styled inside the select dropdown. Which could be a browser specific behaviour. To see if this is the case just replace the select with ul and the option with li tag. When it's shown correctly then you can't use font inside the option. Because select is a element which style is defined by the browser.
This is also the reason why bootstrap uses ul/li for rendering dropdown. As they can be styled independently from browsers.
Related
I have a question regarding how I might display a number of different background images on my site (not a slideshow but page specific backgrounds) along with an image title/credit line of text specific to each image?
I can position the text ok but not sure how to change the text with each new image.
This is what I have so far:
#header #headerbanner {
float: right;
width: 468px;
margin: 30px 0 10px 0;
text-align: left;
padding: 10px;
background: font-size: .8em;
line-height: 1.5em;
}
#header #headerbanner h3 {
font-size: 1.1em;
font-family: "Lucida Grande", "Lucida Sans
Unicode",Verdana,Arial,Helvetica,sans-serif;
}
#header #headerbanner p a {
border-bottom: 1px dashed #a8ef9d;
}
#header #headerbanner a:hover {
background: url(images/blacktrans.png);
}
<div id="headerbanner" class="widget widget_block widget_text">
<p>Image: Eildon Hills, Scottish Borders</p>
</div>
Thanks in advance.
S
I would use some JavaScript to always move to the next image/text:
setInterval(nextImage, 10000);
function nextImage() {
// Repeats every 5 seconds
}
Before this function just select the image and text element by using IDs and the JavaScript getElementById function.
<p id="text"></p>
<img id="img"></img>
text = document.getElementById('text');
img = document.getElementById('img');
And in this function set content of these elements
text.innerHTML = "Your Authors Name";
img.style.background = "url(newUrl/)";
In the function you should also use an Array with all names and images. And an counter and
if(counter>=imgArray.length) {
counter=0;
} else {
counter++;
}
And use the counter to display the text and image on the current position.
I've one array, which is output of some function and size of array is dynamic. So, I want to put all array element as drop-down with checkbox. Can anyone is here to help?
<select name="per1" id="per1">
<option selected="selected">Choose one</option>
<?php
foreach($names as $name) { ?>
<option value="<?= $name['name'] ?>"><?= $name['name'] ?></option>
<?php
} ?>
</select>
$names is example array take your.
check this link also
How to create checkbox inside dropdown?
Note
Okay, I can provide you a pseudo-code to help get you started. I borrowed my code from my own web server along with code from CodePen. Please note that I did not test the code, so do feel free to modify the code.
Code
PHP
<div class="dropdown" data-control="checkbox-dropdown">
<label class="dropdown-label">Select categories.</label>
<ul class="article-category-list dropdown-list">
<?php if(count($categories) > 0) {
foreach ($categories as $category) { ?>
<li class="article-category-listitem dropd-wn-listoption">
<input name="cbcategories[]"
id="cb<?=$category["CategoryID"] ?>" type="checkbox"
class="article-list-cb"
value="<?=$category['CategoryID'] ?>" />
<label class="article-list-lbl"
for="cb<?=$category["CategoryID"] ?>">
<?=$category['CategoryName'] ?>
</label>
</li>
<?php }} ?>
</ul>
</div>
This is a code borrowed from the administration portion of my blog that I haven't gotten into website development for a long time.
So the $categories variable is a list of categories for a blog. If the $categories array is greater than 0, PHP will loop through the $categories and will write out HTML code inside an unordered list, which contains the ID and name of the category.
CSS
(Borrowed from CodePen)
.dropdown {
position: relative;
font-size: 14px;
color: #333;
.dropdown-list {
padding: 12px;
background: #fff;
position: absolute;
top: 30px;
left: 2px;
right: 2px;
box-shadow: 0 1px 2px 1px rgba(0, 0, 0, .15);
transform-origin: 50% 0;
transform: scale(1, 0);
transition: transform .15s ease-in-out .15s;
max-height: 66vh;
overflow-y: scroll;
}
.dropdown-option {
display: block;
padding: 8px 12px;
opacity: 0;
transition: opacity .15s ease-in-out;
}
.dropdown-label {
display: block;
height: 30px;
background: #fff;
border: 1px solid #ccc;
padding: 6px 12px;
line-height: 1;
cursor: pointer;
&:before {
content: '▼';
float: right;
}
}
&.on {
.dropdown-list {
transform: scale(1, 1);
transition-delay: 0s;
.dropdown-option {
opacity: 1;
transition-delay: .2s;
}
}
.dropdown-label:before {
content: '▲';
}
}
[type="checkbox"] {
position: relative;
top: -1px;
margin-right: 4px;
}
}
It looks to me the "&.on" class is for when dropdown is opened.
jQuery
Now this code is in jQuery format. If you want plain JavaScript code, let me know.
(function($) {
var CheckboxDropdown = function(el) {
var _this = this;
this.isOpen = false;
this.areAllChecked = false;
this.$el = $(el);
this.$label = this.$el.find('.dropdown-label');
this.$checkAll = this.$el.find('[data-toggle="check-all"]').first();
this.$inputs = this.$el.find('[type="checkbox"]');
this.onCheckBox();
this.$label.on('click', function(e) {
e.preventDefault();
_this.toggleOpen();
});
this.$checkAll.on('click', function(e) {
e.preventDefault();
_this.onCheckAll();
});
this.$inputs.on('change', function(e) {
_this.onCheckBox();
});
};
CheckboxDropdown.prototype.onCheckBox = function() {
this.updateStatus();
};
CheckboxDropdown.prototype.updateStatus = function() {
var checked = this.$el.find(':checked');
this.areAllChecked = false;
this.$checkAll.html('Check All');
if(checked.length <= 0) {
this.$label.html('Select Options');
}
else if(checked.length === 1) {
this.$label.html(checked.parent('label').text());
}
else if(checked.length === this.$inputs.length) {
this.$label.html('All Selected');
this.areAllChecked = true;
this.$checkAll.html('Uncheck All');
}
else {
this.$label.html(checked.length + ' Selected');
}
};
CheckboxDropdown.prototype.onCheckAll = function(checkAll) {
if(!this.areAllChecked || checkAll) {
this.areAllChecked = true;
this.$checkAll.html('Uncheck All');
this.$inputs.prop('checked', true);
}
else {
this.areAllChecked = false;
this.$checkAll.html('Check All');
this.$inputs.prop('checked', false);
}
this.updateStatus();
};
CheckboxDropdown.prototype.toggleOpen = function(forceOpen) {
var _this = this;
// The dropdown menu is opened.
if(!this.isOpen || forceOpen) {
this.isOpen = true;
this.$el.addClass('on');
$(document).on('click', function(e) {
if(!$(e.target).closest('[data-control]').length) {
_this.toggleOpen();
}
});
}
else {
// The dropdown menu is closed.
this.isOpen = false;
this.$el.removeClass('on');
$(document).off('click');
}
};
var checkboxesDropdowns = document.querySelectorAll('[data-control="checkbox-dropdown"]');
for(var i = 0, length = checkboxesDropdowns.length; i < length; i++) {
new CheckboxDropdown(checkboxesDropdowns[i]);
}
})(jQuery);
I'm not sure why a "_this" variable is needed, plus I'm not an expert in CSS regarding the use of "&" character such as "&.on" (looks to me like a nested class or something), but at least I can be of help.
Here's the source of the code borrowed from CodePen (some from HTML such as dropdown-list):
https://codepen.io/RobotsPlay/pres/pyNLdL
Update as of 2:15 AM EDT:
As a fallback, for those who turned off JavaScript or is using a NoScript extension in Firefox to browse the web safely, you might want to provide just a simple <select><option>...</option></select> code as provided by Tejas kothari's answer and wrap it in a <noscript>...</noscript> tag.
Example of <noscript> tag:
<noscript>
<label for="categories_noscript">
Categories:
</label>
<p>In Windows/Linux, do Ctrl+click or in macOS, do Cmd+click to select
more than one.</p>
<select name="categories_noscript[]" id="categories_noscript">
<option selected="selected">Choose one or more categories</option>
<?php if(count($categories) > 0) {
foreach($categories as $category) { ?>
<option value="<?=$category['CategoryID'] ?>">
<?=$category['CategoryName'] ?>
</option>
</select>
</noscript>
It's not a drop down combo box as provided in the code above, but at least people can submit a form with JavaScript disabled.
I have this HTML:
<div class="dashboard_wrap">
<div>orders</div>
<div>porting</div>
<div>contact</div>
</div>
that displays 3 divs, here is the CSS:
.dashboard_wrap {
padding:10px;
}
.dashboard_wrap div {
border-left:1px solid black;
padding:10px;
width: 50%;
height:200px;
margin-bottom:50px;
overflow-y:scroll;
float: left;
}
.dashboard_clear:after {
content: "";
display: table;
clear: both;
}
#media all and (max-width: 700px) {
div.wrap div {
width: 100%;
float: none;
}
}
I am using PHP so only certain users can see certain divs. If a user can only see the first 2 divs, how can i make them 50% each rather than 40%?
There is no need to use php or javascript for this. You can use basic html and css for this.
You can check the html fiddle for this: http://jsfiddle.net/4WaX4/1/
All the css which you need is this:
.dashboard_wrap {
display:table;
min-width:500px;
background:#00ff00;
}
.dashboard_items {
display:table-row;
}
.dashboard_items div{
display:table-cell;
border:1px solid #ff0000;
}
#media all and (max-width: 700px) {
div.dashboard_items div {
width: 100%;
display:block;
}
}
And the html looks as follows:
<div class="dashboard_wrap">
<div class="dashboard_items">
<div>orders</div>
<div>porting</div>
</div>
</div>
<div class="dashboard_wrap">
<div class="dashboard_items">
<div>orders</div>
<div>porting</div>
<div>contact</div>
</div>
</div>
Very simpel and quick. When you resize the result window in jsfiddle you see that the divs become 100% relative to the outer div (500px).
I hope this is the solution youre looking for...
You can specify the class of the wrapper based on the number of items inside.
CSS classes for each variant will handle the style automatically.
If however the number of divs can extend beyond expected numbers, then dynamic inline styles may be your solution.
<div class="dashboard_wrap has3">
<div>orders</div>
<div>porting</div>
<div>contact</div>
</div>
<div class="dashboard_wrap has2">
<div>orders</div>
<div>porting</div>
</div>
<style>
.dashboard_wrap div {
border-left:1px solid black;
padding:10px;
height:200px;
margin-bottom:50px;
overflow-y:scroll;
float: left;
}
.dashboard_wrap.has2 div {
width: 50%;
}
.dashboard_wrap.has3 div {
width: 33%;
}
</style>
When the page gets rendered, only two divs will be visible. What you need to do is use a client-based language i.e. javascript or jQuery, to manipulate what is visible on screen.
Use a simple check to see what divs are visible or use php to generate a value which you can hide in the page to make it easier to resize the divs like:
<input type='hidden' id='divs_visible' value='" . $divs_visible ."' />
then using jQuery:
$(document).ready(function() {
var divsvis = $("#divs_visible").val();
if(divsvis == 2)
{
// resize the divs
}
});
EDIT
You can also render all the divs, then using jQuery and the value you've placed in the hidden input, you can simply hide the div you do not need with:
$("#div_to_be_hidden").hide();
I've got a page (documents.php) that contains four tabs, the 1st tab is set as the default and opens when one browses to documents.php
I need to be able to target tabs 2, 3 and 4 directly from hyperlinks on my index.php and a JavaScript menu that appears on all pages on the site.
Example:
Tab 3 on documents.php contains "archived documents".
On Index.php I want to place a link called "Click here to go to Archived documents" and when someone clicks on it it must take them to documents.php but automatically go to Tab 3 which is "archived documents" and not go to the default 1st Tab.
Here is the coding I am using to create the Tabs and would like to only modify this at most (and not re-invent the wheel by using jQuery or other technology and re-write the tabs on this and other pages):
HTML:
<ul>
<li class="current">General Documents</li>
<li>Circulars</li>
<li>Newsletters</li>
<li>Archived Documents</li>
</ul>
Javascript:
<script>
$(document).ready(function(){
$(".tabs li").click(function() {
$(this).parent().parent().find(".tab-content").hide();
var selected_tab = $(this).find("a").attr("href");
$(selected_tab).fadeIn();
$(this).parent().find("li").removeClass('current');
$(this).addClass("current");
return false;
});
});</script>
Then there's some CSS in an external style sheet that formats the Tabs, their borders, background etc.
CSS Formatting:
.tabs ul{
list-style:none;
display:block;
margin:0px;
padding:0px;
z-index:99;
position:relative;
}
.tabs li {
float:left;
display:block;
border-top:#E5E5E5 1px solid;
border-left:#E5E5E5 1px solid;
border-right:#E5E5E5 1px solid;
border-top-left-radius:4px;
border-top-right-radius:4px;
position:relative;
z-index:999;
color: #444444;
padding: 4px 8px 4px 8px;
margin: 0px 6px 0px 0px;
background: #e7e7e7 url(/assets/images/common/bg.png) repeat-x;
}
.tabs li:hover {
/*If you want hover effects on tabs put your css here*/
}
.tabs li a {
display:block;
color:#323234;
outline:none;
}
.tabs li.current {
border-bottom:#DD6E27 2px solid;
outline:none;
}
.tab-content {
display:none;
clear:both;
min-height: 120px;
border-top-left-radius:0px;
border-top-right-radius:4px;
border-bottom-left-radius:4px;
border-bottom-right-radius:4px;
color:#444444;
background:#fefefe url(/assets/images/common/bg.png) repeat-x;
border: 1px solid #E5E5E5;
overflow:hidden;
padding:15px;
}
.tab-content:first-child {
display: block;
}
Pass the # value url like http://example.com#tabs3 .Then use like this in your document ready.
$(document).ready(function(){
var hash = window.location.hash;
$('#'+ hash).addClass("current");
$(".tabs li").click(function() {
$(this).parent().parent().find(".tab-content").hide();
var selected_tab = $(this).find("a").attr("href");
$(selected_tab).fadeIn();
$(this).parent().find("li").removeClass('current');
$(this).addClass("current");
return false;
});
});
I have a link after an image in my xhtml. The browser automatically puts a return character after the image so that the link is below the image. I want the link to be beside the image. How do I modify the CSS/XHTML for this?
PHP generates it like this(example code)
echo "<img class = \"c\" src=\"http:\/\/www.facebook.com\/favicon.ico\" alt=\"\"\/>";
echo "<a name = \"a1\" class = \"b\" href = \"$ass_array[url]\">$ass_array[name]</a>";
CSS
img.c
{
display:??;
}
a.b
{
color:#000088;
padding-top:2px;
padding-bottom:2px;
display:block;
width:100%;
border-bottom:1px solid #cccccc;
}
See: http://jsfiddle.net/thirtydot/vgnAa/
CSS:
.c {
display: block;
float: left;
margin-top: 4px;
margin-right: 4px;
}
.b {
color:#000088;
padding-top:2px;
padding-bottom:2px;
display:block;
border-bottom:1px solid #cccccc;
overflow: hidden;
}
Either float: left, float: right depending which side you want the link to be. Apply that to both, and make sure to have a clear div after.
This way you can still have that display:block on .b.
"float:left;" for both elements will work