gpt4 book ai didi

html - 如何制作带有可点击表单的标题?

转载 作者:太空宇宙 更新时间:2023-11-04 07:55:10 28 4
gpt4 key购买 nike

我正在尝试制作一个标题,其中包含一个标题(标签“手动控制”)和一个可点击的红色表单或按钮(“返回”),它们是内联的(宽度比例:75% 到 25%)。页面总宽度不超过420px。

这应该是这样的:

enter image description here

我用周围的 <div class='heading'> 试了一下标记和以下 CSS 代码:

.heading {
width: 100%;
}
.heading div, form {
float: left;
clear: none;
}

但这最终看起来像这样:

enter image description here

底部的 slider 也太窄了。它们应该从左向右展开,并依次排列(如第一张图片所示)。

这是我的 JSFiddle:https://jsfiddle.net/salocinx/rub5jLhn/

要求:

  • 整个页面宽度最大为 420 像素
  • 内联标题(“手动控制”和“返回”)
  • 剩余页面为“ block ”
  • slider 全长页面

HTML:

<!DOCTYPE html>
<html lang='en'>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'/>
<title>Menu Test</title>
<link href='style.css' rel='stylesheet' type='text/css'>
<script src='websocket.js' type='text/javascript'></script>
</head>
<body>
<div class='frame'>
<div class='heading'>
<div class='title'>
Manual Control
</div>
<form method='post' action='/' class='back'>
Back
</form>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.</p>
</div>
<div class='title'>
Gadget
</div>
<div>
<input class='enabled_red' id='r0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
<input class='enabled_green' id='g0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
<input class='enabled_blue' id='b0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
</div>
</div>
</body>
</html>

CSS:

body {
text-align: center;
font-family: verdana;
}
p {
font-size: 1em;
text-align: center;
}
div {
font-size:1em;
border-radius: 0.2rem;
box-sizing: border-box;
}
div.frame {
max-width: 420px;
margin: auto;
color: #444;
text-align: left;
border-style: solid;
border-width: 1px;
border-color: #d1d1d1;
display: block;
}
.heading {
width: 100%;
}
.heading div, form {
float: left;
clear: none;
}
div.title {
border: 0;
font-size:1.25em;
font-weight: bold;
text-align: center;
color: white;
background-color: #4C6DAF;
padding: 18px;
}
form.back {
border: 0;
border-radius: 0.2rem;
font-size:1.25em;
font-weight: bold;
text-align: center;
color: white;
background-color: #CB4C4C;
cursor: pointer;
padding: 18px;
}
div.logo {
border: 0;
text-align: center;
padding: 24px;
}
/*input {
width:100%;
font-size:1em;
border-style: solid;
border-width: 1px;
border-radius: 0.2rem;
border-color: #d1d1d1;
margin: 12px 0px;
padding: 12px 0px 12px 12px;
box-sizing: border-box;
display: block;
} */
button {
width: 100%;
border: 0;
color: white;
border-radius: 0.2rem;
line-height: 2.4rem;
font-size: 1.2rem;
cursor: pointer;
padding: 12px 0px;
}
button:hover {
opacity: 0.75;
}
form.back:hover {
opacity: 0.75;
}

/* ___________________________________ COLOURS __________________________________ */

.red {
background-color: #CB4C4C;
}
.green {
background-color: #4DB248;
}
.blue {
background-color: #5591E3;
}

/* ____________________________________ SLIDER ___________________________________ */

input[type=range] {
-webkit-appearance: none;
border: 0px;
outline: none;
padding: 16px 16px;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: 0px;
height: 36px;
width: 36px;
margin-top: -16px;
border-radius: 5px;
cursor: pointer;
}
input.enabled_red[type=range]::-webkit-slider-thumb {
background: #CB4C4C;
cursor: pointer;
}
input.enabled_green[type=range]::-webkit-slider-thumb {
background: #4DB248;
cursor: pointer;
}
input.enabled_blue[type=range]::-webkit-slider-thumb {
background: #5591E3;
cursor: pointer;
}
input.disabled[type=range]::-webkit-slider-thumb {
background: #999999;
}
input[type=range]::-webkit-slider-runnable-track {
width: inherit;
height: 4px;
border-radius: 1px;
background: #CCCCCC;
}
input.enabled[type=range]::-webkit-slider-runnable-track {
cursor: pointer;
}

