在 CSS 中向上移动图像
Moving an image up in CSS
因此,在过去的一个小时里,我一直在尝试使用 css 属性 position
移动此图像。我的问题是每次我使用 top
或 bottom
移动它时它都无法正常工作。这是它的屏幕截图 before using said properties and after。您可以在下面找到我的 html & css。最后,这个 position
必须是 absolute
否则图像会完全消失。
HTML
<section class="row posts">
<div class="col-md-6 col-md-offset-3">
<header><h3>What others have to say...</h3></header>
@foreach($posts as $post)
<article class="post" data-postid="{{ $post->id }}">
<p>{{ $post->body }}</p>
<div class="info">
Posted by {{ $post->user->user_name }} on {{ $post->created_at }}
</div>
<div class="interaction">
<a href="#" class="like heart"></a> |
<a href="#" class="like">Dislike</a>
@if(Auth::user() == $post->user)
|
<a href="#" class="edit">Edit</a> |
<a href="{{ route('post.delete', ['post_id' => $post->id]) }}">Delete</a>
@endif
</div>
</article>
@endforeach
</div>
</section>
CSS
.heart{
background: url('http://localhost:8079/uncaughterror/public/src/img/web_heart_animation.png');
background-position: left;
background-repeat: no-repeat;
height: 50px; width: 50px;
cursor: pointer;
position: absolute;
left: 12px;
bottom: 5px; //This or 'top' is what causes my entire problem
background-size:1450px;
}
.heart:hover {
background-position: right;
}
添加这个如何:
.interaction {
position: relative;
}
我认为你应该把 no-repeat
和 background
放在同一行
它对我有用,我不知道为什么
因此,在过去的一个小时里,我一直在尝试使用 css 属性 position
移动此图像。我的问题是每次我使用 top
或 bottom
移动它时它都无法正常工作。这是它的屏幕截图 before using said properties and after。您可以在下面找到我的 html & css。最后,这个 position
必须是 absolute
否则图像会完全消失。
HTML
<section class="row posts">
<div class="col-md-6 col-md-offset-3">
<header><h3>What others have to say...</h3></header>
@foreach($posts as $post)
<article class="post" data-postid="{{ $post->id }}">
<p>{{ $post->body }}</p>
<div class="info">
Posted by {{ $post->user->user_name }} on {{ $post->created_at }}
</div>
<div class="interaction">
<a href="#" class="like heart"></a> |
<a href="#" class="like">Dislike</a>
@if(Auth::user() == $post->user)
|
<a href="#" class="edit">Edit</a> |
<a href="{{ route('post.delete', ['post_id' => $post->id]) }}">Delete</a>
@endif
</div>
</article>
@endforeach
</div>
</section>
CSS
.heart{
background: url('http://localhost:8079/uncaughterror/public/src/img/web_heart_animation.png');
background-position: left;
background-repeat: no-repeat;
height: 50px; width: 50px;
cursor: pointer;
position: absolute;
left: 12px;
bottom: 5px; //This or 'top' is what causes my entire problem
background-size:1450px;
}
.heart:hover {
background-position: right;
}
添加这个如何:
.interaction {
position: relative;
}
我认为你应该把 no-repeat
和 background
它对我有用,我不知道为什么