Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome loading forces float:right to new line

I'm having a loading issue in chrome only where certain times it loads it all at once and the float looks fine in the menu, but other times it loads it slower than usual and it causes the float to break to a new line. I notice it usually only happens on hard refreshes (F5) but it does sometimes occur when just clicking around.

It is not a problem in IE, Firefox, or Safari. Anyone have any edits to my code to fix this problem?

Here is my code:

HTML:

$text .=    '<div class="block-menu ">';
$text .=        '<a class="block-menu-item logo gray" href="/"></a>';
$text .=        '<a class="block-menu-item">Button 1</a>';
$text .=        '<a class="block-menu-item">Button 2</a>';
$text .=        '<a class="block-menu-item">Button 3</a>';

//Floats right
$text .=        '<div id="block-menu-bar-button">';
$text .=            '<a class="block-menu-item">Button 4</a>';
$text .=            '<a class="block-menu-item">Button 5</a>';
$text .=            '<div style="clear:both;"></div>';
$text .=        '</div>';
$text .=    '</div>';

CSS:

#block-menu-bar-button{
     float:right; 
     display:inline-block; 
     overflow:hidden;
}
.block-menu{
     position:relative; 
     width:70%; 
     text-align:left; 
     margin:auto; 
     padding:15px 0;
}
a.block-menu-item, div.block-menu-item{
     display:inline-block; 
     margin:0 20px; 
     padding:2px 0;
     border-bottom: 2px solid transparent;
     cursor:pointer;
}

I'm interested in alternatives to float:right as well (not a fan of floats). I've toyed with the idea of using table-cell, but I've gotten the assumption this is bad practice. Also I've toyed with the idea of flex-boxes but they are not supported in ie8 or 9 and my site accommodates those browsers.

like image 763
Dom Avatar asked Mar 10 '14 13:03

Dom


People also ask

How do I make a div float right?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

What does float left do?

The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to absolute positioning).

Is float still used in CSS?

Is CSS float deprecated? In a word: no. The float property still exists in CSS as it did when Internet Explorer was a young browser, and still works the same.

How do you float an element in CSS?

How do you float other HTML elements in CSS? As mentioned earlier, any HTML element can be floated in CSS, not just images. Let's say you want a button to float to the left of the text in a container. You can use a class selector to target the button class and define it with the rule float: left or float: right.


1 Answers

In your HTML, the floated item should be first rather than second. I don't have a great explanation why... I've just noticed in Chrome that sometimes the page renders before floats are applied, and if the element is after the rest of the content, the float never applies correctly.

like image 162
kthornbloom Avatar answered Sep 22 '22 14:09

kthornbloom