gpt4 book ai didi

javascript - HTML和CSS img是相连的怎么分开?

转载 作者:行者123 更新时间:2023-11-28 06:39:40 26 4
gpt4 key购买 nike

代码如下:

body{
background-image:url('http://wallpoper.com/images/00/31/33/51/black-background_00313351.jpg');
}

div.header{
background-color:#F0F8FF;
text-align:center;
padding:3px;
opacity:0.2;
height:60px;
}
h1{
font-family:'Lucida Console';
font-weight:bold;
color:blue;
}
div.header ul {
font-style:none;
font-size:50%;
list-style-type:none;
position:relative;
right:700px;
bottom:50px;
}
ul{

list-style-type:none;
line-height:220%;
}
a:link{
color:white;
font-size:150%;
text-decoration:none;

}
a:visited{
color:white;
font-size:150%;
text-decoration:none;
margin:10px;
}
a:hover{
font-size:220%;
color: #7CB9E8;
}
div.gallary img{
position:relative;
left:160px;
top:150px;
margin:5px;
width:200px;
height:200px;

}

img:hover{
width:220px;
height:220px;
border: 1px solid #ccc;
}
<!DOCTYPE HTML>
<html>
<head>
<link rel = "stylesheet" href = "stylesheet.css">
</head>
<body>
<div class = "header">
<h1>Gordong Guitar Lesson</h1>
<ul>
<li>Mailbox:147ox</li>
<li>phone: (151)-232-4576</li>
<li>Zip:223</li>
</ul>
</div>
<div class +"nav" >
<ul>
<li><a href = "">Home</a></li>
<li><a href = "">Lessons</a></li>
<li><a href = "">Videos</a></li>
<li><a href = "">apply</a></li>
</ul>
</div>
<div class = "gallary">
<img src = "http://www.londonguitaracademy.com/wp-content/uploads/guitar-lessons1.jpg"></img>
<img src = "http://lessonsthatrock.com/wp-content/uploads/2012/02/guitar-lessons-long-beach1.jpg"></img>
<img src = "http://tampabaymusicacademy.com/blog/wp-content/uploads/2015/10/guitarlessons.jpg"></img>
<img src = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTUpvERhA8lpbGi7ic9GGThcF20NZl1ZrDTT_N-mqvZwTqdpw7vMA"></img>
<img src = "http://hobartguitarlessons.files.wordpress.com/2011/11/guitar-man-new_221.jpg?w=300&h=300"></img>
</div>
</body>
</html>

我的问题是当我运行这段代码并将鼠标悬停在链接或图像上时,它们似乎都通过某个看不见的盒子连接在一起。例如,当我将鼠标悬停在“主页”链接上时。每个链接和每个 img 都向下移动。我该如何解决?谢谢。

最佳答案

它们根本没有连接,它们只是响应元素的增长,因为你的链接在悬停时使你的字体变大,而你的图像在悬停时变得有边框。

避免这种行为的最佳方法是设置 border-sizing 属性:

/* apply a natural box layout model to all elements, but allowing components to change */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}

* { Box-sizing: Border-box } FTW通过保罗爱尔兰

关于javascript - HTML和CSS img是相连的怎么分开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34376237/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com