Responsive image and List items - php

I'm developing a header part of a responsive design. Can anyone tell me how to keep same height in both list items total height and responsive image height, responsive image height will be change according to the resolution, what i need to do is according to that height add more list items or change list items bottom margin and height (both should be increase or decrease and add/remove items to keep a clean look.)
Can anyone help me in this matter to solve? (I'm using HTML5, CSS3, Jquery and PHP if needed)
http://jsfiddle.net/ST7xy (This is a demo)
<div class="navigation">
<ul class="list">
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
</ul>
</div>
<div class="image">
<img src="http://placehold.it/500x200" width="100%">
</div>

I would recommend floating it all inside a div, with an adjustable height depending on resolution then using percentages on your heights, so making the main image 100% and the list's (4 in your example) 25% each.
JSfiddle
css:
.container {
height: 200px;
}
.navigation{
float: left;
width: 200px;
height: 100%;
}
.list{
padding: 0;
margin: 0;
height: 100%;
}
.list li{
margin:0;
padding:0;
margin-right: 5px;
margin-bottom: 2%;
height: 23.5%;
}
.list li:last-child{
margin-right: 5px;
margin-bottom: 0;
height: 23.5%;
}
.list li a{
display: block;
background: grey;
line-height: 100%;
height: 100%;
}
.image{
float: left;
}

You cannot get this to work with css alone. You need to use jquery.
Use
var navHeight = $(".navigation").height();
to get the height of the navigation div. And on any change you need to assign that height to div image like :
$(".image").height(navHeight);
So basically :
$(window).resize(function(){
var navHeight = $(".navigation").height();
$(".image").height(navHeight);
});
$(window).resize(); //on page load
Jus giving an insight and you can build on from here..:)

This is what you want and what you need
Working Solution
Jquery
$(document).ready(function () {
var leftHeight = $('.image').height() - 5;
$('.navigation').css({
'height': leftHeight
});
var rightHeight = $('.navigation').height();
});
CSS
.navigation {
float: left;
width: 200px;
}
.list {
padding: 0;
margin: 0;
background-color:#000;
height:inherit;
}
.list li {
padding:0;
height:25%;
margin-right: 5px;
}
.list li a {
display: block;
background: gray;
height:90%;
}
.image {
padding: 0;
margin: 0;
float: left;
}
As you can see the query is simple ad straight forward. I assign the height of the image div to the navigation div.
In the CSS i have used percentages to match the parent ul. So incase you using 4/6/8 list item's you will have to change this percentage accordingly.
Enjoy!

Related

Circular-like dynamic menu - CSS3

