代码如下:
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都向下移动。我该如何解决这个问题?谢谢。
发布于 2015-12-20 07:02:20
它们根本没有联系在一起,它们只是对元素的增长做出反应,因为你的链接在悬停时会使你的字体变得更大,而你的图像在悬停时会变得更有边框。
避免此行为的最佳方法是设置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
https://stackoverflow.com/questions/34376237
复制相似问题