Yichen Dai
Yichen Dai

Reputation: 41

css text with resizable image

how can i make the text over the image and with fix position? and the image is resizable via the view size of browser changing to change, the position of text and image i want like this:

position

i know to use position:absolute, but also want the group to the center of width

html:

.figure {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.figure .figcaption {
  width: 100%; 
  height: 0;
  font-size: 25px; 
  line-height: 0;
  color: white;
  position:absolute;
  top: 50%;
  z-index: 1;
}

.figure img {
  display:block;
  max-width: 100%; 
}

#subscribe {
  display: flex;
  position: relative;
  margin: 0;
  padding: 0;
  align-items: center;
}

input {
  -webkit-appearance: none;
  outline: none;
  border: 0;
}


input[type="email"] {
  position: relative;
  width: 50%;
  height: 40px;
  border-radius: 20px;
  padding-left: 20px;
}
<div class="figure">
 <div class="figcaption">
   <div class="slogen">
     <p>SLOGEN1</p>
     <p>SLOGEN2</p>
     <p>SLOGEN3</p>
   </div>
   <div class="content">
     <p>CONTENT1</p>
     <p>CONTENT2</p>  
     <p>CONTENT3</p>
     <p>CONTENT4</p>
   </div>
   <div id="subscribe">
     <input type="email" placeholder="enter your email here">
   </div>
 </div>
 <img src="http://s4.favim.com/orig/50/beautiful-city-light-night-street-Favim.com-460323.jpg"/>
</div>

the code is here:

https://codepen.io/jevonsdone/pen/xxVXzGv

thanks!

Upvotes: 0

Views: 89

Answers (4)

Przemek Kro
Przemek Kro

Reputation: 361

I think this will be it.

.figure {
  position: relative;
  display: inline-block;
  width: 100%;
  height: auto;
}

.figure .figcaption {
  font-size: 25px; 
  line-height: 0;
  color: white;
  position:absolute;
  bottom: 0%;
  z-index: 1;
  background-color: black;
  width: auto;
  display: inline-block;
}

.figure .figcaption > * {
    background-color: inherit;
}

.figure img {
  display:block;
  max-width: calc(100% - 10rem); 
  height: auto;
  margin-left: 10rem;
}

#subscribe {
  display: flex;
  position: relative;
  margin: 0;
  padding: 0;
  align-items: center;
}

input {
  -webkit-appearance: none;
  outline: none;
  border: 0;
}


input[type="email"] {
  position: relative;
  width: 50%;
  height: 40px;
  border-radius: 20px;
  padding-left: 20px;
}

Upvotes: 0

Yichen Dai
Yichen Dai

Reputation: 41

i think this is what i want:

body {
  background-color: black; 
}

.figure {
  position: relative;
  display: flex;
  width: 100%;
  height: auto;
  justify-content: center;
}

.figure .figcaption {

  font-size: 25px; 
  line-height: 0;
  color: white;
  z-index: 1;
  margin: 0;
  padding: 0;
  position: absolute;
  bottom: -15%;
  left: 15%;
}

.figure img {
  display:block;
  width: 50%; 
}

Upvotes: 0

Kishor Patil
Kishor Patil

Reputation: 950

Only CSS changed. Problem with your figure width.

.figure {
  position: relative;
  display: inline-block;
  width: 100%;
  height: 100%;
  
}

.figure .figcaption {

  font-size: 25px; 
  line-height: 0;
  color: white;
  position:absolute;
  z-index: 1;
  border: 3px solid green;
  padding: 10px;
  

  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.figure img {
  display:block;
  width: 100%; 
}

#subscribe {
  display: flex;
  position: relative;
  margin: 0;
  padding: 0;
  align-items: center;
}

input {
  -webkit-appearance: none;
  outline: none;
  border: 0;
}


input[type="email"] {
  position: relative;
  width: 100%;
  height: 40px;
  border-radius: 20px;
  padding-left: 20px;
}

Upvotes: 1

Przemek Kro
Przemek Kro

Reputation: 361

I don't know if I understood You correctly, but I have some proposition.

.figure .figcaption {
  font-size: 25px; 
  line-height: 0;
  color: white;
  position:absolute;
  bottom: 0;
  z-index: 1;
  background: black; /* Your figcaption background color here */
  width: auto; /* Width just to make a content fit in */
}

.figure img {
  display:block;
  max-width: 100%; 
  margin-left: 10rem; /* Image offset */
}

How about this?

Upvotes: 1

Related Questions