html - 当我尝试插入图像时,边框和输入会移动
问题描述
我对编程真的很陌生。每当我尝试使用它插入图像时,它都会向下移动边框并向下输入。然后我必须将它们移回以匹配文本,如下图所示。我在 CSS 中使用“margin:”来做到这一点。为什么我尝试插入时边框和输入会向下移动?有没有比使用 :margin:" 更简单的方法来定位边框等内容?
CSS(用于导航栏和输入):
#navBar {
border: 2px solid black;
height: 30px;
width: 43%;
margin-top: -42px;
margin-left: 405px;
padding: 5px;
}
#searchInput {
margin-top: 3px;
margin-left: 1250px;
height: 35px;
width: 185px;
border-radius: 10px;
font-family: 'Roboto', sans-serif;
font-size: 20px;
outline: none;
}
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Restaurant</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href= "{{ url_for('static', filename='style.css') }}">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Ubuntu&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto&family=Ubuntu&display=swap" rel="stylesheet">
</head>
<body>
<img src="/static/searchImage.png" id="searchImage">
<div id="search">
<input id="searchInput" type="text">
</div>
<div id="navBar">
<a href="deals">
<button id="dealsButton">Deals</button>
</a>
<a href="burgers">
<button id="burgersButton">Burgers</button>
</a>
<a href="drinks">
<button id="drinksButton">Drinks</button>
</a>
<a href="sides">
<button id="sidesButton">Sides</button>
</a>
<a href="desserts">
<button id="dessertsButton">Desserts</button>
</a>
</div>
</body>
</html>
图片:
在插入图像之前,边框与文本完全对齐,输入就在边框旁边。但是当我插入时会发生这种情况。
解决方案
推荐阅读
- continuous-integration - 如何在 gitlab CI 中签署 APK 并将版本发送到 slack
- linux - detox init -r jest 在 Linux ubuntu 上抛出错误。它的任何替代命令
- r - R geom_bar:按组可视化单个大小和总大小
- html - HTML img 为什么加载不了本地图片的相对路径,而是把图片复制到同一个目录下显示?
- google-apps-script - 从某一行到最后一行的循环函数
- node.js - DiscordAPIError:缺少权限
- reactjs - 如何更改其他文件 React 中的值
- css - 即使设置 CSS min-height,Lighthouse 也会报告高 CLS
- python - 如何使用连体网络在自定义生成器上执行数据增强
- wordpress - 如果列表为空,隐藏列表元素?