html5动态切换class,HTML5 网格/列表展示模式动态切换

CSS

语言:

CSSSCSS

确定

body {

background: #5298fc;

text-align: center;

font-family: "Open Sans", sans-serif;

}

#view-code {

color: #fff;

opacity: 0.7;

font-size: 14px;

text-transform: uppercase;

font-weight: 700;

text-decoration: none;

position: absolute;

top: 700px;

left: 50%;

margin-left: -35px;

}

#view-code:hover {

opacity: 1;

}

#window {

margin: 30px auto 0;

border-radius: 6px;

background: #fff;

width: 675px;

height: 620px;

overflow: hidden;

position: relative;

}

#header {

background: #e3e5e9;

height: 33px;

padding-left: 18px;

}

#header .circle {

background: #9fa2a8;

border-radius: 50%;

float: left;

width: 12px;

height: 12px;

margin-right: 6px;

margin-top: 11px;

}

.thumbs {

padding: 10px 50px 30px 70px;

}

.thumbs p,

.thumbs p.floating-thumb {

background: #e3e5e9;

width: 155px;

height: 60px;

margin: 30px 30px 0 0;

border-radius: 4px;

float: left;

padding-top: 121px;

}

.floating-thumb {

background: #e3e5e9;

width: 155px;

height: 60px;

border-radius: 4px;

float: left;

padding-top: 121px;

position: absolute;

top: 156px;

left: 70px;

}

.floating-thumb.animate {

width: 303px;

height: 80px;

margin-top: 20px;

padding-top: 326px;

top: 146px;

left: 186px;

-webkit-transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99);

-moz-transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99);

-ms-transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99);

-o-transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99);

transition: all 400mscubic-bezier(0, 0.93, 0.33, 0.99);

}

.thumbs p span,

p.floating-thumb span {

display: block;

height: 10px;

margin: 10px 20px;

background: #d2d4d9;

border-radius: 2px;

}

.thumbs p span.short,

p.floating-thumb span.short {

width: 50px;

}

.thumbs p:hover {

background: #dfe0e5;

cursor: pointer;

-webkit-transition: all 100ms ease-out;

-moz-transition: all 100ms ease-out;

-ms-transition: all 100ms ease-out;

-o-transition: all 100ms ease-out;

transition: all 100ms ease-out;

}

#headline {

padding: 39px 50px 0px 70px;

}

#headline p {

width: 380px;

margin: 10px 0;

height: 15px;

background: #9fa2a8;

border-radius: 3px;

}

#headline p.short {

width: 220px;

}

#grid-selector {

width: 100px;

position: absolute;

top: 92px;

right: 79px;

}

#viewCarousel {

background: #e3e5e9;

width: 20px;

height: 20px;

float: right;

border-radius: 1px;

}

#viewCarousel:hover {

cursor: pointer;

}

#viewCarousel:hover,

#viewGrid:hover p {

cursor: pointer;

background: #cacdd1;

}

#viewCarousel.active,

#viewGrid.active p {

color: #5298fc;

}

#viewGrid {

width: 22px;

height: 20px;

float: right;

margin-top: -1px;

margin-right: 5px;

}

#viewGrid p {

background: #e3e5e9;

width: 9px;

height: 9px;

float: right;

border-radius: 1px;

margin: 1px;

}

#viewGrid.active p,

#viewCarousel.active {

background: #9fa2a8;

}

#carousel {

overflow: hidden;

position: relative;

height: 488px;

margin-top: 25px;

display: none;

position: absolute;

top: 121px;

left: 0;

width: 675px;

}

#carousel .innerCarousel {

position: absolute;

top: 0;

left: -168px;

}

#carousel .innerCarousel div {

width: 337px;

height: 448px;

text-align: center;

float: left;

}

#carousel .innerCarousel div p {

background: #e3e5e9;

width: 220px;

height: 73px;

margin: 30px auto 0 auto;

border-radius: 4px;

padding-top: 300px;

margin-top: 38px;

-webkit-transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

-moz-transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

-ms-transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

-o-transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

}

#carousel .innerCarousel div p:hover {

cursor: pointer;

}

#carousel .innerCarousel div p.current:hover {

cursor: normal;

}

#carousel .innerCarousel div p.current {

width: 303px;

height: 80px;

margin-top: 20px;

padding-top: 326px;

-webkit-transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

-moz-transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

-ms-transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

-o-transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

transition: all 300ms cubic-bezier(0, 0.93, 0.33, 0.99);

}

#carousel .innerCarousel span,

p.floating-thumb.animate span {

height: 10px;

display: block;

margin: 10px 30px;

height: 12px;

background: #d2d4d9;

border-radius: 3px;

}

#carousel .innerCarousel span.short,

p.floating-thumb.animate span.short {

width: 170px;

}

.title {

position: absolute;

top: 152px;

left: 0;

width: 100%;

height: 60px;

overflow: hidden;

-webkit-transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99) 120ms;

-moz-transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99) 120ms;

-ms-transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99) 120ms;

-o-transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99) 120ms;

transition: all 400ms cubic-bezier(0, 0.93, 0.33, 0.99) 120ms;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
井字游戏可以使用HTML、CSS和JavaScript来实现。下面是一个简单的HTML代码示例,用于构建井字游戏界面: ```html <!DOCTYPE html> <html> <head> <title>井字游戏</title> <style> .board { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 2px; width: 300px; height: 300px; margin: 0 auto; } .cell { background-color: #eee; display: flex; align-items: center; justify-content: center; font-size: 48px; cursor: pointer; } .cell:hover { background-color: #ddd; } .cell.x { color: #f00; } .cell.o { color: #00f; } </style> </head> <body> <div class="board"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <script> const cells = document.querySelectorAll('.cell'); let currentPlayer = 'x'; cells.forEach(cell => { cell.addEventListener('click', () => { if (!cell.textContent) { cell.textContent = currentPlayer; cell.classList.add(currentPlayer); currentPlayer = currentPlayer === 'x' ? 'o' : 'x'; } }); }); </script> </body> </html> ``` 这段代码使用CSS的网格布局来创建一个3x3的格子,每个格子都是一个可点击的div元素。点击格子时,会在格子内显示当前玩家的标记('x'或'o'),并且为该格子添加对应的类名,以便通过CSS样式设置不同的颜色。JavaScript部分负责处理点击事件,切换玩家标记。你可以将这段代码保存为一个HTML文件,用浏览器打开即可看到井字游戏界面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值