我在一個虛擬練習網站上作業,我嘗試使用帶有影像的錨標記,以便我可以從該影像獲得超鏈接,但每當我嘗試使用其位置屬性(相對)更改影像的位置時。它只是在螢屏上的其他地方創建一個相同大小的不可見鏈接。我嘗試了多種方法,但它一直在發生。除非我使用position: absolute. 幫助。提前致謝。;)
[而且我知道它會創建一個相同大小的不可見超鏈接,因為農藥擴展允許我看到螢屏上的所有元素。]
我想當我嘗試將影像移動到其他位置時會出現問題,但我不知道為什么會發生。[請忽略我效率低下的代碼,幾天前開始 Web 開發;)]
body{
margin: 0;
background-color: #222831;
}
nav{
background-color: #ebebeb;
position: relative;
padding: 5px;
}
nav .icon{
margin: 0;
display: inline-block;
margin: 5px 0 0px 10px;
color: #121212;
height: 25px;
width: 25px;
}
.search-bar{
position: relative;
bottom: 7px;
left: 10px;
background: url(../Images/search-icon.png) no-repeat scroll 2px 2px;
padding-left:30px;
width: 400px;
}
nav h1{
display: inline-block;
position: relative;
left: 10%;
}
.profile-pic{
margin: 0;
position: absolute;
color: #121212;
height: 30px;
width: 30px;
right: 200px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="../CSS/home.css">
<link rel="icon" href="../Images/menu.png">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
<nav>
<img src="../Images/menu.png" alt="SQUARE LOGO" class = "icon">
<input type="text" class="search-bar" id="search-bar">
<h1>SQUARE</h1>
</nav>
<a href="index.html"><img class="profile-pic" src="../Images/user.png" alt="Profile Picture" href="index.html "></a> <!-- This is the code producing error--!>
</body>
</html>
uj5u.com熱心網友回復:
您不需要使用相對,因為絕對定位將默認相對于身體。您確實需要將 left 或 top 添加到絕對元素
body{
margin: 0;
background-color: #222831;
}
nav{
background-color: #ebebeb;
padding: 5px;
}
nav .icon{
margin: 0;
display: inline-block;
margin: 5px 0 0px 10px;
color: #121212;
height: 25px;
width: 25px;
}
.search-bar{
bottom: 7px;
left: 10px;
background: url(../Images/search-icon.png) no-repeat scroll 2px 2px;
padding-left:30px;
width: 400px;
}
nav h1{
display: inline-block;
}
.profile-pic{
margin: 0;
position: absolute;
color: #121212;
height: 30px;
width: 30px;
right: 200px;
left:50%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="../CSS/home.css">
<img src="https://via.placeholder.com/50">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
<nav>
<img src="https://via.placeholder.com/50" alt="SQUARE LOGO" class = "icon">
<input type="text" class="search-bar" id="search-bar">
<h1>SQUARE</h1>
</nav>
<a href="index.html"><img class="profile-pic" src="https://via.placeholder.com/25" alt="Profile Picture" > </a>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/532022.html
標籤:htmlcss
上一篇:我想使用html和css更改導航欄span標簽以顯示在圖示下方
下一篇:洗掉h1后切換開關出現故障
