2016-03-22 14 views
3

私は下の図のようにテキストの真ん中に白い線で素敵なテキストを作るという仕事をしています。 cssとすることは可能ですか?ここでFiddle真ん中に白い線が入ったテキスト

enter image description here

.container{ 
 
    height:200px; 
 
    width:400px; 
 
    background-color:#EB8A1C; 
 
} 
 

 
.container h1{ 
 
    color:#2CDB1D; 
 
    text-align: center; 
 
    padding-top:40px; 
 
    font-size:400%; 
 
}
<div class="container"> 
 
    <h1> filosofia </h1> 
 
</div>

+0

私は前に、CSSで私が知っている唯一の1がテキストの装飾であることを見たことがないそうは思いません;それはそうではありません – DanyCode

+6

Webkitで簡単です。他にも簡単ではありませんhttps://jsfiddle.net/3rror404/woj4o7L4/ – Turnip

+0

@Turnip回答セクションに回答を投稿;) – AVI

答えて

5

あなたがSVGLinear Gradientでこれを行うことができます。ここでは別のDemo

svg { 
 
    border: 1px solid black; 
 
    background: #EB8A1C; 
 
} 
 

 
text { 
 
    font-size: 30px; 
 
    font-weight: bold; 
 
}
<svg width="250px" height="50px"> 
 
    <defs> 
 
    <linearGradient id="textGradient" x1="0" x2="0" y1="0" y2="1"> 
 
     <stop offset="0%" stop-color="#A5DE4A" /> 
 
     <stop offset="45%" stop-color="#A5DE4A" /> 
 
     <stop offset="50%" stop-color="white" /> 
 
     <stop offset="60%" stop-color="#A5DE4A" /> 
 
     <stop offset="100%" stop-color="#A5DE4A" /> 
 
    </linearGradient> 
 
    </defs> 
 

 
    <text fill="url(#textGradient)" x="0" y="35">LOREM IPSUM</text> 
 
</svg>

position: absoluteと固定heightを持っており、最も重要な部分はspan

@import url(https://fonts.googleapis.com/css?family=Montserrat:700); 
 

 
.text { 
 
    width: 200px; 
 
    height: 50px; 
 
    padding: 10px; 
 
    background: #EB8A1C; 
 
    color: white; 
 
    position: relative; 
 
    display: inline-block; 
 
    font-family: 'Montserrat', sans-serif; 
 
    font-weight: 700; 
 
} 
 

 
span { 
 
    font-size: 45px; 
 
    left: 20px; 
 
    position: absolute; 
 
    overflow: hidden; 
 
} 
 

 
span:nth-child(1) { 
 
    color: #A5DE4A; 
 
    height: 50; 
 
} 
 

 
span:nth-child(2) { 
 
    color: white; 
 
    height: 33px; 
 
} 
 

 
span:nth-child(3) { 
 
    color: #A5DE4A; 
 
    height: 29px; 
 
}
<div class="text"> 
 
    <span>filosofia</span> 
 
    <span>filosofia</span> 
 
    <span>filosofia</span> 
 
</div>
overflow: hiddenですされ、重複要素でこれを行うための別の方法があります

+0

ありがとうたくさん:) –

+0

@トーマスBajoras私は別の可能な解決策で私の答えを更新したので多分見てみましょう。 –

-2

は、あなたのH1要素にクラスを追加しています。

<h1 class="strike">....</h1> 

これもあなたのCSSを追加します。

.strike{ 
text-decoration: white line-through; 
} 
+0

それはすべてのh1タグの行を追加するために、私はテキスト文字にのみ行を追加する必要があります。 –

+0

私は答えを更新しました。 – andnowchris

+0

文字の間隔には、緑色の背景などのマークも付けられます。 –

2

これは、私はそれをやった方法です:

.container h1 { 
    text-align: center; 
    padding-top: 40px; 
    font-size: 400%; 
    background: -webkit-linear-gradient(#2CDB1D 68%, white 70%, #2CDB1D 0%); 
    -webkit-background-clip: text; 
    -webkit-text-fill-color: transparent; 
} 

Here is the JSFiddle demo

+4

ええ、Firefoxで動作しません;) –

+0

クロムで動作します:) –

3

これは、上記のコメントで述べたように、非標準の-webkit-text-fill-colorのおかげで、Webkitでは簡単です。しかし、Webkit以外のブラウザでは扱いにくいです。

SVG線形勾配を使用すると、同じ効果を得ることができます。これは私がテストしたすべてのものにうまく動作するようです:ライン・スルー:

body { 
 
    background: orange; 
 
} 
 

 
.svg_text, h1 { 
 
    font-size: 72px; 
 
    font-weight: bold; 
 
    margin: 0; 
 
} 
 

 
/* webkit-only ... */ 
 
.fancy { 
 
    background: #8bed89; 
 
    background: -moz-linear-gradient(top, #8bed89 0%, #8bed89 45%, #ffffff 51%, #8bed89 56%, #8bed89 100%); 
 
    background: -webkit-linear-gradient(top, #8bed89 0%, #8bed89 45%, #ffffff 51%, #8bed89 56%, #8bed89 100%); 
 
    background: linear-gradient(to bottom, #8bed89 0%, #8bed89 45%, #ffffff 51%, #8bed89 56%, #8bed89 100%); 
 
    -webkit-background-clip: text; 
 
    -webkit-text-fill-color: transparent; 
 
}
<h4>Webkit only...</h4> 
 

 
<h1 class="fancy"> 
 
    filosofia 
 
</h1> 
 

 
<h4>Others...</h4> 
 

 
<svg height="60" width="500"> 
 
    <defs> 
 
    <linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%"> 
 
     <stop offset="0%" style="stop-color:rgb(139,237,137); stop-opacity:1"/> 
 
     <stop offset="45%" style="stop-color:rgb(139,237,137); stop-opacity:1"/> 
 
     <stop offset="50%" style="stop-color:rgb(255,255,255); stop-opacity:1"/> 
 
     <stop offset="55%" style="stop-color:rgb(139,237,137); stop-opacity:1"/> 
 
     <stop offset="100%" style="stop-color:rgb(139,237,137); stop-opacity:1"/> 
 
    </linearGradient> 
 
    </defs> 
 
    <text x="0" y="50" fill="url(#gradient)" class="svg_text"> 
 
    filosofia 
 
    </text> 
 
</svg>

+0

回答ありがとう:) –

関連する問題