我希望我的圖示位于input元素內部,目前它們都混合在一起。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<link rel="stylesheet" href="style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Mochiy Pop P One&display=swap"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
</head>
<body>
<div id="mainContainer">
<div id="container">
<table id="mainForm">
<div class="mainTable">
<tr>
<th>
<label for="user" class="label">User</label>
</th>
<div class="icon">
<i class="fa-solid fa-user"></i>
</div>
<td>
<input type="text" class="inp" />
</td>
</tr>
</div>
<div class="mainTable">
<tr>
<th>
<label for="address" class="label">Address</label>
</th>
<div class="icon">
<i class="fa-solid fa-location-dot"></i>
</div>
<td>
<input type="text" class="inp" />
</td>
</tr>
</div>
<div class="mainTable">
<tr>
<th>
<label for="password" class="label">Password</label>
</th>
<div class="icon">
<i class="fa-solid fa-key"></i>
</div>
<td>
<input type="text" class="inp" />
</td>
</tr>
</div>
</table>
<div id="mainBtn">
<button id="btn">Submit</button>
</div>
</div>
</div>
<script src="app.js"></script>
</body>
</html>
CSS
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
background-color: rgb(253, 253, 253);
}
#mainContainer{
background-color: rgb(242, 53, 53);
width: 600px;
height: 400px;
display: flex;
justify-content: center;
align-items: center;
margin: 0 auto;
border-radius: 15px;
box-shadow: 5px 5px 5px rgb(189, 189, 189);
margin-top: 200px;
}
#mainBtn{
display: flex;
justify-content: center;
margin-top: 10px;
}
.label{
color: #fff;
font-size: 30px;
font-family: 'Ubuntu', sans-serif;
margin-right: 15px;
display: inline-block
}
.inp{
border-radius: 5px;
outline: none;
border: 2px solid #fff;
padding: 10px 30px;
width: 300px;
}
#btn{
border-radius: 5px;
padding: 5px;
background-color: #fff;
outline: none;
border: 2px solid #fff;
cursor: pointer;
font-size: 20px;
font-family: 'Ubuntu', sans-serif;
font-weight: bold;
}
#mainForm{
border-spacing: 0 0.8em;
position: relative;
}
.icon{
position: absolute;
}
uj5u.com熱心網友回復:
幾乎沒有什么問題,而且這是一個非常廣泛的問題,因為有很多方法可以在 CSS/HTML 中獲得相同的結果。首先,標簽“for”選項應對應于輸入“id”。您的輸入沒有 ID,因此請添加它們或從標簽中洗掉“for”。
同樣屬于一起的代碼,應該一起,沒有必要將圖示保留在表格單元格之外。
考慮在輸入元素上使用偽元素作為圖示。將輸入標記為相對位置,在前面添加一些填充并使用絕對定位將偽元素移動到所需位置。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/419791.html
標籤:
