gpt4 book ai didi

html - CSS 伪选择器 "Blocking"Angular Ng-Click?

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:29 25 4
gpt4 key购买 nike

我有一个 css 表格卡片布局,它使用 :before 伪选择器来插入标题名称。

同样在我的表中,我创建了一个按钮,按下时会触发警报。

问题是按钮在 plunkr 中不起作用:http://plnkr.co/edit/ZKweKp

但是当我去掉 css 时,按钮按预期工作。

这是CSS:

.cards tr:nth-of-type(odd) { 
background: #eee;
}

.cards th {
background: #333;
color: white;
}
.cards td,
.cards th {
padding: 6px;
border: 1px solid #ccc;
text-align: left;
}

/* Force table to not be like tables anymore */
.cards table,
.cards thead,
.cards tbody,
.cards th,
.cards td,
.cards tr {
display: block;
}

/* Hide table headers (but not display: none; for accessibility) */
.cards th {
position: absolute;
top: -9999px;
left: -9999px;
}

.cards tr { border: 1px solid #ccc; }

.cards td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 20%;
}

.cards td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}

.cards td:nth-of-type(1):before { content: "Date"; }
.cards td:nth-of-type(2):before { content: "User"; }

html:

<!DOCTYPE html>
<html ng-app="app">

<head>

<script data-require="angular.js@~1.4.0" data-semver="1.4.0" src="https://code.angularjs.org/1.4.0/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>

<body ng-controller="IndexController">

<table class='cards'>
<tr>
<th>Color</th>
<th>Button</th>
</tr>
<tr ng-repeat="color in pageData.colors">
<td>{{ color }}</td>
<td>
<button ng-click="pageFn.clickMe()">Click Me</button>
</td>
</tr>
</table>

</body>

</html>

还有 JS:

var app = angular.module('app', []);

app.controller('IndexController', function ($scope) {
$scope.pageData ={};
$scope.pageFn = {};

$scope.pageData.colors = ['This is red. etc... ', 'This is green. etc...', 'Blue text here... asdfadsfadsfadsf a'];

$scope.pageFn.clickMe = function () {
console.log('hello');
alert('clicked!');
}

});

最佳答案

只需将 .cards td:before 的 CSS 更改为此,

.cards td:before { 
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: auto;
padding-right: 10px;
white-space: nowrap;
}

width:45% 更改为 width:auto;,这会阻止按钮被点击。

关于html - CSS 伪选择器 "Blocking"Angular Ng-Click?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30604131/

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