gpt4 book ai didi

html - 如何使用 justify-content center 在 flexbox div 中将输入拉伸(stretch)到 100%

转载 作者:行者123 更新时间:2023-11-27 23:59:57 26 4
gpt4 key购买 nike

如果不执行类似 width: 150%

的操作,我无法让下面代码片段中的输入拉伸(stretch)到包含按钮的 100%

.explore__column,
.explore__row {
display: flex;
}

.explore__row {
flex-direction: row;
flex: 1 1;
}

.search-box__item {
display: flex;
flex-direction: column;
justify-content: center;
flex: 1 1;
margin-right: 3.75rem!important;
margin-bottom: 3.75rem!important;
width: 0;
border: 1px solid rgba(33, 33, 33, .4);
align-items: center;
border-radius: 5px;
background: transparent;
background: #fff;
cursor: pointer;
}

.search-box__item.search-box__active {
border-top: 2px solid #4f9bc9;
box-shadow: 0 2px 20px 0 rgba(0, 0, 0, .12);
}

.search-box__item {
display: flex;
flex-direction: column;
justify-content: center;
flex: 1 1;
margin-right: 3.75rem!important;
margin-bottom: 3.75rem!important;
width: 0;
border: 1px solid rgba(33, 33, 33, .4);
align-items: center;
border-radius: 5px;
background: transparent;
background: #fff;
cursor: pointer;
}
<div class="explore__row"><button class="search-box__item search-box__active" type="button"><div class="search-box__translate"><svg viewBox="0 0 30 30" style="overflow: visible;"><use xlink:href="#icon-Plan" style="overflow: visible;"></use></svg></div><div class="search-box__fade
"><input type="text" autocomplete="off" class="input__default form-control" placeholder="search Plans"></div><h2>One</h2></button><button class="search-box__item" type="button"><div class="search-box__translate"><svg viewBox="0 0 30 30" style="overflow: visible;"><use xlink:href="#icon-BusinessUnit" style="overflow: visible;"></use></svg></div><div class="search-box__fade"><input type="text" autocomplete="off" class="input__default form-control" placeholder="search Business Units"></div><h2>Two</h2></button>
</div>

最佳答案

  1. 您不能使用 <div>在按钮元素内(为什么首先在这种情况下使用按钮?每当您单击它时,它都会使您的内容摆动)
  2. 只需为输入及其父级添加 100% 的宽度,并添加 box-sizing: border-box为了也考虑填充。

.explore__column,
.explore__row {
display: flex;
}

.explore__row {
flex-direction: row;
flex: 1 1;
}

.search-box__item {
display: flex;
flex-direction: column;
justify-content: center;
flex: 1 1;
margin-right: 3.75rem!important;
margin-bottom: 3.75rem!important;
width: 0;
border: 1px solid rgba(33, 33, 33, .4);
align-items: center;
border-radius: 5px;
background: transparent;
background: #fff;
cursor: pointer;
padding: 0 10px;
}

.search-box__item.search-box__active {
border-top: 2px solid #4f9bc9;
box-shadow: 0 2px 20px 0 rgba(0, 0, 0, .12);
}

.search-box__item {
display: flex;
flex-direction: column;
justify-content: center;
flex: 1 1;
margin-right: 3.75rem!important;
margin-bottom: 3.75rem!important;
width: 0;
border: 1px solid rgba(33, 33, 33, .4);
align-items: center;
border-radius: 5px;
background: transparent;
background: #fff;
cursor: pointer;
}

.search-box__fade,
input {
width: 100%;
box-sizing: border-box;
}
<div class="explore__row">
<div class="search-box__item search-box__active" type="button">
<div class="search-box__translate">
<svg viewBox="0 0 30 30" style="overflow: visible;"><use xlink:href="#icon-Plan" style="overflow: visible;"></use></svg>
</div>
<div class="search-box__fade">
<input type="text" autocomplete="off" class="input__default form-control" placeholder="search Plans"></div>
<h2>One</h2>
</div>
<div class="search-box__item" type="button">
<div class="search-box__translate">
<svg viewBox="0 0 30 30" style="overflow: visible;"><use xlink:href="#icon-BusinessUnit" style="overflow: visible;"></use></svg>
</div>
<div class="search-box__fade">
<input type="text" autocomplete="off" class="input__default form-control" placeholder="search Business Units">
</div>
<h2>Two</h2>
</div>
</div>

关于html - 如何使用 justify-content center 在 flexbox div 中将输入拉伸(stretch)到 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56044385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com