【问题标题】:Underlining lines in full width, not only text全宽下划线,不仅是文本
【发布时间】:2015-08-30 11:37:52
【问题描述】:

嗨,
我目前正在尝试使用 HTML/CSS 设置一些看起来像便利贴的东西。

我的目标图像

请注意,每一行都应加下划线,无论该行有多少个字符。此外,每个新行都应完全加下划线。

HTML:

<p>
    <img src="http://trööt.net/img/pin.png" alt="Stecknadel"/>
    <font>Heading</font><br />
    <span class="blockMargin">
    <span class="underline">
        <strong>Subheading</strong> text text text
    </span>
    </span>
</p>

CSS:

p {
    background-Color: #ffc; 
    padding: 1em; 
    width: 40em; 
    box-shadow: 5px 5px 3px 0px rgba(119,119,119,0.7); 
    text-align: justify;
}
img{
    float: None;  
    height: 4em; 
    display: block; 
    margin-left: Auto; 
    margin-right: Auto;
}

.blockMargin{
    display: block; 
    margin-bottom: -1px;
}

.underline{
    border-bottom: 1px dotted #c03;
}

这是我目前正在使用的代码(已经从 stackoverflow.com 获得了这个想法)。但是,它并没有下划线完整的线条,而是完全像text-decoration: underline...

有什么想法吗? 也许我应该补充一点,我使用 WordPress 和核主题创建这个。

非常感谢您的帮助!

JSFiddle 示例:http://jsfiddle.net/8w9Lj7nd/

【问题讨论】:

标签: css border underline


【解决方案1】:

http://jsfiddle.net/8w9Lj7nd/1/

给你。

.underline{
border-bottom: 1px dotted #c03;
width: 100%;
display: block;
}

【讨论】:

  • 谢谢!它在 JSFiddle 中看起来很完美......不幸的是,有些东西阻止它在我的页面上工作。线条根本不显示。我猜 Wordpress 或主题会以某种方式做到这一点?!
  • 检查元素或尝试 !important。
【解决方案2】:

这是回答here


我将other answer 升级为 SCSS 以使其可配置。您现在可以轻松更改孔和规则的大小和颜色,并且所有内容都会相应地调整大小。

另外,我添加了另一个使用可编辑 div 而不是 textarea 的示例。

jsfiddle

// rule config
$rule-height: 20px; // <-- primary parameter

   $font-size: min(max($rule-height - 9, 8pt), 13pt);
   $rule-mask-height: $rule-height - 1;
   $rule-padding-top: $rule-height + 2;
   $rule-padding-right: $rule-height;
   $rule-padding-left: $rule-height * 2;

// colors
$hole-fill-color: #f5f5f5;
$hole-shadow: #CCCCCC;
$paper-color: #FFFFFF;
$line-color: #E7EFF8;

不幸的是,Stackoverflow 不支持 SCSS,所以我只在此处包含了一个固定配置的快照:

@import url("https://fonts.googleapis.com/css?family=Reenie+Beanie");

html { height: 100%; }
body { background-color: #f5f5f5; }

.editable {
  color: #000000;
  border: 1px solid #EEEEEE;
  box-shadow: 1px 1px 0 #DDDDDD;
  display: inline-block;
  vertical-align: top;
  /*font-family: 'Marck Script', cursive;*/
  font-family: 'Reenie Beanie', cursive;
  font-size: 24px;
  line-height: 20px;
  margin: 2% auto;
  padding: 22px 20px 3px 40px;
  resize: none;
  min-height: 200px;
  width: 300px;
  background-color: #FFFFFF;
  background-image: -moz-linear-gradient(top, transparent, transparent 19px, #E7EFF8 0px), -moz-radial-gradient(4% 50%, circle closest-corner, #f5f5f5, #f5f5f5 39%, transparent 0%), -moz-radial-gradient(3.9% 46%, circle closest-corner, #CCCCCC, #CCCCCC 43.5%, transparent 0%);
  background-image: -webkit-linear-gradient(top, transparent, transparent 19px, #E7EFF8 0), -webkit-radial-gradient(4% 50%, circle closest-corner, #f5f5f5, #f5f5f5 39%, transparent 0%), -webkit-radial-gradient(3.9% 46%, circle closest-corner, #CCCCCC, #CCCCCC 43.5%, transparent 0%);
  -webkit-background-size: 100% 20px;
  background-size: 100% 20px;
}
<textarea class="editable">Textarea: This is the first line.
See, how the text fits here, also if there is a linebreak at the end? It works nicely.

  Great.
</textarea>

<div class="editable" contenteditable>Editable div: This is the first line.<br>
  See, how the text fits here, also if there is a linebreak at the end?<br>
  It works nicely.<br>
  <br>
  Great.
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-18
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 2013-08-22
    • 2014-07-29
    • 2020-08-26
    • 1970-01-01
    相关资源
    最近更新 更多