gpt4 book ai didi

html - 如何将按钮与 html 和 css 对齐?

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

我写了一个包含一些按钮的小 html 页面。我想要做的是让它们看起来像这样:

enter image description here我一点也不擅长 css,我尝试了一些组合,但我得到的是让它们像这样“在蓝线以下”:

enter image description here这是我的 html 代码:

  <div class="module form-module">
<div class="flex-container">
<article class="article">
<table>
<tr>
<td>
<button>Configurations</button>
</td>
<td>
<button>Create User </button>
</td>
<td>
<button>Update User</button>
</td>
<td>
<button>Create Group</button>
</td>
<td>
<button>Update Group</button>
</td>
</tr>
</table>
</article>
</div>
</div>

你可以在那个 plunker 中找到我的 css 代码:https://plnkr.co/edit/sCcBBFfWRiCwGz8hs8oR?p=catalogue

你能帮我解决这个 html 中的小问题吗?

最佳答案

CSS 更改:

.form-module {
border-bottom: 5px solid #33b5e5;
position: relative;
background: #ffffff;

width: 100%;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
margin: 0 auto;
align: right;
}

.flex-container > * {
padding: 15px;
-webkit-flex: 1 100%;
flex: 1 100%;
}

table {
border-spacing:0px;
}

td {
padding:0px;
}

解释的变化:

蓝线是边框,设置在按钮的父容器上。当您希望它位于底部时,它已设置为顶部,因此这是第一个更改。

然后你有填充,它将按钮与容器的边缘分开,这是第二个变化,将它设置为 0px。

最后,表格和每个按钮都有一个 1px 的边框,将它与容器的边缘分开,第三个更改是将这些边框设置为 0px。

小建议:

如果您不知道:使用浏览器检查器确实有助于更好地了解 CSS 的运行情况。此外,如果您不想从头开始制作所有内容,我建议您看看 Bootstrap,它非常简单,可能会为您节省大量时间。

祝你好运。

如果它有用,这里是完整的 CSS:

body {
background: #e9e9e9;
color: #666666;
font-family: 'RobotoDraft', 'Roboto', sans-serif;
font-size: 14px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

table {
border-spacing:0px;
}

td {
padding:0px;
}

/* Pen Title */
.pen-title {
padding: 50px 0;
text-align: center;
letter-spacing: 2px;
}
.pen-title h1 {
margin: 0 0 20px;
font-size: 48px;
font-weight: 300;
}
.pen-title span {
font-size: 12px;
}
.pen-title span .fa {
color: #33b5e5;
}
.pen-title span a {
color: #33b5e5;
font-weight: 600;
text-decoration: none;
}



/* Form Module */
.form-module {
position: relative;
background: #ffffff;

width: 100%;
border-bottom: 5px solid #33b5e5;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
margin: 0 auto;
align: right;
}
.form-module .toggle {
cursor: pointer;
position: absolute;
top: -0;
right: -0;
background: #33b5e5;
width: 30px;
height: 30px;
margin: -5px 0 0;
color: #ffffff;
font-size: 12px;
line-height: 30px;
text-align: center;
}
.form-module .toggle .tooltip {
position: absolute;
top: 5px;
right: -65px;
display: block;
background: rgba(0, 0, 0, 0.6);
width: auto;
padding: 5px;
font-size: 10px;
line-height: 1;
text-transform: uppercase;
}
.form-module .toggle .tooltip:before {
content: '';
position: absolute;
top: 5px;
left: -5px;
display: block;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-right: 5px solid rgba(0, 0, 0, 0.6);
}
.form-module .form {
display: none;
padding: 40px;
}
.form-module .form:nth-child(2) {
display: block;
}
.form-module h2 {
margin: 0 0 20px;
color: #33b5e5;
font-size: 18px;
font-weight: 400;
line-height: 1;
}

.form-module table {
width: 100%
}





.form-module input {
outline: none;

width: 80%;
border: 1px solid #d9d9d9;

padding: 10px 15px;


font-weight: 400;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.form-module input:focus {
border: 1px solid #33b5e5;
color: #333333;
}
.form-module button {
cursor: pointer;
background: #33b5e5;
width: 90%;

border: 0;
padding: 10px 15px;
color: #ffffff;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.form-module button:hover {
background: #178ab4;
}

.form-module select {
cursor: pointer;

width: 85%;
height:80%;


padding: 10px 15px;

-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}

.flag button {
background: white;
color: #178ab4;
}

.flag button:hover {
background: white;
border: 20px;
border-color: #178ab4;
}

.flag {
cursor: pointer;
background: white;
width: 100%;
border: 0;
padding: 10px 15px;
border-color: #178ab4;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;

}

.flag a {
cursor: pointer;
background: white;
width: 100%;
border: 0;
color: #33b5e5;
border-color: #178ab4;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;

}

.flag a :hover {
background: white;

}

.form-module .cta {
background: #f2f2f2;
width: 100%;
padding: 15px 40px;
box-sizing: border-box;
color: #666666;
font-size: 12px;
text-align: center;
}
.form-module .cta a {
color: #333333;
text-decoration: none;
}



.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
align: right;
}

.flex-container > * {
padding: 0px;
-webkit-flex: 1 100%;
flex: 1 100%;
}


.article {
text-align: left;
}

.detail button {
width: 120px
}

.detail table {
border-collapse: separate;
border-spacing: 5px 10px;
width: 100%
}


.search table {

border-collapse: separate;
border-spacing: 5px 10px;
width: 70%
}

.search button {
width: 120px
}

.search input {
outline: none;

width: 90%;
border: 1px solid #d9d9d9;

padding: 10px 15px;


font-weight: 400;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}

.search select {
cursor: pointer;

width: 90%;
padding: 10px 15px;

-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}

.resultSearch table {

border-collapse: separate;
border-spacing: 5px 10px;
width: 80%
}



.dropbtn {
outline: none;
border:1;
width: 80%;
border: 1px solid #d9d9d9;

padding: 10px 15px;

font-size: 16px;
cursor: pointer;
}

.dropbtn:hover, .dropbtn:focus {
}
#myInput {
border-box: box-sizing;
background-image: url('searchicon.png');
background-position: 14px 12px;
background-repeat: no-repeat;
font-size: 16px;

outline: none;

width: 100%;
border: 1px solid #d9d9d9;

padding: 10px 15px;

}