I'm using LESS. I designed my <li>s, with every proceedings, taking a different id with a PHP loop. And in CSS I've written a code like:
li.page-2{
margin-left: 15px;
}
li.page-3{
margin-left: 25px;
}
li.page-4{
margin-left: 22px;
}
li.page-5{
margin-left: 18px;
}
...
I've two questions regarding this, so, first of all, I want to share my intention:
I want to design a dynamic circular menu like this.
Q#1: How can I minimize the CSS coding dynamically, as I'm actually first, increasing the value, and after some places, decreasing the value of margin-left.
Q#2: Is there any other way I can do such circular dynamic menu?
You can anyways minify this using LESS or SASS, as far as traditional CSS goes, than use CSS Positioning techniques to achieve so..
Demo
Explanation : Here, am using position: relative; container, further nesting absolute span elements which I later position using top and left properties.
If you are creating dynamic menus, than you need to nudge the nth elements using LESS as and when the menu items increase.
HTML
<div>
<span>Page 1</span>
<span>Page 2</span>
<span>Page 3</span>
<span>Page 4</span>
<span>Page 5</span>
</div>
CSS
div {
height: 150px;
width: 150px;
margin: 100px;
border: 2px solid #000;
border-radius: 50%;
position: relative;
}
div span {
font-family: Arial;
font-size: 12px;
position: absolute;
width: 100px;
}
div span:nth-of-type(1) {
left: 135px;
}
div span:nth-of-type(2) {
left: 155px;
top: 30px;
}
div span:nth-of-type(3) {
left: 160px;
top: 60px;
}
div span:nth-of-type(4) {
left: 155px;
top: 90px;
}
div span:nth-of-type(5) {
left: 145px;
top: 120px;
}
The best way is to use some simple JavaScript as described here:
Animated radial menu with CSS3 and JavaScript
var items = document.querySelectorAll('.circle a');
for(var i = 0, l = items.length; i < l; i++) {
items[i].style.left = (50 - 35*Math.cos(-0.5 * Math.PI - 2*(1/l)*i*Math.PI)).toFixed(4) + "%";
items[i].style.top = (50 + 35*Math.sin(-0.5 * Math.PI - 2*(1/l)*i*Math.PI)).toFixed(4) + "%";
}
document.querySelector('.menu-button').onclick = function(e) {
e.preventDefault(); document.querySelector('.circle').classList.toggle('open');
}
You can use CSS3 to animate the menu, still (this is better, performance-wise). You could add any number of elements and the JS will position them dynamically
Creating redundant css styles for dynamic code is not a good practice. I suggest you to look into the javascript way. If anyone wants the JS way look into this approach. I have written the code in Jquery.
HTML
<ul id='circularMenu'>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
<li>Page 4</li>
<li>Page 5</li>
<li>Page 6</li>
</ul>
Javascript
var childCount = $('#circularMenu li').length();
var diff = 10; // The difference in margin for each item
var marginLeft = 0;
var currentChild = 1;
$('#circularMenu li').each(function(){
//Skip condition, as we style this element within center elements section
if(childCount%2 && currentChild == Math.ceil(childCount/2)) coutinue;
//Top half of the menu where margin is increased
if(currentChild < childCount/2) {
marginLeft += diff;
this.css('margin-left', marginLeft+'px');
}
//Bottom half of the menu where margin is decreased
else if(currentChild > childCount/2) {
marginLeft -= diff;
this.css('margin-left', marginLeft+'px');
}
//The center element, this is tricky as there can be one or two center elements
else if(currentChild == Math.floor(childCount/2)) {
marginLeft += diff;
this.css('margin-left', marginLeft+'px');
if(childCount%2){
this.next().css('margin-left', marginLeft+'px');
}
}
});
This is untested code, there might be some errors. Please comment for any issues. The above code can be minified a lot, i just elaborated so you can understand the concept.

Centering my css3 menu of changing widths...?

