gpt4 book ai didi

javascript - 在 CSS 和 HTML5 中对齐正方形内的四个圆圈

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

我正在开发一个 Simon Says 游戏,并且拥有所有可用的 JavaScript 等。

我遇到的主要问题是 CSS;单击它时一切正常,

这是我希望它看起来像的模拟图像:

enter image description here

更新仍然有对齐问题更新了我的 CSS

enter image description here

CSS:

body {
background-color: #333;
color: #fff;
}

ul {
list-style: none;
margin: 0 0 20px 0;
padding: 0;
text-align: center;
}

li {
display: inline-block;
padding: 3px;
}

.wrapper {
position: relative;
width: 640px;
margin: 0 auto;
}

.back {
width:700px;
height:700px;
background-color:black;
}

.pad {
width: 200px;
height: 200px;
z-index: 1;
margin: 10px;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=60)";
filter: alpha(opacity=60);
opacity: 0.6;
}

.shape1 {
position: absolute;
left: 0;
top: 50%;
margin-top: -300px;
width: 100px;
height: 100px;
background-color: green;
border-radius: 50%;
}

.shape2 {
position: absolute;
left: 50%;
margin-left: -50px;
width: 100px;
height: 100px;
background-color: red;
border-radius: 50%;
}

.shape3 {
position: absolute;
left: 0;
right: 50%;
margin-right: -50px;
width: 100px;
height: 100px;
background-color: yellow;
border-radius: 50%;
}

.shape4 {
position: absolute;
left: 0;
bottom: 50%;
margin-bottom: -50px;
width: 100px;
height: 100px;
background-color: blue;
border-radius: 50%;
}

.level, .score {
width: 50%;
float: left;
text-align: center;
}

.sButton {
width: 30%;
margin: 0 auto;
}

.start {
width: 100%;
height: 30px;
text-align: center;
}

HTML:

<body>
<div class="wrapper">
<div class="back">
<div class="pad shape1" data-pad="1">
<audio preload="auto" class="sound1">
<source src="sounds/mp3/sounds_01.mp3" type="audio/mpeg"/>
<source src="sounds/ogg/sounds_01.ogg" type="audio/ogg"/>
</audio>
</div>
<div class="pad shape2" data-pad="2">
<audio preload="auto" class="sound2">
<source src="sounds/mp3/sounds_02.mp3" type="audio/mpeg"/>
<source src="sounds/ogg/sounds_02.ogg" type="audio/ogg"/>
</audio>
</div>
<div class="pad shape3" data-pad="3">
<audio preload="auto" class="sound3">
<source src="sounds/mp3/sounds_03.mp3" type="audio/mpeg"/>
<source src="sounds/ogg/sounds_03.ogg" type="audio/ogg"/>
</audio>
</div>
<div class="pad shape4" data-pad="4">
<audio preload="auto" class="sound4">
<source src="sounds/mp3/sounds_04.mp3" type="audio/mpeg"/>
<source src="sounds/ogg/sounds_04.ogg" type="audio/ogg"/>
</audio>
</div>
<div class="break"></div>
</div>

<div class="level">
<h2>Level: 1</h2>
</div>
<div class="score">
<h2>Score: 0</h2>
</div>

<ul class="difficulty">

<li>
<input type="radio" class="difOpt" name="difficulty" value="2">Easy
</li>
<li>
<input type="radio" class="difOpt" name="difficulty" value="1" checked>Normal
</li>
<li>
<input type="radio" class="difOpt" name="difficulty" value="0.5">Hard
</li>
<li>
<input type="radio" class="difOpt" name="difficulty" value="0.25">Insane
</li>
</ul>
<div class="sButton">
<button class="start">start</button>
</div>
</div>
</body>

最佳答案

你要给你的形状一个绝对位置,并使用“顶部”、“左”、“右”和“底部”CSS 属性,如下所示:

.shape1 {
position: absolute;
left: 0;
top: 50%;
margin-top: -50px;
width: 100px;
height: 100px;
background-color: green;
border-radius: 50%;
}

请注意,margin-top 用于稍微偏移“top”属性。 Border-radius 会将这些变成圆圈。

关于javascript - 在 CSS 和 HTML5 中对齐正方形内的四个圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26264410/

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