Forums » CGI & CSS

USANDO A PROPRIEDADE FLOAT DO CSS

    • 467 posts
    31 de julho de 2013 19:52:37 ART

    USANDO A PROPRIEDADE FLOAT DO CSS

    float é uma propriedade meio imprevisível no CSS. Este é um tutorial explicando passo-a-passo o seu funcionamento com alguns macetes que você não encontrará em nenhum site de referência CSS.

    Começamos fazendo um HTML com 3 Div’s.

     
    <div class="wrapper">
        <div class="nav">Menu</div>
        <div class="main">Conteúdo</div>
    </div>

    html básico com 3 divs
    float é uma propriedade que faz o objeto flutuar à esquerda ou à direita do restante do conteúdo. Se quisermos o menu à esquerda e o conteúdo à direita, o que geralmente fazem é:

     
    .nav{
        float:left;
        width:30%;
    }
    .main{
        float:right;
        width:90%;
    }

    html básico com 3 divs

    Porém, isso vai lhe causar certas dores de cabeça mais para frente no desenvolvimento do site.

    Problemas enfrentados

    Os elementos com float sobrepõem o resto do site.

    Div sobreposta

    Pode notar que a div ‘wrapper’ não está acompanhando a altura das div ‘nav’ e ‘main’. Para fazer com que a div ‘wrapper’ acompanhe a altura do conteúdo dentro dela, simplesmente adicionamos uma nova div com o seguinte CSS:

     
    .clear{
        clear:both;
        display:block;
        overflow:hidden;
        visibility:hidden;
        width:0;
        height:0;
    }

    Clear resolve

    Float:right não alinha com Float:left

    Quem já encontrou este problema sabe o quanto é irritante. Em alguns casos, as colunas não ficam uma do lado da outra NUNCA, por mais que você tente.
    Float:right não alinha com o Float:left
    Para corrigir isso devemos usar o float da maneira correta. Ao invés de colocar ‘float:left;’ no da esquerda e ‘float:right;’ no da direita, colocamos apenas no da esquerda e deixamos o da direita alinhar naturalmente com um espaço de margem.

     
    .nav{
        float:left;
        width:30%;
    }
    .main{
        margin-left:35%;/* um pouco a mais para dar um espaço entre eles*/
    }

    Agora o código completo:

     
    <!--HTML-->
    <div class="wrapper">
        <div class="nav">Menu</div>
        <div class="main">Conteúdo</div>
        <div class="clear"></div>
    </div>
     
    <!--CSS-->
    rel="stylesheet" type="text/css">
    .wrapper{
        display:block;
    }
    .nav{
      float:left;
      width:30%;
    }
    .main{
      margin-left:35%;/* um pouco a mais para dar um espaço entre eles*/
    }
    .clear{
        clear:both;
        display:block;
        overflow:hidden;
        visibility:hidden;
        width:0;
        height:0;
    }
     

    Tudo Funcionando


    Este post foi editado por Oliveira Dario em 31 de julho de 2013 19:53:40 ART"
    • 3223 posts
    3 de dezembro de 2019 04:13:30 ART

    If your looking for Online Illinois license plate sticker renewals then you have need to come to the right place.We offer the fastest Illinois license plate sticker renewals in the state.   The Underdog Advantage

    • 3223 posts
    3 de dezembro de 2019 07:43:01 ART

    Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.   Text Chemistry

    • 3223 posts
    3 de dezembro de 2019 08:08:55 ART

    They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women.  Obsession Method

    • 3223 posts
    3 de dezembro de 2019 08:35:02 ART

    I read a article under the same title some time ago, but this articles quality is much, much better. How you do this..  Free Logo Creator

    • 3223 posts
    4 de dezembro de 2019 06:27:33 ART

    Personally I think overjoyed I discovered the blogs.   Numerologist

    • 3223 posts
    4 de dezembro de 2019 07:08:29 ART

    Thanks for sharing this information. I really like your blog post very much. You have really shared a informative and interesting blog post with people..  Keto Diet

    • 3223 posts
    4 de dezembro de 2019 12:42:47 ART

    They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women.   His Secret Obsession

    • 3223 posts
    7 de dezembro de 2019 11:33:12 ART

    A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.  The Knowledge Business Blueprint

    • 3223 posts
    7 de dezembro de 2019 11:51:43 ART
    The Knowledge Business Blueprint Review This post is good enough to make somebody understand this amazing thing, and I’m sure everyone will appreciate this interesting things.
    Este post foi editado por lifetime lifetime em 7 de dezembro de 2019 11:52:24 ART"
    • 3223 posts
    8 de dezembro de 2019 13:18:48 ART
    I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. Unlock Your Hip Flexors
    • 3223 posts
    10 de dezembro de 2019 03:05:24 ART

    I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more.   Cinderella Solution Review

    • 3223 posts
    10 de dezembro de 2019 10:47:45 ART
    Halki Diabetes Remedy Review I’m happy I located this blog! From time to time, students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. nice one
    Este post foi editado por lifetime lifetime em 10 de dezembro de 2019 10:48:18 ART"
    • 15 posts
    19 de dezembro de 2019 07:35:49 ART

    Great blog,Thanks a lot for sharing The Venus Factor 2.0 Review

    • 15 posts
    19 de dezembro de 2019 18:13:50 ART

    Nice blog and this is a great article, great amount of information in it. Vertigo And Dizziness Program Review

    • 15 posts
    20 de dezembro de 2019 05:35:00 ART

    A good blog I’m happy I located this blog.a lot of information in this post Beetroot

    • 2 posts
    25 de março de 2020 01:32:36 ART

    The content of the forum is really good. It brings a lot of useful information for those who visit this website. geometry dash

    • 8 posts
    31 de março de 2020 14:29:54 ART

    This is the reason it really is greater you could important examination before creating. It will be possible to create better write-up like this.

    My Teen Latina Cam Girls

  • 9 de abril de 2020 04:43:56 ART

    Thanks

  • 9 de abril de 2020 04:44:04 ART

    Thanks

    • 76 posts
    10 de abril de 2020 16:46:33 ART

    Male Extra is considered the most effective natural product for men who want to bigger, harder, stronger the penis and increase blood flow and this supplement is made from a powerful and effective formula that uses 100% natural ingredients, gives optimal results.
    Male Extra


    http://amazon-profit.com/

  • 11 de abril de 2020 03:53:20 ART
    For this web site, you will see our account, remember to go through this info. poker88
  • 11 de abril de 2020 04:38:38 ART
    I wrote about a similar issue, I give you the link to my site. poker88
    • 76 posts
    11 de abril de 2020 14:25:40 ART

    Male Extra is considered the most effective natural product for men who want to bigger, harder, stronger the penis and increase blood flow and this supplement is made from a powerful and effective formula that uses 100% natural ingredients, gives optimal results.
    Male Extra


    http://amazon-profit.com/ href="http://amazon-profit.com/">http://amazon-profit.com/

    • 76 posts
    11 de abril de 2020 14:27:00 ART

    Male Extra is considered the most effective natural product for men who want to bigger, harder, stronger the penis and increase blood flow and this supplement is made from a powerful and effective formula that uses 100% natural ingredients, gives optimal results.
    Male Extra


    http://amazon-profit.com/ href="http://amazon-profit.com/">http://amazon-profit.com/