Search code examples
csspositionfixed

CSS fixed position on X axis but absolute on Y axis?


My container, #topmenu is in fixed position. I just added a phone number (image) that I want to move with this bar, but it doesn't move with the fixed bar.

I've absolutely positioned it within a relatively positioned element, but it just doesn't stick.

If I just make the phone number position:fixed then it moves around with the viewport width. What's the best way to accomplish what I'm doing?

CSS fragment:

.topsocial a { margin-left: 15px;  }
#topmenu {position:fixed; z-index:220; }
#topmenu .ktwrap {padding-top: 3px; padding-bottom: 3px; color: #fff;}
#topmenu ul li { display:inline; list-style-type: none; padding: 0px 10px 0 0; font-size: 13px; }
#topmenu .widget-container { margin-top: 5px;}
.topsocial .widget-containter {margin-top: 0px!important;}

#menu-menu li a span {
    display:block;
    line-height:14px;
    margin-right: 4px;
    text-transform: lowercase!important;
}       

.menu-menu ul li a span {
    line-height:14px;
    margin-right: 4px;
    text-transform: lowercase!important;
}

.topsocial {margin-top: 5px; color: #fff;}

.ktlogo {float: left; width: auto; margin-top:-35px; margin-left: 137px; font-family: 'HoneyScriptLight'; font-size: 60px; padding-top: 22px; }

.ktlogo img:hover {background: none;}

#navigationtop { font-size: 12px; color: #fff;}
#navigationtop ul li strong { display: block; padding-bottom: 7px; font-size: 14px; }
#navigationtop .ktwrap { padding-top: 60px; padding-bottom: 5px; height:71px; }
#floatnumber {
    position: absolute;
    top: -3px;
    right: 150px;
    z-index : 270;  
}

PHP fragment:

<?php get_template_part( 'includes/template-parts/topbar' ); ?>

<?php } ?>

<?php 
$disable_sidebar = of_get_option('disable_footer', '' );
if( $disable_sidebar['navbar']==0 ) { ?>

<div class="ktfullwidth" id="navigationtop"> 
    <div class="ktwrap"> <div id="floatnumber"><img src="http://combined-effort.com/wp-content/uploads/telephone-18005174660.png" alt="Phone Number 1-800-517-4660"></div>
        <div class="ktlogo">
            <?php 
            $disable_sidebar = of_get_option('disable_parts', '' );
            if( $disable_sidebar['logo']==0 ) { ?>

                <?php if ( of_get_option('logo') ) { ?>

                        <a href="<?php echo home_url() ?>"><img src="<?php echo of_get_option('logo'); ?>" /></a>

                        <?php } else { ?>

                        <a href="<?php echo home_url() ?>">

                        <?php if ( of_get_option('logotext') ) { ?>
                            <?php echo of_get_option('logotext', ''); ?></a>
                        <?php } else { ?>
                        Combined Effort</a>
                        <?php } ?>

                <?php } ?>

            <?php } ?>

        </div>

Solution

  • You can change

    <ul id="menu-main" class="sf-menu sf-js-enabled sf-shadow">...</ul>
    <div class="topsocial right">...</div>
    

    into

    <ul id="menu-main" class="sf-menu sf-js-enabled sf-shadow">...</ul>
    <div class="right">
      <img src="http://combined-effort.com/wp-content/uploads/telephone-18005174660.png" alt="Phone Number 1-800-517-4660">
      <div class="topsocial right">...</div>
    </div>
    

    And then delete the othe image.