gpt4 book ai didi

css - 改变网页的主题颜色

转载 作者:行者123 更新时间:2023-11-28 05:05:11 25 4
gpt4 key购买 nike

我想在单击一个按钮后用三种不同的颜色更改网页的三个字段(即页眉、菜单、页脚)。如果我使用 onclick() 函数,它只会更改字段颜色,或者它会更改具有相同颜色的所有区域。

<div ng-style="myStyle" class="header">
<h1 style="color:white;padding:20px;">Header</h1>
</div>enter code here`

<div class="menu" ng-style=""">

<br><br><br>
<h2 style="color:white;margin-left:20px">Menu</h2>
<br>
<form class="n1">
<p style="color:white;"><b>Choose any color to change the <br/>theme of your website.</b></p><br/>
<input class="n2" type="button" value="Red" ng-click="myStyle={background:'red'}"><br><br>
<input class="n3" type="button" value="Green" ng-click="myStyle={background:'green'}"><br><br>

<input class="n4" type="button" value="Yellow" ng-click="myStyle={background:'yellow'}"><br><br>
<input class="n5" type="button" value="Lime" ng-click="myStyle={background:'lime'}"><br><br>
<input class="n6" type="button" value="Magenta" ng-click="myStyle={background:'magenta'}"><br>
</form>
</div>

最佳答案

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app=''>
<div ng-style="myStyle.header" class="header">
<h1 style="color:white;padding:20px;">Header</h1>
</div>enter code here

<div class="menu" ng-style='myStyle.body'>


<h2 style="color:white;margin-left:20px">Menu</h2>
<br>
<form class="n1">
<p style="color:white;"><b>Choose any color to change the <br/>theme of your website.</b>
</p>
<br/>
<input class="n2" type="button" value="Red" ng-click="myStyle={header: {background:'red'}, body: {background:'maroon'}}">
<br>
<br>
<input class="n3" type="button" value="Green" ng-click="myStyle={header: {background:'green'}, body: {background:'darkgreen'}}">
<br>
<br>

<input class="n4" type="button" value="Yellow" ng-click="myStyle={header: {background:'yellow'}, body: {background:'orange'}}">
<br>
<br>
<input class="n5" type="button" value="Lime" ng-click="myStyle={header: {background:'red'}, body: {background:'pink'}}">
<br>
<br>
<br>
</form>
</div>
</body>

这是一个工作片段,其中所有样式都在改变。您没有添加 ng-app,因此没有提供范围。这是你想要的吗?还是别的原因?这个问题有点模棱两可。

更新

如果你想为不同的元素使用不同的颜色,只需像这样使用嵌套对象:

{
header:
{
background:'red'
},
body: {
background:'maroon'
}
}

关于css - 改变网页的主题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39866595/

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