是否可以在画布标签中获取DOM的所有同级元素(图像,按钮,链接等)以适合浏览器的个人大小?我将展示一个简单的例子。
.bl_game__bigScreen {
position: relative;
display: block;
width: 100%;
min-height: 480px;
background-color: #000;
vertical-align: top;
}
.bl_game__wrapper {
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 100vw;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex-wrap: wrap;
color: #fff;
z-index: 2;
}
.bl_game__img {
margin-right: 4vw;
}
.bl_game__nav {
width: 100%;
max-width: 600px;
}
.gamePage_title {
position: relative;
display: initial;
max-width: 550px;
line-height: normal;
font-size: 48px;
text-transform: uppercase;
color: #FFF;
text-shadow: 0 8px 12px rgba(0, 0, 0, 0.36);
}
.bl_game__desc {
position: relative;
display: block;
margin-top: 24px;
max-height: 140px;
overflow-y: auto;
line-height: 23px;
font-size: 16px;
letter-spacing: 0.09em;
text-transform: uppercase;
color: #FFF;
}
.bl_game__buttons {
margin-top: 24px;
}
.btn_playGame {
width: 184px;
height: 56px;
background-color: #000;
border-radius: 44px;
margin-right: 24px;
line-height: 23px;
font-size: 16px;
text-align: center;
font-weight: 600;
cursor: pointer;
color: #fff;
outline: none;
transition: .15s all;
}
.btn_watchVideo {
width: 184px;
height: 56px;
background: #FFF;
border-radius: 44px;
cursor: pointer;
line-height: 23px;
font-size: 16px;
text-align: center;
font-weight: 600;
color: #000;
outline: none;
transition: .2s all;
}
<div class="bl_game">
<img class="bl_game__bigScreen" src="https://baconmockup.com/1600/512" alt="mainImage-slot">
<div class="bl_game__wrapper">
<img class="bl_game__img" src="https://placekitten.com/302/250
" alt="gameLogo">
<div class="bl_game__nav">
<h1 class="gamePage_title">Game Title</h1>
<div class="bl_game__desc">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum eveniet nesciunt consequuntur distinctio neque esse, ut dolor illum cupiditate. Veniam.</div>
<div class="bl_game__buttons">
<button class="btn_playGame" data-href="" type="button">Run Demo</button>
<button class="btn_watchVideo" data-href="" type="button">Play Video</button>
</div>
</div>
</div>
<canvas id="canvas"></canvas>
</div>