CSS how to get the: a img on top, insted of the first a href "<a></a><a><img></a>"without floating

StackOverflow https://stackoverflow.com/questions/23468664

  •  15-07-2023
  •  | 
  •  

문제

Hi I'm working on a little website and need some help with some CSS coding. I'm trying to display the image on top/first, insted of the a href headline and I can't use float to do this or change the HTML this has to be done only by CSS, anyone know an alternative way of doing this? TIA

<ul>
<li>
<a href="url">headline</a>
<a href="url"><img class="thumbnail" alt="" src="image.jpg"></a>
some text here...
<a href="url">read more about this article</a>
</li>
</ul>
도움이 되었습니까?

해결책 2

I found another way of doing this:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
ul {list-style: none; margin: 0; padding: 0;}
li {position: relative; overflow: hidden;}
a {display: block;}
a:first-child {display: table-footer-group;}
a:nth-child(2) {display: table-header-group;}
a img{width:100%;}
</style>
</head>
<body>

<ul>
  <li>
     <a href="url">headline</a>
     <a href="url"><img class="thumbnail" alt="" src="http://placehold.it/200X200"></a>
     some text here...
     <a href="url">read more about this article</a>
  </li>
</ul>

</body>
</html>

다른 팁

You could do something like this (following the lines of what user3008011 said above): http://codepen.io/pageaffairs/pen/Lzwxc

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
ul {list-style: none; margin: 0; padding: 0;}
li {position: relative; overflow: hidden;}
a {display: block;}
a:first-child {margin-top: 210px;}
a:nth-child(2) {position: absolute; top: 0;}
</style>
</head>
<body>

<ul>
    <li>
        <a href="url">headline</a>
        <a href="url"><img class="thumbnail" alt="" src="http://placehold.it/200X200"></a>
        some text here...
        <a href="url">read more about this article</a>
    </li>
</ul>

</body>
</html>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top