Visualizzazione dei risultati da 1 a 8 su 8

Discussione: Posizionamento div.

  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    266

    Posizionamento div.

    Salve, ho appena scaricato uno script nella sezione javascript di html.it, "ricreiamo il logo di natale di google". Ho posizionato il div dentro un div header. Su firefox tutto ok, su ie invece il div si posiziona sotto il div header ecco due img per capire meglio il problema:

    FIREFOX:


    Uploaded with ImageShack.us

    EXPLORER:


    Uploaded with ImageShack.us

    Eccovi il codice html:
    codice:
    <div id="header">
    <div id="logo">[img]img/logo.jpg[/img]
    
    <div id="page"></div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script src="js/script.js"></script>
    Codice css:

    codice:
    #page{
    	height:240px;
    	margin: 0 auto;
    	left: 30%;
    	position: relative;
    	float:left;
    }
    
    .pic{
    	position:absolute;
    	overflow:hidden;
    	border:4px solid #f4802b;
    	text-decoration:none;
    	z-index:0;
    }
    
    .pic img{
    	position:absolute;
    	border:none;
    }
    
    .pic:nth-child(2n+1){
    	border-color:#454fa4;
    }
    
    .pic:nth-child(3n+2){
    	border-width:5px;
    }
    Grazie anticipatamente per gli aiuti!

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    266
    nada de nada? ^^

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    21,188
    Non dai informazioni sufficienti per poterti rispondere.
    In particolare non scrivi che DTD usi (vedi "tag" DOCTYPE)
    e non dici in quale/quali versioni di IE hai testato
    Dici di postare lo script, ma non lo posti - e probabilmente comunque non aggiungerebbe informazioni utilizzabili

    La mia sfera di cristallo mi dice che hai una DTD transitional, o comunque di tipo vecchio.
    Prova a passare a XHTML 1.0 Strict.
    E magari hai dei float o dei posizionamenti non innestati correttamente.
    Nuova politica di maggiore severita` sui titoli delle discussioni: (ri)leggete il regolamento
    No domande tecniche in messaggi privati

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    266
    DTD giusto:

    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

    Codice css dello script:
    codice:
    #page{
    	height:240px;
    	margin: 0 auto;
    	left: 30%;
    	position: relative;
    	float:left;
    }
    
    .pic{
    	position:absolute;
    	overflow:hidden;
    	border:4px solid #f4802b;
    	text-decoration:none;
    	z-index:0;
    }
    
    .pic img{
    	position:absolute;
    	border:none;
    }
    
    .pic:nth-child(2n+1){
    	border-color:#454fa4;
    }
    
    .pic:nth-child(3n+2){
    	border-width:5px;
    }
    Codice css del div in cui si trova lo script:
    codice:
    #logot {
    	width:100%;
    }
    #logo {
            margin: 0 auto;
    	height:250px;
    	position: relative;
    }
    script.js
    codice:
    (function($){
    	
    	// Using a self-executing anonymous function,
    	// so that we do not pollute the global space
    	
    	$(document).ready(function(){
    	
    		var page	= $('#page');
    
    		// Creating the expanding images:
    			
    		var picArr = [
    			new pic({
    				top : 70, left : 0, width : 60,height : 100, href:'#',
    				img : { src : 'slide/1.jpg', offsetTop : 50, offsetLeft: 10}
    			}),
    			new pic({
    				top : 30, left : 80, width : 70,height : 115, href:'#',
    				img : { src : 'slide/2.jpg', offsetTop : 30, offsetLeft: 10}
    			}),
    			new pic({
    				top : 130, left : 180, width : 100,height : 50, href:'#',
    				img : { src : 'slide/3.jpg', offsetTop : 50, offsetLeft: 30}
    			}),
    			new pic({
    				top : 80, left : 300, width : 100,height : 62, href:'#',
    				img : { src : 'slide/4.jpg', offsetTop : 43, offsetLeft: 73}
    			}),
    			new pic({
    				top : 50, left : 170, width : 100,height : 62, href:'#',
    				img : { src : 'slide/5.jpg', offsetTop : 43, offsetLeft: 73}
    			}),
    			new pic({
    				top : 50, left : 420, width : 58,height : 90, href:'#',
    				img : { src : 'slide/6.jpg', offsetTop : 13, offsetLeft: 42}
    			})
    		];
    		
    		// Appending the images to the #page div:
    		
    		$.each(picArr,function(){
    			page.append(this.elem);
    		});
    		
    	
    		// Setting up an event listener for the window.load event.
    		// window.load is executed after all the images have been loaded.
    		
    		$(window).load(function(){
    
    			page.mousemove(function(e){
    				
    				var left = (e.pageX - page.offset().left),
    					top = (e.pageY - page.offset().top),
    					pic = null;
    				
    				// On each mouse movement, loop through the pics
    				// and check whether the cursor is above any of them.
    
    				for(var i = 0;i < picArr.length;i++){
    					pic = picArr[i];
    					
    					if(pic.near(left,top)){
    
    						if(pic.over(left,top)){
    							pic.open();
    						}
    						else pic.focus();
    					}
    					else pic.close();
    				}
    				
    			}).mouseleave(function(){
    				
    				// When the mose leaves the #page div,
    				// foce a close on all the images.
    				
    				for(var i = 0;i < picArr.length;i++){
    					picArr[i].close();
    				}
    				
    			});
    		});	
    	});
    
    	// This is the constructor of the pics
    	
    	function pic(options){
    		
    		// All the properties of the options object
    		// are copied to the current pic:
    		
    		$.extend(this,options);
    		
    		// Creating the markup of the pic,
    		// and storing it in the elem property:
    		
    		this.elem = $('<a>',{
    			className: 'pic',
    			href: this.href,
    			css : {
    				top : this.top,
    				left : this.left,
    				width: this.width,
    				height: this.height
    			}
    		});
    
    		var borderWidth = 5;
    
    		// The bottom and right properties are not passed
    		// as arguments, so we need to calculate them.
    				
    		this.bottom = this.top+this.height+2*borderWidth;
    		this.right = this.left+this.width+2*borderWidth;
    		
    		this.image = $('<img>',{
    			css:{
    				left : -this.img.offsetLeft,
    				top : -this.img.offsetTop
    			}
    		});
    		
    		var self = this;
    		
    		// Appending the image to the body so we can get
    		// its dimensions. After we do this, we remove it
    		// and append it to the markup stored in this.elem:
    		
    		this.image.hide().appendTo('body').load(function(){
    			
    			self.img.width = self.image.width();
    			self.img.height = self.image.height();
    			self.elem.append(self.image.show());
    			
    		}).attr('src',this.img.src);
    		
    	}
    	
    	// The prototype holds the class methods,
    	// that are common for all objects.
    	
    	pic.prototype = {
    		open	: function(){
    			if(this.opened){
    				return false;
    			}
    			
    			this.opened = true;
    			
    			// Firing our own expand method with a percentage of 100:
    			this.expand(100);
    		},
    		close	: function(){
    			if(!this.opened && !this.focused){
    				return false;
    			}
    			
    			this.opened = this.focused = false;
    			this.expand(0);
    		},
    		focus	: function(){
    			if(this.focused || this.opened){
    				return false;
    			}
    			
    			this.focused = true;
    			
    			//Expanding to 30%:
    			this.expand(30);
    		},
    		
    		near	: function(x,y){
    			// Checking whether the passed x and y coordinates are near the current image:
    			return (x > this.left-15 && x < this.right+15 && y > this.top-15 && y < this.bottom+15);
    		},
    		
    		over	: function(x,y){
    			// The same, but returning true only when directly above the image:
    			return (x > this.left && x < this.right && y > this.top && y < this.bottom);
    		},
    		
    		expand : function(animPercent){
    			if(!this.animateObj){
    				this.animateObj = {count:0};
    			}
    			
    			// We use jQuery's animate method to
    			// change the count property of the object:
    			
    			$(this.animateObj).stop().animate({
    				count:animPercent
    			},{
    				duration:150,
    				
    				// The step funciton is executed on every animation frame.
    				// With jQuery's proxy we pass the "this" of the function:
    				step:$.proxy(this.stepAnimation,this)
    			});
    		},
    		
    		stepAnimation : function(p,fx){
    			
    			// P holds the current value of the count property,
    			// between 0 and 100. Below we are turning into percentage.
    			
    			p = p/100;
    			
    			// Changing the size and position of the image holder:
    			
    			this.elem.css({
    				width : (this.img.width - this.width)*p + this.width ,
    				height : (this.img.height - this.height)*p + this.height,
    				marginTop : -this.img.offsetTop*p,
    				marginLeft: -this.img.offsetLeft*p,
    				zIndex: 100*p
    			});
    			
    			// Moving the image so it appears as if fixed:
    			
    			this.image.css({
    				marginLeft : p*this.img.offsetLeft,
    				marginTop : p*this.img.offsetTop
    			});
    		}
    	};
    
    })(jQuery);

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    21,188
    La cosa diventa complicata ...

    Vedo infatti che il tuo JS va a modificare il CSS direttamente; devo dire che la cosa non mi piace molto, ma capisco che non la hai fatta tu e probabilmente chi l'ha fatta sapeva il fatto suo.

    Comunque una cosa nel tuo CSS c'e` che non e` riconosciuta da IE (per lo meno IE6 e IE7; non so come sia IE8):
    codice:
    .pic:nth-child(2n+1){
    	border-color:#454fa4;
    }
    
    .pic:nth-child(3n+2){
    	border-width:5px;
    }
    E non so come si possa aggirare il problema, neppure con i commenti condizionali.

    Prova a togliere (commentare) quelle righe e vedi se anche FF si comporta male: se e` cosi` il problema e` sicuramente quello; non e` una gran consolazione, ma almeno sai cosa e`.
    Nuova politica di maggiore severita` sui titoli delle discussioni: (ri)leggete il regolamento
    No domande tecniche in messaggi privati

  6. #6
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    266
    Dimenticavo di dire che se nel div #page invce di position relative metto absolute e imposto i margini il problema si capovolge, su ie tutto ok e su firefox il problema diventa come ie, gioco di parole^^.

    Io non capisco questo però.. se si imposta la posizione assoluta i margini vengono visti dal browser tramite i left top bottom right, infatti su ie funge mentre su ff no why??

  7. #7
    Utente di HTML.it L'avatar di sandrone65
    Registrato dal
    May 2009
    residenza
    Guidonia Montecelio
    Messaggi
    129
    Probabilmente il problema è dovuto come hai disposto i vari DIV, ma il codice che hai postato è un po' confuso, difficile capirci qualcosa.
    Per esempio: nel frammento di HTML apri due DIV ("header" e "logo") e non li chiudi. Il DIV "page" quindi sta dentro di essi o sta fuori/accanto?
    Prova magari ad impostare uno z-index elevato al DIV "page".
    La cosa migliore sarebbe che tu isolassi il codice html relativo al problema e lo postassi tutto intero altrimenti è arduo
    Ciao
    Se non sbagli ora e di nuovo, è segno che non vuoi correre rischi. [W.Allen]

  8. #8
    Utente di HTML.it
    Registrato dal
    Nov 2010
    residenza
    Bologna
    Messaggi
    15
    Se posso darti un consiglio, userei solamente la classe img, quel div logo mi pare superfluo.. Magari il problema di posizionamento e` proprio quello
    Saverio Gentile, web, grafica, fotografia.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.