I have a css menu which has a width of 400 for non-Admins... and a width of 500 for Admins. If I set the UL width to 500, the menu centers fine and nicely for Admins. But for non-admins, whose mneu is really only 400 wide... it's off-kilter.
So I removed the width attribute from the UL to try and remove this and then it lost centering altogether; the whole menu is now stuck to the left side of the container.
Anyone have a simple idea for how to make it always centered? Site is here:
http://www.runic-paradise.com/
ul.menu{
height: 40px;
list-style: none outside none;
margin: 0 auto;
/*width: 500px;*/
}
/*li{
width:100px;
height:50px;
float:left;
color:#191919;
text-align:center;
overflow:hidden;
}*/
a.menu{
color:#FFF;
text-decoration:none;
}
p.menu{
padding-top: 10px;
padding-right: 5px;
padding-left: 5px;
}
.subtext{
padding-top: 10px;
}
ul.menu li{
width: 100px;
height: 40px;
float: left;
color: #191919;
text-align: center;
overflow: hidden;
}
/*Menu Color Classes*/
.green{
background:#6AA63B url('/img/menu/green-item-bg.jpg') top left no-repeat;
}
.yellow{
background:#FBC700 url('/img/menu/yellow-item-bg.jpg') top left no-repeat;
}
.red{
background:#D52100 url('/img/menu/red-item-bg.jpg') top left no-repeat;
}
.purple{
background:#5122B4 url('/img/menu/purple-item-bg.jpg') top left no-repeat;
}
.blue{
background:#0292C0 url('/img/menu/blue-item-bg.jpg') top left no-repeat;
}
<ul class="menu">
<li class="green">
<p class="menu">Home</p>
<p class="subtext">The front page</p>
</li>
<li class="yellow">
<p class="menu">-</p>
<p class="subtext">More info</p>
</li>
<li class="red">
<p class="menu">Forums</p>
<p class="subtext">Get in touch</p>
</li>
<li class="blue">
<p class="menu">-</p>
<p class="subtext">Send us your stuff!</p>
</li>
<?php
if ($user->data['group_id'] == 5)
{
echo ' <li class="purple">
<p class="menu">Admin</p><p class="subtext">Legal things</p>
</li>';
}
?>
</ul>
Your CSS sets the ul.menu width to 400px. If the user is admin, the php script adds another 100px wide li to ul.menu. When this happens, you have to set the ul.menu width to 500px. If you do this, the css rule margin:0px auto; will handle the centering as expected.
A simple jQuery fix would be something like this:
<script>
$(document).ready(function() {
var menu=$('ul.menu');
if(menu.find('li')>4) {
//if there are more then 4 menu items, reset menu width to 500px
menu.css('width','500px');
}
});
</script>
Use max-width:500px;for UL.Demo for these http://jsfiddle.net/dhanith/ZMB93/
Can you please try this,
In animated-menu.css (demo url: http://www.runic-paradise.com/), Change margin style as like below
ul.menu {
height: 40px;
list-style: none outside none;
margin: auto 25%;
}

How to position a picture flyout

So i have this problem. I want to center my flyout but here is the catch. I do not know what the size of the picture will be since it is a picture uploaded by a user. I also don't what the picture disappearing if i make the screen smaller. I tried to set position to be relative but then it pushes my images / texts behind the flyout down.
<div id="imageFlyout<?=$step['order']+1?>" class="popUpWrapper" style="display:none;position:absolute;top:100px;left:<script type="text/JavaScript">
int w = screen.width;
<?php $tempSize=getimagesize("guidebook_images/".$step['attachment']); if($tempSize[0] > 935){?>w/2<?php }else{?>w-<?php echo($tempSize[0]/2);}?></script>px;">
Centering in HTML is an easy two step process:
Give the parent:
text-align:center;
Give the element:
margin:auto;
Demo: http://jsfiddle.net/uriahjamesgd_73/kNFGj/22/
I used the CSS values VW (viewer width) & VH (viewer height) to specify that the flyout be a percentage of whatever the viewport is at a given instance. Hopefully this allows resizing of the viewport in mobile devices.
<!-- HTML -->
<div class="wrap">
<div class="product">
<span class="flyOut"></span>
</div>
</div>​
/* CSS */
body { margin: 50px; }
.wrap { position: relative; }
.product { background-color: #555; position: relative; width: 100px; height: 75px; }
span.flyOut { display: none; background-color: #ddd; position: absolute; width: 50vw; height: 37.5vh; left: 100%; }
.product:hover > span.flyOut { display: inline-block; }
​

Image rollover-zoom near mouse

I have an advent/christmas calendar. Everyday is another picture with one more door opened. To make these regions clickable I used CSS and IDs like this:
CSS:
ul#doorregions {
list-style: none;
background: url(<?php echo($pictureoftheday); ?>) no-repeat 0 0;
position: relative;
width: 950px;
height: 575px;
margin: 0;
padding: 0;
}
ul#doorregionsli {
border: 0px ;
position: absolute;
}
#door1 {
left: 135px;
top: 192px;
width: 73px;
height: 116px;
}
#door2 {
left: 135px;
top: 192px;
width: 73px;
height: 116px;
}
HTML:
<ul id="doorregions">
<li id="door1">
<span><a href="<?php echo($december1); ?>">
<img src="blankpixel.gif" width="100%" height="100%">
</a></span></li>
<li id="door2">
<span><a href="<?php echo($december2); ?>">
<img src="blankpixel.gif" width="100%" height="100%">
</a></span></li>
</ul>
So far all works fine. Now an image should, on rollover, show a door near the mouse cursor while it is over the region. I tried something like:
#door1 a:hover {
display:block;
background-image: url(OTHERPICTURE1.jpg);
}
But this method doesn't work if the other picture is bigger than the door region. Any other idea? I can't slice the background image, that is not an option.
It's not necessary to follow the mouse in the region, the position can be fixed. But this second image should only apear while the mouse is over the door (or maybe on the second picture).
The BEST solution would be something like this: http://www.sohtanaka.com/web-design/fancy-thumbnail-hover-effect-w-jquery/
But in this case it is the same picuture which zooms in. I have only blank gifs. What will be the smartest idea?
If you are willing to use jQuery, you could create a hidden div for each "door". Then, bind a hover event to the a tag and set the visibility of the div to true. Like such:
$("li #door1 a").hover(function () {
$("div #door1image", this).fadeIn("fast");
}, function () {
$("div #door1image", this).fadeOut("fast");
});
The "door1image" is id of the div that would be hidden from the start (display:none). It could be placed inside the li with the a tag for each door.
Code is not tested and may not be perfect, but hopefully you get the idea.
What about setting the door divs to position: relative then do an absolutely positioned div with negative bottom and rightplacement example:
#door1 {
Position: relative;
}
#door1 .door {
Position: absolute;
Bottom: -25;
Right:-25;
Display:none;
}
Then use javascript to change the display property back to normal.
Hope this helps.
I haven't been able to get fades or animation to work like I want it to, but here is how I would make the popup images. Note: that instead of using a blank image, the image should be the image you want to display on hovering.
CSS
ul#doorregions {
list-style: none;
background: url(<?php echo($pictureoftheday); ?>) no-repeat 0 0;
position: relative;
width: 950px;
height: 575px;
margin: 0;
padding: 0;
}
ul#doorregions li {
border: 0px ;
position: absolute;
}
#door1 {
left: 135px;
top: 192px;
}
#door2 {
left: 225px;
top: 192px;
}
.doors {
background: #444;
width: 73px;
height: 116px;
}
.popup {
position: absolute;
top: 0;
left: -99999px;
border: 0px;
z-index: 9;
}
HTML
<ul id="doorregions">
<li id="door1" class="doors">
<span><a href="<?php echo($december1); ?>">
<img class="popup" src="<?php echo($december1Image); ?>">
</a></span>
</li>
<li id="door2" class="doors">
<span><a href="<?php echo($december2); ?>">
<img class="popup" src="<?php echo($december2Image); ?>">
</a></span>
</li>
</ul>
Script
// using window.load to ensure all images are loaded
$(window).load(function(){
$('.doors').each(function(){
var popup = $(this).find('.popup');
// find middle of door
var doorY = $(this).height()/2;
var doorX = $(this).width()/2;
// position middle of popup to middle of door
var popY = doorY - popup.height()/2;
var popX = doorX - popup.width()/2;
popup
.hide()
.css({top: popY, left: popX });
$(this).hover(function(){
popup.show();
},function(){
popup.hide();
})
})
})
I'm not entirely sure of what you're needing, but the following code duplicates the functionality of the "Fancy Thumbnail" link you provided. Hopefully it will help!
<!DOCTYPE html>
<style>
ul {
list-style: none;
margin: 50px;
padding: 0;
}
li {
width: 300px;
height: 300px;
float: left;
border: 3px outset gray;
background: white;
}
li:hover {
margin: -50px;
width: 400px;
height: 400px;
z-index: 2;
position: relative;
}
</style>
<ul>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
</ul>