尝试了很多不同的方法,但我真的很不走运。有人能给我指出正确的方向吗?

最佳答案

您正在使用一些不必要的 float 。您可以像这样使用 flex 作为标题:

.heading {
width: 100%;
display: flex;
}

.heading>div {
flex: 4;
}
.heading>form {
flex: 1;
}

还将输入范围包装在容器中并像这样使用 flex :

.container-input {
display:flex;
flex-direction:column;
}

完整代码:

body {
text-align: center;
font-family: verdana;
}

p {
font-size: 1em;
text-align: center;
}

div {
font-size: 1em;
border-radius: 0.2rem;
box-sizing: border-box;
}

div.frame {
max-width: 420px;
margin: auto;
color: #444;
text-align: left;
border-style: solid;
border-width: 1px;
border-color: #d1d1d1;
display: inline-block;
}

.heading {
width: 100%;
display: flex;
}

.heading>div {
flex: 4;
}
.heading>form {
flex: 1;
}

div.title {
border: 0;
font-size: 1.25em;
font-weight: bold;
text-align: center;
color: white;
background-color: #4C6DAF;
padding: 18px;
}

form.back {
border: 0;
border-radius: 0.2rem;
font-size: 1.25em;
font-weight: bold;
text-align: center;
color: white;
background-color: #CB4C4C;
cursor: pointer;
padding: 18px;
}

div.logo {
border: 0;
text-align: center;
padding: 24px;
}

.container-input {
display: flex;
flex-direction: column;
padding:10px 0;
}

button {
width: 100%;
border: 0;
color: white;
border-radius: 0.2rem;
line-height: 2.4rem;
font-size: 1.2rem;
cursor: pointer;
padding: 12px 0px;
}

button:hover {
opacity: 0.75;
}

form.back:hover {
opacity: 0.75;
}


/* ___________________________________ COLOURS __________________________________ */

.red {
background-color: #CB4C4C;
}

.green {
background-color: #4DB248;
}

.blue {
background-color: #5591E3;
}


/* ____________________________________ SLIDER ___________________________________ */

input[type=range] {
-webkit-appearance: none;
border: 0px;
outline: none;
padding: 16px 16px;
}

input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: 0px;
height: 36px;
width: 36px;
margin-top: -16px;
border-radius: 5px;
cursor: pointer;
}

input.enabled_red[type=range]::-webkit-slider-thumb {
background: #CB4C4C;
cursor: pointer;
}

input.enabled_green[type=range]::-webkit-slider-thumb {
background: #4DB248;
cursor: pointer;
}

input.enabled_blue[type=range]::-webkit-slider-thumb {
background: #5591E3;
cursor: pointer;
}

input.disabled[type=range]::-webkit-slider-thumb {
background: #999999;
}

input[type=range]::-webkit-slider-runnable-track {
width: inherit;
height: 4px;
border-radius: 1px;
background: #CCCCCC;
}

input.enabled[type=range]::-webkit-slider-runnable-track {
cursor: pointer;
}
<body>
<div class='frame'>
<div class='heading'>
<div class='title'>
Manual Control
</div>
<form method='post' action='/' class='back'>
Back
</form>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.</p>
</div>
<div class='title'>
Gadget
</div>
<div class='container-input'>
<input class='enabled_red' id='r0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
<input class='enabled_green' id='g0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
<input class='enabled_blue' id='b0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
</div>

</div>
</body>

</html>

关于html - 如何制作带有可点击表单的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47398066/

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