html - 如何保持两个不同 HTML 元素之间的高度和宽度?
问题描述
我想用仅使用 CSS 和 htmlimg
的元素来保持元素的高度。input
任何指导将不胜感激我对这些事情很陌生。以下是部分代码
<!-- Main section of the html part-->
<main>
<!-- Division with Search Bar as an input element and the svg as an image-->
<div class="searchDiv">
<!-- A label -->
<label class="searchBar" id="search">Taste of home right at your finger tips <br> </label>
<!-- Search Bar -->
<input type="text" id="searchBar1" class="searchBar">
<!-- SVG image-->
<img id="searchBtn" src="css/SVGS/magnifying-glass.svg">
</div>
</main>
我也尝试过<object>
标签,但它不起作用。这是CSS部分
#searchBar1 {
float:left;
box-sizing: border-box;
margin: 4% auto auto 26%;
padding:0.99% 22% 0.4% 1%;
border: solid thin rgba(74, 87, 98, 0.61);
border:none;
border-right:none;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2), 0 1px 2px 0 rgba(0, 0, 0, 0.19);
}
@media screen and (min-width: 1200px) {
#searchBar1 {
margin: 4% auto auto 31%;
}
}
#searchBtn {
width: 3.45%;
margin-bottom: 0.2%;
float:left;
border: none;
box-sizing: border-box;
background-color: white;
margin-top: 4%;
padding: 1% 1% 1.1% 1%;
border-left:dashed thin rgba(74, 87, 98, 0.61);
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2), 0 1px 2px 0 rgba(0, 0, 0, 0.19);
}
解决方案
问题在于您的填充和边距,删除它们并写入高度和宽度的值应该可以解决它。这是我的代码(我还更正了您在 html 注释中的注释,而不是 <-- 注释 --!>)
<style>
#searchBar1 {
width: 3.45%;
height: 3.45%;
float:left;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2), 0 1px 2px 0 rgba(0, 0, 0, 0.19);
}
#searchBtn {
height: 3.45%;
width: 3.45%;
float:left;
border: none;
background-color: white;
}
</style>
<main>
<!-- Division with Search Bar as an input element and the svg as an image-->
<div class="searchDiv">
<!-- A label -->
<label class="searchBar" id="search">Taste of home right at your finger tips <br> </label>
<!-- Search Bar -->
<input type="text" id="searchBar1" class="searchBar">
<!-- SVG image-->
<img id="searchBtn" src="css/SVGS/magnifying-glass.svg">
</div>
</main>
我很高兴看到社区的新成员
推荐阅读
- javascript - 如何在不使用的情况下创建 SVG 模态弹出窗口容纳模态文本的容器
- c# - 如何在 Azure 中每月运行一次控制台应用程序
- file-upload - 在 Blazor Server 中使用 EditForm 上传文件?
- c++11 - 如果 constexpr 函数未在编译时运行,如何调试?
- python - “value_counts()”和“agg('count')”返回不同的结果
- python - 多标签分类实现
- javascript - 无法读取未定义的属性“发送”
- c# - 如何绘制宽度小于高度的圆角矩形?C#
- angular - 模板形式 angular 结合 *ngFor
- google-cloud-data-fusion - 数据融合:GCS 创建创建文件夹而不是对象