首页 \ 问答 \ 在css中设置背景图像和颜色(Set background image and color in css)

在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-imagebackground-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 and background-color.
For example green color over the image with opacity: 0.37 Sorry, I forgot the placing opacity property in css

  #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
更新时间:2023-04-02 07:04

最满意答案

您需要将$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 to myCustomIncrement() method and have it incremented there. So your myCustomIncrement() and myCustomOutput() 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.

相关问答

更多
  • @SaidKholov - 哇,我知道了。 我不知道我在这方面做了多长时间,直到我要求一些帮助才能解决这个问题。 我在想你的var_dump,我意识到我试图让结果成为一个数组,当它们已经是一个数组时。 所以摆脱了make数组线,我有: /**Find groups that are not closed and send to group_find page */ foreach(NewguyModel::getAllAvailability() as $key => $value) { ...
  • 这里有两个问题 您正在创建一个覆盖lorem()函数的子类。 您必须显式调用parent::lorem()才能访问它 即使你调用它,那个执行include父函数意味着在该函数中定义的任何东西都是局部作用于该函数的 。 这意味着你的子函数不能继承它(至少没有某种return声明) 您需要在类声明之外移动包含 include_once 'extendClass.php'; class myClass { public function lorem() { } public funct ...
  • 分开你的顾虑将帮助你更清楚地看到你的问题。 在你的控制器中: 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( ...
  • 对象总是作为参考传递。 如果您需要两个单独的不相交对象,则需要显式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 ...
  • 你可以用特质做很多事情。 我在我的框架中使用它,例如Singleton和Getter / Setter。 trait Singleton { protected static $_instance; protected function __construct(){} public static function getInstance() { if (null === self::$_instance) { self::$_ins ...
  • 您需要将$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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。