Jump to content

float: left; or .float-left


brown2005

Recommended Posts

Ahh, I see what you are asking. I thought you were asking about the difference between:

 

<div style="float:left;">

 

and

 

<div class="float_left;">

 

As for your question, well it really depends on the site, and how you are doing it. But I almost always find myself using the first method you mentioned, rather than explicitly declaring a class for floats. Usually a particular class will need a float, or a specific element with an ID, so I find that way easier to deal with.

 

But neither way is right or wrong.

Link to comment
Share on other sites

  • 2 weeks later...

In addition, it's encouraged and sensible not to use "presentational" class or id values. Imagine having:

 

<h2 class="float-left"></h2>
<div class="wide no-margin">
   <p class="highlight-yellow">Lorem ipsum dolor</p>
</div>

 

What happens if the paragraph needs to be restyled to be red? Or if the div no longer needs to be "wide" and needs to have margins. Or if we don't want the heading to be floated left?

 

You might be able to restyle them without affecting other elements in different parts of the site that use the same class names...but usually it is much more difficult to do so because of the concept of using presentational class names. This links the css with the html much more closely, making it harder to use css changes alone to affect the appearance of the document. Instead there is often a need to go into the html to change class names. You can't have the css declarations for "no-margins" to contain margins, or for "wide" to end up being narrower than the default appearance, etc.

 

But if you name based on semantics derived from the document (i.e. not with a though about how to visually present it) then you avoid both these problems. If my target has a class of "entry" or "section" then I can style it any way I want without ever having to go into the html or have confusing class names.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.