html - 如何保持两个不同 HTML 元素之间的高度和宽度?

标签 html css responsive-design responsive-images

我想保持我的 img 的高度元素与 input仅使用 CSS 和 html 的元素。任何指导将不胜感激我对这些东西很陌生。 以下是部分代码

<!-- 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 comments are 中的评论,而不是 <-- comment --!>)

<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>

我很高兴看到社区有新成员

关于html - 如何保持两个不同 HTML 元素之间的高度和宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51344526/

相关文章:

使用 z-index 属性显示和隐藏 div 的 javascript 代码

css - 如何在不使用内容容器的情况下在 Bulma 中的标题前创建间距

html - 页脚移动到页面顶部?

css - Vue-Bootstrap b-select 选项悬停

jquery - 使用 jquery 的响应式导航栏

flutter - 如何在 Flutter 应用程序中创建响应式网格?

javascript - Jquery attr() - Mozilla 在设计方面表现不同(不同的字体系列或字体大小?)

html - CSS:在绝对div中嵌套绝对div?

html - Django:在现有的 html 页面上返回 StreamingHttpResponse

css - 内联 svg 缩放 - 自动宽度