.dropdown {
position: relative;
display: inline-block;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f6f6f6;
min-width: 230px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

.dropdown a:hover {background-color: #ddd}

.show {display:block;}

#searchbox
{
width: 35px;
}
@media all and (min-width: 768px) {
.nav {text-align:left;-webkit-flex: 1 auto;flex:1 auto;-webkit-order:1;order:1;}
.article {-webkit-flex:5 0px;flex:5 0px;-webkit-order:2;order:2;}
footer {-webkit-order:3;order:3;}
}


.newUser button {
width: 120px

}

.newUser table {
border-collapse: separate;
border-spacing: 5px 10px;
width: 90%
}

.return table{
border-collapse: separate;
border-spacing: 5px 10px;
width: 90%;


}

.returnCheckBox input {

align: left;
width:0%;

}
.invoiceListTable table {
border-collapse: separate;
border-spacing: 5px 10px;
width: 90%
}

.sessionInfo table {
border-collapse: separate;
border-spacing: 5px 10px;
width: 100%;
align: right;

}

.sessionInfo {
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
align: right;
}

.sessionInfo > * {
padding: 15px;
-webkit-flex: 1 100%;
flex: 1 100%;
align: right;

}


.sessionInfo {
position: relative;
background: #ffffff;

width: 20%;
border-top: 5px solid #33b5e5;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
margin: 0 auto;
align: right;
}
.sessionInfo .toggle {
cursor: pointer;
position: absolute;
top: -0;
right: -0;
background: #33b5e5;
width: 30px;
height: 30px;
margin: -5px 0 0;
color: #ffffff;
font-size: 12px;
line-height: 30px;
text-align: center;
}
.sessionInfo .toggle .tooltip {
position: absolute;
top: 5px;
right: -65px;
display: block;
background: rgba(0, 0, 0, 0.6);
width: auto;
padding: 5px;
font-size: 10px;
line-height: 1;
text-transform: uppercase;
}
.sessionInfo .toggle .tooltip:before {
content: '';
position: absolute;
top: 5px;
left: -5px;
display: block;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-right: 5px solid rgba(0, 0, 0, 0.6);
}
.form-module .form {
display: none;
padding: 40px;
align:right;
}

更新:您提到按钮应该位于表单模块的外部和上方,因此需要更改 html 而不仅仅是 css。我们删除了嵌套在 form-module div 中的 flex-container div,并将其放置在该容器关闭之后。由于按钮从 .form-module 的样式中获取它们的布局属性,因此有必要创建一个新类“按钮”。基本上现在表单模块和按钮位于不同的容器中,并且具有独立的样式属性。

要了解容器 block 的工作原理: http://www.w3schools.com/html/html_blocks.asp

html:

<div class="flex-container buttons">
<article class="article">
<table>
<tr>
<td>
<button>Configurations</button>
</td>
<td>
<button>Create User </button>
</td>
<td>
<button>Update User</button>
</td>
<td>
<button>Create Group</button>
</td>
<td>
<button>Update Group</button>
</td>
</tr>
</table>
</article>
</div>
<div class="module form-module">
</div>

更改了 CSS:

body {
background: #e9e9e9;
color: #666666;
font-family: 'RobotoDraft', 'Roboto', sans-serif;
font-size: 14px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

.buttons table {
width: 100%;
border-spacing:0px;
}

.buttons td {
padding:0px;
}

.buttons input {
outline: none;

width: 80%;
border: 1px solid #d9d9d9;

padding: 10px 15px;


font-weight: 400;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.buttons input:focus {
border: 1px solid #33b5e5;
color: #333333;
}
.buttons button {
cursor: pointer;
background: #33b5e5;
width: 90%;

border: 0;
padding: 10px 15px;
color: #ffffff;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.buttons button:hover {
background: #178ab4;
}

.buttons select {
cursor: pointer;

width: 85%;
height:80%;


padding: 10px 15px;

-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}

完整的 CSS:

body {
background: #e9e9e9;
color: #666666;
font-family: 'RobotoDraft', 'Roboto', sans-serif;
font-size: 14px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

.buttons table {
width: 100%;
border-spacing:0px;
}

.buttons td {
padding:0px;
}

.buttons input {
outline: none;

width: 80%;
border: 1px solid #d9d9d9;

padding: 10px 15px;


font-weight: 400;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.buttons input:focus {
border: 1px solid #33b5e5;
color: #333333;
}
.buttons button {
cursor: pointer;
background: #33b5e5;
width: 90%;

border: 0;
padding: 10px 15px;
color: #ffffff;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.buttons button:hover {
background: #178ab4;
}

.buttons select {
cursor: pointer;

width: 85%;
height:80%;


padding: 10px 15px;

-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}

/* Pen Title */
.pen-title {
padding: 50px 0;
text-align: center;
letter-spacing: 2px;
}
.pen-title h1 {
margin: 0 0 20px;
font-size: 48px;
font-weight: 300;
}
.pen-title span {
font-size: 12px;
}
.pen-title span .fa {
color: #33b5e5;
}
.pen-title span a {
color: #33b5e5;
font-weight: 600;
text-decoration: none;
}



/* Form Module */
.form-module {
position: relative;
background: #ffffff;

width: 100%;
border-top: 5px solid #33b5e5;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
margin: 0 auto;
align: right;
}

.form-module .toggle {
cursor: pointer;
position: absolute;
top: -0;
right: -0;
background: #33b5e5;
width: 30px;
height: 30px;
margin: -5px 0 0;
color: #ffffff;
font-size: 12px;
line-height: 30px;
text-align: center;
}
.form-module .toggle .tooltip {
position: absolute;
top: 5px;
right: -65px;
display: block;
background: rgba(0, 0, 0, 0.6);
width: auto;
padding: 5px;
font-size: 10px;
line-height: 1;
text-transform: uppercase;
}
.form-module .toggle .tooltip:before {
content: '';
position: absolute;
top: 5px;
left: -5px;
display: block;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-right: 5px solid rgba(0, 0, 0, 0.6);
}
.form-module .form {
display: none;
padding: 40px;
}
.form-module .form:nth-child(2) {
display: block;
}
.form-module h2 {
margin: 0 0 20px;
color: #33b5e5;
font-size: 18px;
font-weight: 400;
line-height: 1;
}

.form-module table {
width: 100%
}





.form-module input {
outline: none;

width: 80%;
border: 1px solid #d9d9d9;

padding: 10px 15px;


font-weight: 400;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.form-module input:focus {
border: 1px solid #33b5e5;
color: #333333;
}
.form-module button {
cursor: pointer;
background: #33b5e5;
width: 90%;

border: 0;
padding: 10px 15px;
color: #ffffff;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.form-module button:hover {
background: #178ab4;
}

.form-module select {
cursor: pointer;

width: 85%;
height:80%;


padding: 10px 15px;

-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}

.flag button {
background: white;
color: #178ab4;
}

.flag button:hover {
background: white;
border: 20px;
border-color: #178ab4;
}

.flag {
cursor: pointer;
background: white;
width: 100%;
border: 0;
padding: 10px 15px;
border-color: #178ab4;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;

}

.flag a {
cursor: pointer;
background: white;
width: 100%;
border: 0;
color: #33b5e5;
border-color: #178ab4;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;

}

.flag a :hover {
background: white;

}

.form-module .cta {
background: #f2f2f2;
width: 100%;
padding: 15px 40px;
box-sizing: border-box;
color: #666666;
font-size: 12px;
text-align: center;
}
.form-module .cta a {
color: #333333;
text-decoration: none;
}



.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
align: right;
}

.flex-container > * {
padding: 0px;
-webkit-flex: 1 100%;
flex: 1 100%;
}


.dropbtn {
outline: none;
border:1;
width: 80%;
border: 1px solid #d9d9d9;

padding: 10px 15px;

font-size: 16px;
cursor: pointer;
}

.dropbtn:hover, .dropbtn:focus {
}


.dropdown {
position: relative;
display: inline-block;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f6f6f6;
min-width: 230px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

.dropdown a:hover {background-color: #ddd}

.show {display:block;}

ul{
list-style-type:none;
width:500px;
}

li{
width:33%;
text-align:center;
float:left;
border-bottom:2px solid #33b5e5;
}

关于html - 如何将按钮与 html 和 css 对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41871318/

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