0

i style simple list of articles, i just found out that my a href on image is smaller than actual image and its not right as soon as its his parent. And i don't know how to fix it, This is how it looks: enter image description here

My HTML looks like:

<div id="article-container">

<ul>
      <li><a href="#"><img src="images/foto.jpg" alt="Popis"></a>
            <h2><a href="#">Název článku</a></h2>
            <p><span><strong>28. 2. 2014 8:29</strong> od Dwandy</span><br>
              Ahoj, jak se máš? Já úplně úžasně a úpe nejvíc. Závidíš, he? </p>
            <p class="more"><a href="#" class="links">Přečíst</a><br>
              <a href="#">4 reakce</a></p>
            <hr>
       </li>

  <li><a href="#"><img src="images/foto.jpg" alt="Popis"></a>
           <h2><a href="#">Název článku</a></h2>
           <p><span><strong>28. 2. 2014 8:29</strong> od Dwandy</span><br>
             Ahoj, jak se máš? Já úplně úžasně a úpe nejvíc. Závidíš, he? </p>
           <p class="more"><a href="#" class="links">Přečíst</a><br>
             <a href="#">4 reakce</a></p>
           <hr>
      </li>

      <li><a href="#"><img src="images/foto.jpg" alt="Popis"></a>
           <h2><a href="#">Název článku</a></h2>
           <p><span><strong>28. 2. 2014 8:29</strong> od Dwandy</span><br>
             Ahoj, jak se máš? Já úplně úžasně a úpe nejvíc. Závidíš, he? </p>
           <p class="more"><a href="#" class="links">Přečíst</a><br>
             <a href="#">4 reakce</a></p>
           <hr>
      </li>
 </ul>

My CSS looks like:

#article-container{
  width: 980px;
    margin: 0 auto;
    color:#4d4d4d;
    font-size:90%;
  height: 144px;
}

#article-container br, hr {
    display:none;
}
#article-container ul {
    width:960px;
  height: 144px
    overflow:hidden;
    margin:0;
    padding:15px 0;
}
#article-container li {
    width:310px;
    display:inline-block;
    list-style:none;
    padding:0;
    margin:0px 0px 0px 8px;
}
#article-container a{
    display:block;
}
#article-container img {
    float:left;
    margin: 0 10px 0 0
}
#article-container a img {
    border:2px solid #999e8a;
}
#article-container a:hover img {
    border-color:#000
}
#article-container h2 {
    margin: 0;
    padding: 0 0 10px 0;
    font-size:110%;
    font-weight:normal;
}
#article-container h2 a {
    color:#4d4d4d
}
#article-container h2 a:hover {
    color:#840000
}
#article-container p {
    padding: 0 10px 0 0;
    margin:0
}
#article-container p span {
    display:block;
    padding: 0 0 5px 0
}
#article-container p.more {
    padding: 0px 0 0 0;
    overflow:hidden
}


#article-container p.more a {
    color:#2e79bc;
    line-height: 27px;
}
#article-container p.more a:hover {
    color:#840000
}
#article-container p.more a.links {
    float:right;
    padding: 5px 10px;
    background:#2e79bc;
    color:#fff;
    margin-right:15px;
    text-decoration:none;
    border-radius:3px;
    line-height: 18px;
}
#article-container p.more a.links:hover {
    background:#000
}

Demo : FIDDLE Whole WEBSITE DEMO

Can somebody help me to make this same width height as image?

Ben
  • 20,737
  • 12
  • 71
  • 115
user258459
  • 443
  • 1
  • 5
  • 12
  • [Read why it happens](http://stackoverflow.com/questions/16568272/how-css-float-works-why-height-of-the-container-element-doesnt-increase-if-it/16568504#16568504) – Mr. Alien Apr 27 '14 at 11:13

2 Answers2

1

Since <img/> is floatting , <a> doesn't wrap it. Trigger layout with overflow or float .


<edit> About dealing with floatting elements : see: http://css-tricks.com/all-about-floats/</edit>


http://fiddle.jshell.net/qB8V4/1/ float seems to be what you need here .


then , you still neeed to manage floatting interaction behavior setting overflow to elements aside it, such as : <p>, <h2> :

http://fiddle.jshell.net/qB8V4/2/

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129
  • hey man, it help but it also destroy the "date" text style :) – user258459 Apr 27 '14 at 11:17
  • what do you mean , destroy ? – G-Cyrillus Apr 27 '14 at 11:18
  • You can see it on your own demo :) the date "28. 2. 2014 8:29" is in other line then it should be and everything is a bit moved – user258459 Apr 27 '14 at 11:20
  • right, i just saw it and updated the fiddle . http://fiddle.jshell.net/qB8V4/2/ . (layout to trigger ) – G-Cyrillus Apr 27 '14 at 11:21
  • i added overflow to h2 an p , to trigger layout, so elements wraps floatting element inside and sees the floatting element standing aside/outside. – G-Cyrillus Apr 27 '14 at 11:27
  • oh mate it actualy not looks fine in firefox, check this : http://funedit.com/imgedit/soubory/small_11750681601398598462.jpg And doing the same to my friend on chrome :( – user258459 Apr 27 '14 at 11:34
  • still FLOATTING issues and probably some padding/margin not collapsing anymore since you partially fix layout issues – G-Cyrillus Apr 27 '14 at 11:36
  • is there a chance you can help me to fix it? – user258459 Apr 27 '14 at 11:36
  • i guess, but in my ff or chtome , i see no bug online at this time ? did you update your live site ? – G-Cyrillus Apr 27 '14 at 11:39
  • i think it can be because of that

    style if u check on it in borowser its is/ to another element as well

    – user258459 Apr 27 '14 at 11:39
  • i did, you can see easy that bug with zoom size (ctrl + scroll up) – user258459 Apr 27 '14 at 11:40
  • okay i see it , when you zoom this way you increase font-size and the white-space in between li. Reduce a little font-size for ul , down to 80% for instance (inspector tells me it is set at 90%) – G-Cyrillus Apr 27 '14 at 11:45
  • Its uploaded, but isnt there other way how to fix it? Beausee this is just about how much user zoom the site or with what resolution he come on site – user258459 Apr 27 '14 at 11:50
  • set `#article-container{font-size:80%;}` and `#article-container li {font-size:120%;}` to fix your zooming behavior, so white-space in between inline-boxes won't groww to much – G-Cyrillus Apr 27 '14 at 11:51
  • Also when text is smaller its harder to read it and its not copy of .psd i had :) – user258459 Apr 27 '14 at 11:52
  • do the update i advise , and let's see what happens :) – G-Cyrillus Apr 27 '14 at 11:52
  • done, but i add 70% and 130% , right if i zoom out a lot it fails but not in normal us i believe, or is there way how to make it 100% fix? – user258459 Apr 27 '14 at 11:56
  • make your li floatting instead inline-block, so no need to deal with font-size anymore :) `#article-container li {float:left;}` – G-Cyrillus Apr 27 '14 at 11:58
0

It is a float problem. just put overflow:hidden to your css element #article-container a.

Test: http://jsbin.com/yavegeru/1/

Canser Yanbakan
  • 3,780
  • 3
  • 39
  • 65