我需要更改绿色按钮在屏幕上的位置。当我创建按钮时,它会自动移到另一个红色按钮下方,并且我希望这些按钮彼此相邻。因为我是一个没有经验的程序员,所以我没有尝试过任何东西,也没有想尝试的东西。我的措辞不佳,我的英语不是很好,我对此表示歉意。帮助将不胜感激。
body {
padding: 50px;
}
.netflix {
color: white;
transition: transform 0.5s;
cursor: pointer;
height: 210px;
width: 400px;
border-style: none;
outline-style: none;
position:relative;
background: red;
/*background-image: url(netflix\ black\ logo.png);
background-size: cover;*/
border-radius: 3px;
}
.netflix:hover {
transform:scale(1.03,1.03);
box-shadow: 0 4px 8px 0 rgba(141, 105, 105, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.hulu {
transition: transform 0.5s;
cursor: pointer;
height: 210px;
width: 400px;
background-image: url(hulu.jpg);
background-size: cover;
border-style: none;
outline-style: none;
background: lightgreen;
}
.hulu:hover {
transform:scale(1.03,1.03);
box-shadow: 0 4px 8px 0 rgba(141, 105, 105, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
/*div {
width: 310px;
height: 169px;
background-image: url(netflix\ black\ logo.png);
background-size: cover;
position: absolute;
top: 4;
/*margin-right: 2px;*/
/*margin-left: 5px;*/
/*align-self: center;
}*/
/*p {
margin-top: 40px;
margin-left: 2px;
margin-right: 2px;
text-align: left;
margin-top: 176px;
color: black;
font-size: 22px;
font-family: Arial, Helvetica, sans-serif;
}*/
<html>
<head>
<title>entertainment</title>
<link rel="stylesheet" href="shop.css">
</head>
<body>
<form action="https://netflix.com/" target="_blank">
<button class="netflix">
<!--div>
</div>
<p>visit netflix and stuff </p-->
</button>
</form>
<form>
<button class="hulu">
</button>
</form>
</body>
</html>
答案 0 :(得分:1)
只需使用Flexbox布局即可对齐元素:
body {
padding: 50px;
display: flex; /* <- It will make children align in the same row */
}
.netflix {
color: white;
transition: transform 0.5s;
cursor: pointer;
height: 210px;
width: 400px;
border-style: none;
outline-style: none;
position:relative;
background: red;
/*background-image: url(netflix\ black\ logo.png);
background-size: cover;*/
border-radius: 3px;
}
.netflix:hover {
transform:scale(1.03,1.03);
box-shadow: 0 4px 8px 0 rgba(141, 105, 105, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.hulu {
transition: transform 0.5s;
cursor: pointer;
height: 210px;
width: 400px;
background-image: url(hulu.jpg);
background-size: cover;
border-style: none;
outline-style: none;
background: lightgreen;
}
.hulu:hover {
transform:scale(1.03,1.03);
box-shadow: 0 4px 8px 0 rgba(141, 105, 105, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<html>
<head>
<title>entertainment</title>
<link rel="stylesheet" href="shop.css">
</head>
<body>
<form action="https://netflix.com/" target="_blank">
<button class="netflix">
<!--div>
</div>
<p>visit netflix and stuff </p-->
</button>
</form>
<form>
<button class="hulu">
</button>
</form>
</body>
</html>
答案 1 :(得分:0)
您可以使用flexbox
flex容器展开项目以填充可用的可用空间,也可以收缩它们以防止溢出。
body {
padding: 50px;
}
.inline {
display: flex;
}
.netflix {
color: white;
transition: transform 0.5s;
cursor: pointer;
height: 210px;
width: 400px;
border-style: none;
outline-style: none;
position:relative;
background: red;
/*background-image: url(netflix\ black\ logo.png);
background-size: cover;*/
border-radius: 3px;
}
.netflix:hover {
transform:scale(1.03,1.03);
box-shadow: 0 4px 8px 0 rgba(141, 105, 105, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.hulu {
transition: transform 0.5s;
cursor: pointer;
height: 210px;
width: 400px;
background-image: url(hulu.jpg);
background-size: cover;
border-style: none;
outline-style: none;
background: lightgreen;
}
.hulu:hover {
transform:scale(1.03,1.03);
box-shadow: 0 4px 8px 0 rgba(141, 105, 105, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
/*div {
width: 310px;
height: 169px;
background-image: url(netflix\ black\ logo.png);
background-size: cover;
position: absolute;
top: 4;
/*margin-right: 2px;*/
/*margin-left: 5px;*/
/*align-self: center;
}*/
/*p {
margin-top: 40px;
margin-left: 2px;
margin-right: 2px;
text-align: left;
margin-top: 176px;
color: black;
font-size: 22px;
font-family: Arial, Helvetica, sans-serif;
}*/
<html>
<head>
<title>entertainment</title>
<link rel="stylesheet" href="shop.css">
</head>
<body>
<div class="inline">
<form action="https://netflix.com/" target="_blank">
<button class="netflix">
<!--div>
</div>
<p>visit netflix and stuff </p-->
</button>
</form>
<form>
<button class="hulu">
</button>
</form>
</div>
</body>
</html>
答案 2 :(得分:0)
尝试将两种形式包装在<div class="button-list">
.button-list {
display: flex;
}
注意:可能有比将每个按钮包装在表单标签中更好的方法。您可以使用隐藏或使用javascript表单提交来为您提供更大的灵活性和更清洁的html。