在css中设置背景图像和颜色(Set background image and color in css)
我要设置背景图像和背景颜色这两个工作正常但问题是,当我在
div
上写一些文本时,背景自动应用于文本这里是我的代码请查看它。#canvas-preview { width: 200px; border: 1px solid #000; box-sizing: border-box; position: relative; background-image: url('path/to/image.png'); } #canvas-preview::before { background-color: green; content: ''; display: block; height: 100%; position: absolute; width: 100%; } #custom-canvas { margin: 10px; color: #fff; }
<div id="canvas-preview"> <div id="custom-canvas">There is some text</div> </div>
我想将文字颜色设置为白色。 这段代码有什么问题。
UPDATE
我需要
background-image
和background-color
。
例如图像上的绿色与opacity: 0.37
对不起,我忘记了在css
放置opacity
属性#canvas-preview::before { background-color: green; opacity: 0.37; /* editing in code */ content: ''; display: block; height: 100%; position: absolute; width: 100%; }
我需要两件事而不是一件事。
I'm going to set background image and background color both this is working fine but the problem is that when I write some text on a
div
the background automatically apply on the text here is my code please review it.#canvas-preview { width: 200px; border: 1px solid #000; box-sizing: border-box; position: relative; background-image: url('path/to/image.png'); } #canvas-preview::before { background-color: green; content: ''; display: block; height: 100%; position: absolute; width: 100%; } #custom-canvas { margin: 10px; color: #fff; }
<div id="canvas-preview"> <div id="custom-canvas">There is some text</div> </div>
I want to set text color white. What's the problem with this code.
UPDATE
I need both
background-image
andbackground-color
.
For example green color over the image withopacity: 0.37
Sorry, I forgot the placingopacity
property incss
#canvas-preview::before { background-color: green; opacity: 0.37; /* editing in code */ content: ''; display: block; height: 100%; position: absolute; width: 100%; }
I need both things not one.
原文:https://stackoverflow.com/questions/39341655
最满意答案
您需要将
$readable
myCustomIncrement()
值传递给myCustomIncrement()
方法并使其增加。 所以你的myCustomIncrement()
和myCustomOutput()
方法将是这样的:protected function myCustomIncrement($readable) { return ++$readable; } public function myCustomOutput() { foreach( $this->my_array as $single ) { $readable = $single['level_1']['level_2']['level_3']['something']; return $this->myCustomIncrement($readable); } }
使增量操作预先增量,如
return ++$readable;
,而不是后增量,以便该方法可以返回更新的值。You need to pass
$readable
value tomyCustomIncrement()
method and have it incremented there. So yourmyCustomIncrement()
andmyCustomOutput()
methods would be like this:protected function myCustomIncrement($readable) { return ++$readable; } public function myCustomOutput() { foreach( $this->my_array as $single ) { $readable = $single['level_1']['level_2']['level_3']['something']; return $this->myCustomIncrement($readable); } }
Make the increment operation pre-increment like
return ++$readable;
, not post-increment, so that the method could return the updated value.
相关问答
更多-
在课堂上找不到字段(Field not found in class)[2021-11-11]
@SaidKholov - 哇,我知道了。 我不知道我在这方面做了多长时间,直到我要求一些帮助才能解决这个问题。 我在想你的var_dump,我意识到我试图让结果成为一个数组,当它们已经是一个数组时。 所以摆脱了make数组线,我有: /**Find groups that are not closed and send to group_find page */ foreach(NewguyModel::getAllAvailability() as $key => $value) { ... -
在课堂上正确使用include(Using include in class properly)[2021-10-11]
这里有两个问题 您正在创建一个覆盖lorem()函数的子类。 您必须显式调用parent::lorem()才能访问它 即使你调用它,那个执行include父函数意味着在该函数中定义的任何东西都是局部作用于该函数的 。 这意味着你的子函数不能继承它(至少没有某种return声明) 您需要在类声明之外移动包含 include_once 'extendClass.php'; class myClass { public function lorem() { } public funct ... -
PHP foreach,if语句(PHP foreach, if statement)[2021-10-01]
分开你的顾虑将帮助你更清楚地看到你的问题。 在你的控制器中: result_array(); $results = array(); $today = time(); foreach($codes->result_array() as $row) { if(strtotime($row['exp_date']) <= $today) {//-- Keep this $results[] = $row; } ... -
尝试一种不同的方法。 首先,在将数据传递给负责生成视图的foreach循环之前准备数据,然后您的foreach循环将更容易阅读和维护。 如果每个第一个元素都应该跟第二个foreach中的第一个元素,第二个到第二个,第三个到第三个等等,那么使用两个foreach循环是多余的。 只使用1个foreach,并且在每个foreach迭代中取其索引(它可以是一个单独的增量变量),并通过索引从第二个数组中获取元素。 你也可以使用标准的循环,它应该更容易实现。 Try a different approach. Firs ...
-
你的类FCSOfOtherClass没有实现java.lang.Iterable 。 “foreach”循环仅适用于Iterable数组和实例。 你可以通过让你的类实现Iterable来解决这个问题: public class FCSOfOtherClass implements java.lang.Iterable
{ ... } 这要求您为接口方法iterator()提供一个实现。 你的示例代码显示你已经做了: public Iterator iterator( ... -
在课堂上返回当前$ this(Return current $this in a class)[2022-02-16]
对象总是作为参考传递。 如果您需要两个单独的不相交对象,则需要显式clone它。 An object is always passed around as reference. If you want two separate disjoint objects, you need to explicitly clone it. -
嗯,你的图书服务没有拿书本对象吗? 似乎它应该Book类的责任来确定它是否有效,而不是你的表单验证什么是有效的书。 一些验证,如必填字段留空可能是表单级验证问题......但很多这听起来像书籍服务和/或书籍类的领域。 Hmm, does your book service not take a book object? Rather than your form doing validation of what's a valid book, it seems like it should maybe bo ...
-
在课堂上使用特征,为什么?(Using traits over classes, why?)[2021-12-12]
你可以用特质做很多事情。 我在我的框架中使用它,例如Singleton和Getter / Setter。 trait Singleton { protected static $_instance; protected function __construct(){} public static function getInstance() { if (null === self::$_instance) { self::$_ins ... -
PHP - 在课堂上/ foreach:卡住了,无法弄清楚该怎么做(PHP - While/foreach in a class: stuck, can’t figure out what to do)[2023-08-10]
您需要将$readable myCustomIncrement()值传递给myCustomIncrement()方法并使其增加。 所以你的myCustomIncrement()和myCustomOutput()方法将是这样的: protected function myCustomIncrement($readable) { return ++$readable; } public function myCustomOutput() { foreach( $this->my_array a ... -
在你的例子中do_stuff不是一个实例变量。 它更像是一个静态变量。 您需要在方法(例如, init方法)中定义do_stuff,其中您具有对self的引用,以使其成为实例变量。 我希望这个例子能为你澄清一些事情: class Foo: def __init__(self): self.do_stuff = { "A": self.do_A, "B": self.do_B } def run(self): for x in ["A", "B"]: self.do_s ...