How to make an Irregular shape divs with CSS

by merkv
20 replies
  • WEB DESIGN
  • |
Hi,

I am currently studying on my own creating wordpress theme. I'm still a beginner. I just want to ask is there any way that we can create an irregular shape divs? for example i want a T-shape div,can this be done?
#css #divs #irregular #make #shape
  • Profile picture of the author Seiryuu
    For a T-shaped div you'd need to use 2 separate divs. One div for the vertical part and another div for the part going horizontally across the top. You may also need to contain these within a further div.. hope that makes sense!

    Alternatively, you could have a large square, with a small square on the bottom left and bottom right which you could have the text/content avoiding - thus giving a "T" illusion.

    Out of interest what do you want to make an irregular shape for? Most problems can be solved with simpler methods!
    {{ DiscussionBoard.errors[8146167].message }}
    • Profile picture of the author merkv
      Originally Posted by Seiryuu View Post

      For a T-shaped div you'd need to use 2 separate divs. One div for the vertical part and another div for the part going horizontally across the top. You may also need to contain these within a further div.. hope that makes sense!

      Alternatively, you could have a large square, with a small square on the bottom left and bottom right which you could have the text/content avoiding - thus giving a "T" illusion.

      Out of interest what do you want to make an irregular shape for? Most problems can be solved with simpler methods!
      Thanks for the advise, there's nothing particular with "T" shape, i just thought of it as a complicated figure, since all div shapes are just rectangle, square, rounded corners, triangles or circles.
      .
      The Irregular shape i want to use it for is for icons,
      for example a T icon(sorry i used this figure again..)yes it can be done by combining 2 divs, but can it be hovered as one element? without enclosing it in a container.

      This may sound weird, but what i watn to achieve is to create an irregular shape div which is consider as one element , without combining 2 or more divs together.

      Sorry i'm still a beginner and trying to make my own webpage thru local host at my PC, I'm just trying to learn more complicated methods rather than the basics.
      {{ DiscussionBoard.errors[8146244].message }}
      • Profile picture of the author Brandon Tanner
        Originally Posted by merkv View Post

        The Irregular shape i want to use it for is for icons,
        for example a T icon(sorry i used this figure again..)yes it can be done by combining 2 divs, but can it be hovered as one element? without enclosing it in a container.

        This may sound weird, but what i watn to achieve is to create an irregular shape div which is consider as one element , without combining 2 or more divs together.
        The way you would do that is to give all of your div's that make up the "T" the same class, like...

        HTML Code:
        <div class="Tclass" id="topT"></div>
        <div class="Tclass" id="bottomT"></div>
        Then you can manipulate everything in the "Tclass" as if it's a single item, via Javascript. For example, if you want to change the background color of all div's in the Tclass to red when they are hovered over, this is how you would do it in jQuery...

        HTML Code:
        $(".Tclass").hover(function(){
            $(".Tclass").css("background-color","red");
        });
        Signature

        {{ DiscussionBoard.errors[8146330].message }}
        • Profile picture of the author merkv
          Originally Posted by Brandon Tanner View Post

          The way you would do that is to give all of your div's that make up the "T" the same class, like...

          HTML Code:
          <div class="Tclass" id="topT"></div>
          <div class="Tclass" id="bottomT"></div>
          Then you can manipulate everything in the "Tclass" as if it's a single item, via Javascript. For example, if you want to change the background color of all div's in the Tclass to red when they are hovered over, this is how you would do it in jQuery...

          HTML Code:
          $(".Tclass").hover(function(){
              $(".Tclass").css("background-color","red");
          });

          Thanks this is what i need, by the way .. this is a non css question,i'm still new to jquery... how do i call that function?

          thanks again...
          {{ DiscussionBoard.errors[8146520].message }}
          • Profile picture of the author Brandon Tanner
            Originally Posted by merkv View Post

            Thanks this is what i need, by the way .. this is a non css question,i'm still new to jquery... how do i call that function?

            thanks again...
            That function is automatically executed whenever the user's mouse hovers over a "Tclass" div.

            So for example, if that was the only jQuery code you want to run on the page, then you would do this...

            HTML Code:
            <script>
                $(function(){  // Tells the browser to wait until the document is ready
                    $(".Tclass").hover(function(){  // When a "Tclass" div is hovered over...
                        $(".Tclass").css("background-color", "red");  // Change the BG color to red
                    });
                }); 
            </script>
            Signature

            {{ DiscussionBoard.errors[8147112].message }}
            • Profile picture of the author Michael71
              Why using jQuery for a simple hover that can be done via CSS?

              Originally Posted by Brandon Tanner View Post

              That function is automatically executed whenever the user's mouse hovers over a "Tclass" div.

              So for example, if that was the only jQuery code you want to run on the page, then you would do this...

              HTML Code:
              <script>
                  $(function(){  // Tells the browser to wait until the document is ready
                      $(".Tclass").hover(function(){  // When a "Tclass" div is hovered over...
                          $(".Tclass").css("background-color", "red");  // Change the BG color to red
                      });
                  }); 
              </script>
              Signature

              HTML/CSS/jQuery/ZURB Foundation/Twitter Bootstrap/Wordpress/Frontend Performance Optimizing
              ---
              Need HTML/CSS help? Skype: microcosmic - Test Your Responsive Design - InternetCookies.eu

              {{ DiscussionBoard.errors[8147131].message }}
              • Profile picture of the author Brandon Tanner
                Originally Posted by Michael71 View Post

                Why using jQuery for a simple hover that can be done via CSS?
                Because the OP may want to do something more complex than simply changing the background color (like maybe call another function, etc), when a user hovers over a div. I only used 'background color' as an example.
                Signature

                {{ DiscussionBoard.errors[8147216].message }}
                • Profile picture of the author Patrick
                  Originally Posted by Brandon Tanner View Post

                  Because the OP may want to do something more complex than simply changing the background color (like maybe call another function, etc), when a user hovers over a div. I only used 'background color' as an example.
                  If the OP really wants to use it then it won't work due to the thing below missing...... and then again its the basics ..

                  <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
                  {{ DiscussionBoard.errors[8147299].message }}
                  • Profile picture of the author Brandon Tanner
                    Originally Posted by Patrick View Post

                    If the OP really wants to use it then it won't work due to the thing below missing...... and then again its the basics ..
                    OK... if you want to play that game, then don't forget about this part too...

                    <html>

                    :rolleyes:
                    Signature

                    {{ DiscussionBoard.errors[8147455].message }}
                    • Profile picture of the author Patrick
                      Originally Posted by Brandon Tanner View Post

                      OK... if you want to play that game, then don't forget about this part too...

                      <html>

                      :rolleyes:
                      Nope I used to play video games when I was in school, but the fact is that when someone gets education, they should get from the basics, not just jump to some code and then think about the basics...:rolleyes:

                      Moreover the OP asked a simple solution which can be done through CSS, don't understand what's the point of making him jump to jQuery (when he specified that he is a beginner) for that and creating more confusion in his mind....:confused: (unless you want him to get really confused and follow your signature )

                      Now if you again found this a "game", you can create another sentence of funny post and get "thanks" for it :p
                      {{ DiscussionBoard.errors[8148088].message }}
      • Profile picture of the author Michael71
        When you master the basics you can start to learn complicated stuff.

        Originally Posted by merkv View Post

        Thanks for the advise, there's nothing particular with "T" shape, i just thought of it as a complicated figure, since all div shapes are just rectangle, square, rounded corners, triangles or circles.
        .
        The Irregular shape i want to use it for is for icons,
        for example a T icon(sorry i used this figure again..)yes it can be done by combining 2 divs, but can it be hovered as one element? without enclosing it in a container.

        This may sound weird, but what i watn to achieve is to create an irregular shape div which is consider as one element , without combining 2 or more divs together.

        Sorry i'm still a beginner and trying to make my own webpage thru local host at my PC, I'm just trying to learn more complicated methods rather than the basics.
        Signature

        HTML/CSS/jQuery/ZURB Foundation/Twitter Bootstrap/Wordpress/Frontend Performance Optimizing
        ---
        Need HTML/CSS help? Skype: microcosmic - Test Your Responsive Design - InternetCookies.eu

        {{ DiscussionBoard.errors[8147134].message }}
  • Profile picture of the author Brandon Tanner
    All div's are rectangular. Actually, that's not entirely true, because you can make circular shaped div's as well if you use border-radius (but that's a CSS3 trick, so it won't work in older browsers).

    Of course, there's nothing preventing you from arranging multiple div's together in the shape of a T.
    Signature

    {{ DiscussionBoard.errors[8146192].message }}
  • Profile picture of the author Andrew H
    haha -> don't forget the body tags too! <body>
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8147582].message }}
    • Profile picture of the author Patrick
      Originally Posted by Andrew H View Post

      haha -> don't forget the body tags too! <body>
      Wrong...

      After <html> comes <head> "haha"
      {{ DiscussionBoard.errors[8148159].message }}
  • Profile picture of the author Edge360
    How about this link? CSS3 Shapes | CSS3 Shapes Resource

    Some great CSS3 effects here, just be careful with older browsers, maybe use a fallback stylesheet and use an image replacement instead
    {{ DiscussionBoard.errors[8148623].message }}
    • Profile picture of the author longblog
      Originally Posted by Edge360 View Post

      How about this link? CSS3 Shapes | CSS3 Shapes Resource

      Some great CSS3 effects here, just be careful with older browsers, maybe use a fallback stylesheet and use an image replacement instead
      That page you linked is an excellent resource. I don't really see the point though, because everything is still constrained to a rectangle by the surrounding divs.

      Most designers just use graphical elements within standard divs to achieve what I believe the OP is trying to accomplish. If you want a T shaped logo, then you just use a rectangular div, and have the logo background either match the website background, or use a png with transparency. Am I missing something here, or is the OP making this excessively complicated out of lack of experience?
      {{ DiscussionBoard.errors[8153338].message }}
  • Profile picture of the author ColorVila
    CSS3 can achieve what you want. And javascript is another good choice.
    {{ DiscussionBoard.errors[8152194].message }}
  • Profile picture of the author JamesLennon
    FYI you dont need to write <html> <head> or even <body> if you don't want
    {{ DiscussionBoard.errors[8154262].message }}

Trending Topics