gpt4 book ai didi

html - 如何让我的元素占用其 "max-width"规范的宽度?

转载 作者:行者123 更新时间:2023-11-28 05:02:41 24 4
gpt4 key购买 nike

我正在尝试使用以下形式在屏幕上对齐输入

<form id="search-form" action="/events/search" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">
<input type="text" name="first_name" id="first_name" value="Dave" placeholder="First Name">
<input type="text" name="last_name" id="last_name" value="" placeholder="Last Name">
<input type="text" name="event" id="event" value="" placeholder="Event">
<input alt="Search" type="image" src="http://www.racertracks.com/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button">
</form>

但是,除非屏幕很小(< 400 像素),否则我不希望事情开始环绕。否则,我希望所有内容都占据我屏幕的 100%,最多 1000 像素。所以我尝试添加这个 CSS

@media (max-width: 1000px) {
#search-form {
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}

#first_name {
width: 50%;
margin: 0;
}

#last_name {
width: calc(50% - 1px);
margin-left: 1px;
}

#first_name, #last_name {
margin-bottom: 1px;
}

#event {
width: calc(100% - 20px);
margin: 0;
}
}

这是说明问题的 Fiddle -- https://jsfiddle.net/7h62z3tw/2/。除非屏幕很小,否则我该如何调整以使所有内容保持在同一条线上?

最佳答案

我想这就是您要找的。我添加了一些额外的 css 以使媒体屏幕 <400px 和普通寡妇看起来都不错。我还在添加和更改的 css 部分注释掉了。 Live ON Fiddle

  /* line 123, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#searchContainer {
padding: 10px;
font-family: "Calibre", "Helvetica Neue", "Helvetica", "Roboto", "Arial", sans-serif;
background-color: tan;

}


/* line 132, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#searchContainer h1 {
margin: 5px 0;
font-size: 1.0em;
text-align: center;
/*just make it for looks good*/
}

#search-form {
display: inline-flex;
/*In screen >400px input element will be inline*/
width: 100%;
}

/* line 137, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#first_name,
#last_name {
width: 40%;
/*make the width like event so all the input fields looks good*/
}

/* line 138, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#event {
width: 100%;
}

/* Do not specify width to allow it to grow freely */


/* line 139, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#last_name,
#event {
margin-left: 1px;
}

@media only screen and (max-width: 400px) {

/*set the max width 400px so they will wrap after the media screen reach 400px*/

#search-form {
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}

/* line 149, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#first_name {
width: 100%; /*Make the this 100% on screen < 400px */
margin: 0;
}

/* line 150, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#last_name {
width: 100%; /*Make the this 100% on screen < 400px */
margin: 0;
/*remove the mergin left 1 and add this */
}

/* line 151, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#first_name,
#last_name {
margin-bottom: 1px;
}

/* line 152, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#event {
width: 85%; /*Make the this 100% on screen < 400px */
margin: 0;
}

}

/* line 158, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#search_form {
display: table-cell;
padding: 0px;
}

/* line 162, /Users/davea/Documents/workspace/runtrax/app/assets/stylesheets/events.css.scss */

#search_form form input {
vertical-align: middle;
}
 

<div id="searchContainer">
<h1>Enter Search Criteria To Lookup Results:</h1>
<form id="search-form" action="/events/search" accept-charset="UTF-8" method="get">
<input name="utf8" type="hidden" value="✓">

<input type="text" name="first_name" id="first_name" value="Dave" placeholder="First Name">
<input type="text" name="last_name" id="last_name" value="" placeholder="Last Name">
<input type="text" name="event" id="event" value="" placeholder="Event">
<input alt="Search" type="image" src="http://www.racertracks.com/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button">
</form>
</div>

关于html - 如何让我的元素占用其 "max-width"规范的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40004114/

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