Tree Menu Won't Scroll

I have a nested list that lists child nodes when the parent node is expanded. The parent node is expanded by clicking an image to the left of the text.
Unfortunately, it expands right off the page. I would like a scrollbar to appear when the content is off the page.
When I set "overflow: auto", a scrollbar never pops up, it just expands off the page and removes the expansion image on left of the list items.
Here's sample .html:
<body>
<div id="theDiv" style="clear: left;">
<ul id="theList">
<li id="1" class="parent">
<img class="expanded" align="absmiddle" src="./tree_expanded.gif"/>
Parent1
<ul style="display: block;">
<li id="10">
.....
</ul>
</li>
....
</ul>
</div>
</body>
Here's sample .js:
function expand() {
if(this.className == "expand") {
jQuery(this.parentNode).children("ul").show();
this.className = "expanded";
this.src = "/_images/tree_expanded.gif";
}
else {
jQuery("ul", this.parentNode).hide();
this.className = "expand";
this.src = "/_images/tree_unexpanded.gif";
}
}
Here's sample .css:
#theList {
margin-top: 0;
}
#theList, #theList ul {
list-style: none;
margin: 5px 20px;
padding: 0;
}
#theList .expand, #theList .expanded {
margin-left: -20px;
cursor: pointer;
}
#theList img {
margin-right: 5px;
}
#theList ul {
display: none;
}
#theList li {
white-space: nowrap;
margin-bottom: 4px;
}
First of all, set a definite width of the container div, so it knows when to start scrolling. Next, set it to overflow-x:scroll; or something to that effect. It should work :)
Ok, I was on the right track but not persistent enough. CSS really drives me nuts. I need to set both the div and the list height to get it to scroll. I was trying one or the other, not both.
I'm such a n00b.

Categories