42

My post title here could be misleading. first have a look at HTML i have currently: enter image description here

As you can see, each column's text content overflows to next column. Secondly, each of them is not horizontal aligned. (eg the link for view details does not align straight). I want them to be aligned straight irrespective of length of text.

Here is my HTML code: (the content here is dynamically generated. so the no of items will vary). I use bootstrap 3 in my code.

<div class="row" style="box-shadow: 0 0 30px black;">


      <div class="col-6 col-sm-6 col-lg-4">
        <h3>2005 Volkswagen Jetta 2.5 Sedan (worcester   http://www.massmotorcars.com) $6900</h3>
        <p>
          <small>2005 volkswagen jetta 2.5 for sale has 110,000 miles powere doors,power windows,has ,car drives excellent ,comes with warranty if you&#39;re ...</small>
        </p>
        <p>
          <a class="btn btn-default" href="/search/1355/detail/" role="button">View details &raquo;</a>
          <button type="button" class="btn bookmark" id="1355" >
            <span class="
                  glyphicon glyphicon-star-empty "></span>
          </button>
        </p>

      </div>
      <!--/span-->
      <div class="col-6 col-sm-6 col-lg-4">
        <h3>2006 Honda Civic EX Sedan (Worcester www.massmotorcars.com) $7950</h3>
        <p>
          <small>2006 honda civic ex has 110,176 miles, has power doors ,power windows,sun roof,alloy wheels,runs great, cd player, 4 cylinder engen, ...</small>
        </p>
        <p>
          <a class="btn btn-default" href="/search/1356/detail/" role="button">View details &raquo;</a>
          <button type="button" class="btn bookmark" id="1356" >
            <span class="
                  glyphicon glyphicon-star-empty "></span>
          </button>
        </p>

      </div>
      <!--/span-->
      <div class="col-6 col-sm-6 col-lg-4">
        <h3>2004 Honda Civic LX Sedan  (worcester www.massmotorcars.com) $5900</h3>
        <p>
          <small>2004 honda civic lx sedan has 134,000 miles, great looking car, interior and exterior looks nice,has cd player, power windows ...</small>
        </p>
        <p>
          <a class="btn btn-default" href="/search/1357/detail/" role="button">View details &raquo;</a>
          <button type="button" class="btn bookmark" id="1357" >
            <span class="
                  glyphicon glyphicon-star-empty "></span>
          </button>
        </p>

      </div>
</div>
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122

4 Answers4

82

Add the following style to your h3 elements:

word-wrap: break-word;

This will cause the long URLs in them to wrap. The default setting for word-wrap is normal, which will wrap only at a limited set of split tokens (e.g. whitespaces, hyphens), which are not present in a URL.

kpentchev
  • 3,040
  • 2
  • 24
  • 41
25

Now Update word-wrap is replace by :

overflow-wrap:break-word;

Compatible old navigator and css 3 it's good alternative !

it's evolution of word-wrap ( since 2012... )

See more information : https://www.w3.org/TR/css-text-3/#overflow-wrap

See compatibility full : http://caniuse.com/#search=overflow-wrap

Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
Css lover
  • 251
  • 3
  • 3
1

Your code is working fine using bootatrap v3.3.7, but you can use word-break: break-word if it's not working at your end.

which would then look like this -

snap

<html>

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
    <div class="row" style="box-shadow: 0 0 30px black;">
        <div class="col-6 col-sm-6 col-lg-4">
            <h3 style="word-break: break-word;">2005 Volkswagen Jetta 2.5 Sedan (worcester http://www.massmotorcars.com)
                $6900</h3>
            <p>
                <small>2005 volkswagen jetta 2.5 for sale has 110,000 miles powere doors,power windows,has ,car drives
                    excellent ,comes with warranty if you&#39;re ...</small>
            </p>
            <p>
                <a class="btn btn-default" href="/search/1355/detail/" role="button">View details &raquo;</a>
                <button type="button" class="btn bookmark" id="1355">
                    <span class="
                      glyphicon glyphicon-star-empty "></span>
                </button>
            </p>
        </div>
        <!--/span-->
        <div class="col-6 col-sm-6 col-lg-4">
            <h3 style="word-break: break-word;">2006 Honda Civic EX Sedan (Worcester www.massmotorcars.com) $7950</h3>
            <p>
                <small>2006 honda civic ex has 110,176 miles, has power doors ,power windows,sun roof,alloy wheels,runs
                    great, cd player, 4 cylinder engen, ...</small>
            </p>
            <p>
                <a class="btn btn-default" href="/search/1356/detail/" role="button">View details &raquo;</a>
                <button type="button" class="btn bookmark" id="1356">
                    <span class="
                      glyphicon glyphicon-star-empty "></span>
                </button>
            </p>

        </div>
        <!--/span-->
        <div class="col-6 col-sm-6 col-lg-4">
            <h3 style="word-break: break-word;">2004 Honda Civic LX Sedan (worcester www.massmotorcars.com) $5900</h3>
            <p>
                <small>2004 honda civic lx sedan has 134,000 miles, great looking car, interior and exterior looks
                    nice,has
                    cd player, power windows ...</small>
            </p>
            <p>
                <a class="btn btn-default" href="/search/1357/detail/" role="button">View details &raquo;</a>
                <button type="button" class="btn bookmark" id="1357">
                    <span class="
                      glyphicon glyphicon-star-empty "></span>
                </button>
            </p>
        </div>
    </div>
</body>

</html>
Tushar Walzade
  • 3,737
  • 4
  • 33
  • 56
-5

1) Maybe oveflow: hidden; will do the trick?

2) You need to set the size of each div with the text and button so that each of these divs have the same height. Then for your button:

button {
  position: absolute;
  bottom: 0;
}
stianlp
  • 999
  • 9
  • 19
  • Try to inspect your elements and see if anything is causing the text to flow outside your div. HTML is supposed to be responsive and the text should wrap automatically. If you cannot find anything, try this: http://www.w3schools.com/cssref/css3_pr_word-wrap.asp – stianlp May 13 '14 at 21:40
  • By removing the overflow does this not make the layout problem worse? – RustyIngles Dec 09 '15 at 13:19