Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good to use classes like .left {float:left} and .right {float:right}

Tags:

html

css

xhtml

  • Which method is more manageable specially in team development?
  • Which will be more optimized in longer?
  • What are pros and cons of both?

Stylesheet

#firstblock { background: #000; float: left; }
.genblock { background: #006699; float: left; }

HTML

<div id="firstblock"></div>
<div class="genblock"></div>
How you should do it

Or

Stylesheet

.left { float: left; }

#firstblock { background: #000; }
.genblock { background: #006699; }

HTML

<div id="firstblock" class="left"></div>
<div class="genblock left"></div>
like image 413
Jitendra Vyas Avatar asked May 12 '11 01:05

Jitendra Vyas


People also ask

Which of the following float left or float right is mandatory?

The element must float on the right side of its containing block. The element must not float. The element must float on the start side of its containing block. That is the left side with ltr scripts, and the right side with rtl scripts.

What is float left and float right?

left : floats the element to the left of its container. right : floats the element to the right of its container.

Why float right does not work?

Here is one way of doing it. The trick is to apply overflow: auto to the div , which starts a new block formatting context. The result is that the floated button is enclosed within the block area defined by the div tag. You can then add margins to the button if needed to adjust your styling.

What property and value are used to remove the effects of using float left and right?

The clear property can be specified with any of the following values: none (default): Floating elements are allowed on both sides of the cleared element. left: No floating elements are allowed on the left side of the cleared element. right: No floating elements are allowed on the right side of the cleared element.


1 Answers

You should not leak presentational information (CSS) to your data layer (HTML).

You should give your elements a class name that describes their purpose. Whether it floats or not is irrelevant in the HTML. You decide that in the CSS.

What if you had a class name such as blue and then your clients say we now want all those things red?

Example

HTML

<ul id="primary-menu">
....
</ul>

CSS

#primary-menu {
   float: left;
   color: #f00;
}
like image 134
alex Avatar answered Nov 15 '22 08:11

alex