首页 \ 问答 \ 如何在CSS中设置文本的背景颜色?(How do I set the background color of targeted text only, using only CSS?)

如何在CSS中设置文本的背景颜色?(How do I set the background color of targeted text only, using only CSS?)

在此输入图像描述

我想要的是绿色背景不要100%的页面宽度。 我想要它在文本的后面。 HTML:

<!DOCTYPE html>

<head> 
<link rel="stylesheet" type="text/css" href="style.css">
</head> 

<body> 

<h1>  
The Last Will and Testament of
Eric Jones</h1> 

</body> 

style.css中:

h1
{ 
    text-align: center; 
    background-color: green; 
}

Question

How can I dynamically add a green background behind text, not the entire page width, just the text.

Problem

The green is expanding to the entire page with my current code. I am not able to modify the HTML or Javascript, just the CSS file.

enter image description here

HTML

<h1>The Last Will and Testament of Eric Jones</h1> 

CSS

h1 { 
    text-align: center; 
    background-color: green; 
}

原文:https://stackoverflow.com/questions/14310154
更新时间:2021-12-14 13:12

最满意答案

您创建的库jar不包含IDE / Gradle可以解析为能够编译/运行测试项目的任何依赖信息。 我看到你正在使用Maven中央仓库,所以你需要做的是将你的库发布到你的本地Maven仓库,并且在测试项目中添加一个依赖信息(不是简单的jar文件)。

因此,在库和测试项目build.gradle添加一个Maven本地存储库配置。

repositories {
   mavenLocal()
   mavenCentral()
}

现在您需要将库发布到本地存储库。 当你使用Gradle 3.3时,你可以使用Maven Publishing

所以在图书馆build.gradle添加一个maven发布信息。

publishing {
    publications {
        maven(MavenPublication) {
            groupId 'io.simplepush'
            artifactId 'project1-sample'
            version '1.1'

            from components.java
        }
    }
}

Gradle“maven-publish”插件可以很容易地发布到本地存储库,自动创建PublishToMavenLocal任务。 所以你可以运行

gradle publishToMavenLocal

它会将你的库与所有的依赖信息一起发布到本地的maven仓库中。

然后你只需要添加一个库信息给你测试项目build.gradle

dependencies {
        // other dependencies .....
        module 'io.simplepush:project1-sample:1.1'
}

I solved it by changing several things.
Thanks to @Babl for pointing me in the right direction.
My new library build.gradle looks like this:

plugins {
  id 'java'
  id 'maven-publish'
}

sourceCompatibility = 1.5

repositories {
  mavenLocal()
  mavenCentral()
}

dependencies {
  compile 'commons-codec:commons-codec:1.10'
  compile 'org.apache.httpcomponents:httpcore:4.4.6'
  compile 'org.apache.httpcomponents:httpclient:4.5.3'
}

publishing {
  publications {
    maven(MavenPublication) {
      groupId 'io.simplepush'
      artifactId 'project1-sample'
      version '1.1'

      from components.java
    }
  }
}

Now I can push the library to the local maven repository with ./gradlew publishToMavenLocal.

The build.gradle of the test project uses the application plugin and defines a main class (which is Hello in my case). Then I can run ./gradlew installDist to generate an executable file (see Application plugin docs) which puts all dependencies in the classpath and runs just fine.

group 'com.test'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'application'

repositories {
  mavenLocal()
  mavenCentral()
}

dependencies {
  compile 'io.simplepush:project1-sample:1.1'
}

mainClassName = "Hello"

相关问答

更多

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)