我有一个搜索框,它是扩大时激活. 但是,我想使搜索框溢出页面上的其他内容.

搜索框位于Bootstrap列内—如何使其扩展突破?

.search-area {
  transition: all .3s ease-in;
  width: 3rem
}

.search-area:focus-within,
.search-area:hover {
  width: 100%;
}

.page-searchform {
  position: relative
}

.header-search {
  padding-right: 2rem;
  border: 0;
  background-color: #fff;
}

.header-search-btn {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
}


/* Presentation onæly */

.row {
  background: #f8f9fa;
  margin-top: 20px;
}

.col {
  padding: 10px;
  border: 1px solid #ccc;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">

<div class="container">
  <div class="row">
    <div class="col col-10">
      Column 1 - Make search input overflow me!
    </div>
    
    <div class="col d-flex justify-content-end align-self-center">
      <div class="search-area">
        <form class="page-searchform" action="" method="get">
          <label for="headerSearch" class="visually-hidden"></label>
          <input name="" id="headerSearch" class="header-search form-control" type="search" placeholder="Search...">
          
          <button class="btn header-search-btn" type="submit" id="headerSearchBtn">Go
          </button>
        </form>
      </div>
    </div>
  </div>
</div>

JsFiddle here.

推荐答案

试着用position:absoluteright:0

.search-area:hover .header-search{
   transition: all .3s ease-in;
    width: 500px;
}

.header-search {
  padding-right: 2rem;
  border: 0;
  background-color: red;
  position:absolute;
  right:0;
  width: 100px;
}

https://jsfiddle.net/23c94ftw/16/

Css相关问答推荐

CSS Grid,意想不到的差距

Vue3日期 Select 器:禁用向左和向右箭头

我找不出Firefox上奇怪的css行为的原因

为什么 CSS Calc() 函数只需要+或-运算符前后有空格

是否有一个 CSS 可以根据字符的高度 for each 字符呈现可变高度?

Tailwind css break-word 在输入字段中不起作用

如何在 konvajs 中居中放置项目?

为什么每次加载新页面时我的 React 侧边栏都会抖动?

Bootstrap 5 - 更改列顺序时出现问题

在活动状态下更改按钮的外观

圆形加载动画

如何保持包装的弹性项目与前一行元素的宽度相同?

创建 CSS 全局变量:样式表主题管理

为什么是垂直对齐:文本顶部;不能在 CSS 中工作

通过 JavaScript 更改 CSS 伪元素样式

CSS 中的星号属性是什么意思?

CSS停止图像下的文本换行

带有一些 LESS 魔法的花式媒体查询

Rails 中正确的 SCSS assets资源 struct

仅当存在 2 个类时,您可以使用 CSS 定位元素吗?