X
X
xfqzmkwy2018-08-31 15:35:00
css
xfqzmkwy, 2018-08-31 15:35:00

How to make the width of the top block depending on the content?

I have a #background block:

#background {
  background-color: red;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

Above this block is another #text div:
#text {
  position: relative;
  z-index: 1000;
  background-color: black;
  color: #fff;
  text-align: center;
}

<div id="background"></div>
<div id="text">Текст</div>

How to make #text width be based on its content? As a result, it takes up the entire width and overlaps #background.
Demo is here.

Answer the question

In order to leave comments, you need to log in

12 answer(s)
M
Maxim Timofeev, 2018-08-31
@webinar

Add to him
display: inline;

C
Comrade Polyakov, 2019-02-21
@eliseishe

You can use em units, set the width as a percentage

G
God Emperor, 2015-03-01
@God-emperor

I liked Andrew Troelson's book. I think it fits

A
Anton Papin, 2015-03-05
@i_light

Microsoft's book co-authored with intuit, C# for high school students is a great start.
And then Troelsen.

G
globuser, 2015-03-01
@globuzer

work on more theory and bases on algorithms and OOP, since you are at school again and again C #, and then take on this language. the classic C for the base will also work, but not deep, C ++ is also in principle, but not deep.

I
ivkol, 2015-03-01
@ivkol

tasks at least half evenly

V
Vladimir Martyanov, 2015-03-01
@vilgeforce

Learn English, at least to the level of free reading MSDN

D
Dorsalon Dethahal, 2015-03-02
@Dorsal

I just also started studying C#, I study from the book by Andrew Troelson "The C# 5.0 Programming Language and the .NET 4.5 Platform", and also by Flenov "The C# Bible". Everything is clearly laid out. I like the first one better.

A
Alexander, 2015-03-02
@saphire13

padabum.com/d.php?id=352
I learned from it, consider it my desktop :) Only under the 4.0 version of the language.

V
Vitaly Vitrenko, 2015-03-02
@Vestail

Books for learning C#/.NET
An extensive article on this topic.

A
Alexander Dubina, 2015-03-10
@struggleendlessly

Well, there are a million questions. the answer is always the same - with the creation of applications. The first - as in all textbooks: a calculator. Then a converter, an alarm clock, a matrix. And then you will see that you can do it more difficult .....

C
cthulhudx, 2015-04-07
@cthulhudx

"Learning C#" E. Stillman, J. Green

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question