• Resolved johannes999

    (@johannes999)


    Hallo,

    yesterday I asked question about the gap between 2 classes. I understand now that I had too many containers and it was very complicated.

    so I started from scratch to create header with flex to see where the problem lies.

    I am using 2 containers of flex in the first-header class.

    this is HTML:

    
    
    <body <?php body_class(); ?>>
    <?php wp_body_open(); ?>
    <div id="page" class="site">
    	
    	<a class="skip-link screen-reader-text" href="#primary"><?php esc_html_e( 'Skip to content', 'auto-repair-service' ); ?></a>
    
    	<header id="masthead" class="site-header"> 
    		
    		<div id="first-header" class="flex-container">
    			
    	
    			
    		<div class="info"> Hello 	</div>	
                    
    	<div class="first-header-second-section">
    		
    			
    		
    	<div class="title">Hello Hello
    
    			</div> 
    			
    			
    		
    			
    			
    			<div class="info2">Klanten Beoordeling 9.2/10</div>
    		<div class="info3">Vooraf prijs opgave</div>
    			
    		</div>  
    		
    		
    		
    		
    		</div>
    		
    		
    		</header>
    		
    	
    	
    
    

    this is CSS:

    #first-header{
    		width:100%;
        	height:65px;
    		background:#45accb;	
    		border:0.01px solid #45accb;	  
    		z-index:9999;
    		display:flex;
    		flex-direction:column;
            position:fixed;
    	}
    	
    	.info {
    	   width:96%;
    		margin-right:4%;
    		display:flex;
    		justify-content:flex-end;
    		color:white;
    		font-size:1.2rem;
    
    		
    	}
    	
    	.first-header-second-section {
    		width:100%;
    		display:flex;
    		flex-direction:row;
    		
    	}
    	
    	.title{
    	width:33.333%;
    	font-size:1.2rem;
    	color:#ffd978; 
        display:flex;
    	justify-content:flex-start;
        margin-left:4%;
      
    
    
    }
    
    	
    	
    	.info2{
    	width:33.333%;
    	font-size:1.2rem;
    	color:#ffd978; 
    	display:flex;
    	justify-content:center;
    	align-items:center;
        
    
    
    }
    
    .info3{
    	width:33.333%;
    	font-size:1.2rem;
    	color:#ffd978; 
      	display:flex;
    	justify-content:flex-end;
    	align-items:center;
    	margin-right:4%;
    
    	
    }

    everything is ok untill I add position:fixed in the first-header (class)

    when I add this (position:fixed) code the first-header goes few rem down from its normaal position. when I remove it the first-header goes back to its normaal position.

    I see this problem is coming from the 2 flex containers I am using in the first-header.

    my aim is to have 2 rows (in flex)in the header.

    how I can solve this problem?

    thanks

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You’ve commented out class flex-header and everything within on your linked page. Anyone wishing to help you would need live content to fiddle with to better see what you’re referring to and to experiment with using element inspector to ensure any suggestions are valid. Hard to do when everything exists as HTML comments ??

    Yes, one could copy everything into their own test page, but that takes greater effort. The greater the effort, the less likely someone is inclined to help. It’s in your best interest to make this as easy as possible for other members. Additionally, any CSS file and line references on ones own page would be meaningless to you.

    Thread Starter johannes999

    (@johannes999)

    thanks,

    I have put back . I wil wait few hours.

    Thread Starter johannes999

    (@johannes999)

    sorry,

    I am going to change the code.

    it seems this problem is complicated.

    I used inspect element but I couldn’t see any clear sign.

    I let know when I solve this problem in onother way .

    I have to solve this problem.

    thanks

    Thread Starter johannes999

    (@johannes999)

    after trying to solve the problem I tought suddenly I wil try javascript to fix the header and try to solve the problem in this way .

    I know very little about javascript at this moment so I tried ( AI ) I wil not give name only to let you know that I am not javascript expert.

    otherwijs I wil not ask question here!

    at this moment it is solved the problem when I scroll down the header is fixed incl. using flex.

    this is the html at this moment as an example:

    <header>
    	
    	<div class="container">				
    		<div class="row">		
    		
    		<div class="col"></div>
    		<div class="col"></div>
    		<div class="col"></div>
    		</div>
    		
    	</div>
    	</header>

    this is the CSS code:

    * {
    			box-sizing: border-box;
    			margin: 0;
    			padding: 0;
    		}
    		.container {
    			display: flex;
    			flex-wrap: wrap;
    			max-width: 100%;
    			height: 70px;
    			background-color: red;
    			position: fixed;
    			top: 0;
    			left: 0;
    		}
    		.col {
    			flex: 1;
    			height: 100%;
    			
    			
    		}

    and this is Jquery code:

    <script>
    	
    $(document).ready(function() {
        var containerTop = $('.container').offset().top;
        $(window).scroll(function() {
            var scroll = $(window).scrollTop();
            if (scroll >= containerTop) {
                $('.container').css({
                    position: 'fixed',
                    top: 0,
                    left: 0
                });
            } else {
                $('.container').css({
                    position: 'static'
                });
            }
        });
    });
    
    
    
    
    </script>

    you have to use jquery cdn or enqueue the jquery in function.php like this:

    function your_theme_name__scripts() {
      wp_enqueue_script('jquery');
    }
    add_action('wp_enqueue_scripts', 'your_theme_name__scripts');
    

    the problem is solved with fixing the header container class with jquery

    and I can use now flex also .

    I writed because if somebody has such a problem the only way is sometimes to use javascript to solve otherwijz I have no interest in anything.

    you help me I write it back if I found solution.

    I have been busy for few days whitout results untill I thought to try javascript.

    maybe the browser is confusing with flex and position: fixed

    you can see it on my homepage: https://webdesignleren.com/

    thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘when I add position fixed the header goes down from its normal position ?’ is closed to new replies.