Mr_MiXiaole 2021-04-26 12:28 采纳率: 100%
浏览 106
已采纳

求助!CSS添加背景图后 after失效。谢谢!

求助,css鼠标移动效果失效,

整体样子是这样的,我想实现下图效果

代码我写出来了,是这样:

        <!--内容文案-->
		<div class="content_text">
			<p class="content_text_medium">1</p>
			<p class="content_text_light">2</p>
		</div>
		<!--鼠标移动点击跳转-->
		<div class="content_move">
			<a href="#">
				<div class="content_move_border">
        			<div class="content_move_text">了解更多</div>
				</div>
			</a>
		</div>
/*鼠标移动效果,从中间至上下*/
.content_move{ width: 160px; height: 42px; margin: 50px auto 80px; overflow: hidden;}
.content_move_border{ display: flex; }
.content_move_text{ width: 160px; height: 40px; line-height: 40px; text-align: center; cursor:pointer; color: #232323; border: 1px solid #232323; border-radius: 3px; position: relative; transition: 0.4s linear;}
.content_move_text:hover{ color: #ffffff;}
.content_move_text:after{ width: 0; cursor:pointer; position: absolute; content: ""; top: 0; bottom: 0; left: 0; z-index: -1; background: #232323; transition: 0.2s linear;}
.content_move_text:hover:after{ width: 100%;}

然后下一部分,我打算按照设计,将图片设为背景图,可是效果出来是这样

代码是这样

        <div class="content_service">
			<div class="content_service_speck">
				<!--内容文案-->
				<div class="content_text">
					<p class="content_ser_medium">1</p>
					<p class="content_ser_light">2</p>
				</div>
				<!--鼠标移动点击跳转-->
				<div class="content_ser">
					<a href="#">
						<div class="content_ser_border">
							<div class="content_ser_text">了解更多</div>
						</div>
					</a>
				</div>
			</div>
		</div>
/*服务区*/
.content_service{ width: 1920px; height: 960px; margin: auto; margin-top: 80px; background: url("../images/CY_Content_Smart_08.jpg"); background-size: contain; position: relative;}
.content_service_speck{ width :1920px; height: 320px; margin: 320px auto; position: absolute;}

/*服务区通用文案设定*/
.content_ser_medium{ width: auto; height: auto; text-align: center; color: #FFFFFF; font-family:'Microsoft Yahei'; font-size:48px; font-weight: 900; text-decoration:none; margin-top: 80px; letter-spacing: 5px;}
.content_ser_regular{ width: auto; height: auto; text-align: center; color: #FFFFFF; font-family:'Microsoft Yahei'; font-size:32px; font-weight: 500; text-decoration:none; margin-top: 30px; letter-spacing: 3px;}
.content_ser_light{ width: auto; height: auto; text-align: center; color: #FFFFFF; font-family:'Microsoft Yahei'; font-size:24px; font-weight: 100; text-decoration:none; margin-top: 30px; letter-spacing: 1px;}

/*服务区鼠标移动效果,从中间至上下*/
.content_ser{ width: 160px; height: 42px; margin: 50px auto 80px; overflow: hidden;}
.content_ser_border{ display: flex; }
.content_ser_text{ width: 160px; height: 40px; line-height: 40px; text-align: center; cursor:pointer; color: #FFFFFF; border: 1px solid #FFFFFF; border-radius: 3px; transition: 0.4s linear;}
.content_ser_text:hover{ color: #232323;}
.content_ser_text:after{ width: 0; cursor:pointer; position: absolute; content: ""; top: 0; bottom: 0; left: 0; z-index: -1; background: #FFFFFF; transition: 0.2s linear;}
.content_ser_text:hover:after{ width: 100px;}

我百度了好久,但是不知道是哪里问题,看CSDN里有说是关于after的问题,新手小白,还望大佬能帮指导下,因为下面设计的,好多都是带背景图的,这个问题解决不了,之后工作进行不下去,谢谢大佬帮帮忙!!!

  • 写回答

4条回答 默认 最新

  • 代码的灵魂是bug! 2021-04-26 14:51
    关注

    1、content_service加z-index: 0

    2、content_ser加position: relative;

    3、content_ser_text:hover:after{ width: 160px;}

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站