Jump to content
  • Sign Up
  • 0

Заглавная буква на фоне текста


Garamond

Question

4 answers to this question

Recommended Posts

  • 0

навскидку два варианта: либо установить в качестве бекграунда, либо абсолютно позиционированный блок.

Link to post
Share on other sites
  • 0
5 минут назад, AlexZaw сказал:

либо установить в качестве бекграунда

Реализовать вариант на php - что бы буква автоматически(!) ставилась и под текст подкладывалась

Link to post
Share on other sites
  • 0

На js примерно так:

<div class="text">
  <div class="bg"></div>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum, harum!</p>
</div>
.text{
  position: relative;
}
.bg{
  position: absolute;
  top: -75px;
  left: 0;
  color: #0ff;
  font-size: 150px;
  z-index: -1;  
}
var txt = document.querySelector('.text');
var bg = document.querySelector('.bg');
var first = txt.querySelector('p').innerHTML.charAt(0);
bg.innerHTML = first;

На пхп, думаю, прицип такой-же, единственно проблема может возникнуть при получении первого символа если используется кирилица, но решение легко гуглится

 

зы. сейчас работает только для первого блока на странице, но можно переделать и под все подобные блоки

Edited by AlexZaw
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy