Div to stretch to fit contents. Overflow: auto; does not work - html

I've created a long scrolling website composed of different sections which fill up the whole screen. One Section contains some pretty lengthy text but the top and bottom parts of the text are cut off. Basically my div won't stretch all the way to accommodate the text. I would like my div to be able to stretch to at least 200% down.
fiddle
I've tried
overflow:auto;
min-height:100%;
This is what it looks like, as you can see at the bottom...the text is cut off.
If I remove Position: absolute; The whole text moves to the left and the bottom text is still cut off.
This is part of my html:
<section id="slide-15" class="homeSlide">
<div class="bcg">
<div class="hsContainer">
<h1>CV GUIDE</h1>
<br>
<h2>
//lengthy text goes here
//lengthy text goes here
//lengthy text goes here
</h2>
</div>
</div>
</section>
and part of style.css
#slide-15 .bcg {
/*position: relative;*/
background-color: #1C1C1C;
min-height: 100%;
overflow: auto;
/*padding:150px;*/
}
slide-15 .hsContent {
position: relative;
}
slide-15 .hscontainer {
width-100%
min-height: 100%;
overflow: auto;
/* position:relative;*/
}
#slide-15 h1 {
margin: 70px;
color: #ffffff;
font-size: 30px;
line-height: 20px;
position: relative;
text-shadow: 2px 4px 3px rgba(0,0,0,0.3);
}
#slide-15 h2 {
color: #ffffff;
font-size: 14px;
line-height: 150%;
position: absolute;
line-spacing: 1px;
text-align: justify;
width: 700px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

with position:absolute it gets cut out of the workflow ,so you need to remove it with you want the parent div to adjust to height;
also set it to display:inline-block ,
check fiddle
You've got a lot of syntax errors in CSS,
I cleaned it up a little here's an updated fiddle

Try creating a class in css like this:
.test {
white-space: nowrap;
}
and apply it to your h2:
<h2 class="test">
//lengthy text goes here
//lengthy text goes here
//lengthy text goes here
</h2>

Related

How can I create a fixed text region within image size in HTML and CSS?

Basically I've an image with text inside it as seen in the image below:
contained_text
But when I resize the window, the text "falls out" of the screen:
uncontained_text
This is the HTML:
<div class="container">
<img class="cpu" src="images/cpu.png" alt="cpu-img">
<div class="text">
<!-- text here -->
</div>
</div>
And this is the CSS:
.container {
position: relative;
padding-top: 100px;
background-color: #222831;
color: #EEEEEE;
}
.cpu {
width: 21%;
padding-top: 40px;
}
.text {
position: absolute;
top: 46.5%;
left: 40%;
width: 20%;
word-break: break-word;
}
Is there a way to fix this issue so text doesn't fall out of screen image?
When you resize your screen, the size of your text inside the <img> tag needs to be changed, so you have to change the size of the text container as well or hide the overflow texts by adding overflow: hidden; to the .text element.

Moving text block over container

I'm new so please be as simple as possible. I want to put words over a picture and got code that words below. The text appears on a black box in the lower right. I want it to appear in the upper left.
When I change in text box bottom to top and right to left it takes up the whole image. If I keep it on the right-it goes down all the way to the bottom of the image. Even if I try to increase the px to make it not so long it doesn't work. How can I fix this & what am I doing wrong?
.container {
position: relative;
font-family: Arial;
}
.text-block {
position: absolute;
bottom: 20px;
right: 20px;
background-color: black;
color: white;
padding-left: 20px;
padding-right: 20px;
}
<div class="container">
<img src="pdf/library.jpg" style="width:100%;">
<div class="text-block">
<h4>WORDS</h4>
</div>
</div>
The positioning of the element is based on the left, right, top and bottom and it will be relative the element you positioned to (in your case is the div with the container class).
If you will use only left and top it will work as you expect. The values is how much space from that side it will take.
Also, if you use 3 or 4 sides, it will stretch the element so the boundaries of it will be on the side you specified.
For example (I used sample image from google for the snippet):
#TEST {
background-image: linear-gradient(45deg,rgb(218,34,255) 30%,#9733ee 90%);
padding: 1em;
border-radius: 3px;
margin: 1em 0;
color: #fff;
}
.container {
position: relative;
font-family: Arial;
}
.text-block {
position: absolute;
top: 20px;
left: 20px;
background-color: black;
color: white;
padding-left: 20px;
padding-right: 20px;
}
<section id="TEST">
<div class="container">
<img src="https://www.petcareplus.ie/wp-content/uploads/2020/04/dog-puppy-on-garden-royalty-free-image-1586966191.jpg" style="width:100%;">
<div class="text-block">
<h4>WORDS</h4>
</div>
</div>
</section>

Centered text in a square CSS box using borders?

I want to create a CSS box to act as a 'logo' piece or what have you, centered in another div on the middle of the page - I'm using bootstrap 3, put the div in a container-fluid for a full-width page as I wanted, and went about starting on the logo portion of it.
My code is as follows
.logo{
width: 50rem;
height: 50rem;
margin: 0 auto;
text-align: center;
font-size: 15em;
font-weight: 100;
font-family: 'Raleway' , sans-serif;
color: white;
border: 14px solid black;
}
For whatever reason, this doesn't actually make a square - I'm assuming this is based on the font-size, but it seems like the larger the font goes, it just spills outside of the box - so I can't for the life of me figure out how to both vertically align this text and create a perfect square around the text while I'm at it. Any insight would be greatly appreciated - thanks!
I have a container div that is basically that can be your body. The size can be adjusted.
Then there is the logo class. This class has a relative width.
In the examples case: 50% of its parent (container class)
There is no fixed height of the box so it height is based on the text.
The box is positioned in the center trough absolute positioning and transforming it again.
.container {
position: relative;
width: 500px;
height: 500px;
background-color: gray;
}
.logo {
position: relative;
top: 50%;
left: 50%;
width: 50%;
transform: translate(-50%, -50%);
text-align: center;
font-size: 3em;
font-weight: 100;
font-family: 'Raleway', sans-serif;
color: white;
box-sizing: border-box;
border: 14px solid black;
}
<div class="container">
<div class="logo">
Some random text goes here?
</div>
</div>

Text over a translucent div causes the text to be translucent

I am trying to get text over a translucent div. This is in Chrome, if that's relevant (i.e. a Chrome bug). For some reason, whenever the text is on top of the div (moved there by a negative margin-top), it is also partially transparent.
HTML is as follows (this is a simplified approximation):
<div class="background-image-div"></div>
<div class="content">
<p>Text goes here</p>
</div>
CSS is as follows (this is a simplified approximation):
.background-image-div {
background: url(../images/Image.png) no-repeat right;
opacity: .5;
}
.content {
height: 480px;
margin-top: -271px;
max-width: 1200px;
padding-top: 15px;
padding-bottom: 15px;
}
So background-image-div should absolutely be translucent, but for some reason, the text in the content div, which shouldn't be and which isn't a child of background-image-div is translucent as well. When I turn opacity off of the background-image-div, it doesn't appear to be on the content div, and likewise when I don't use negative margin-top on the content div (to push it to the same position as background-image-div), it also doesn't appear to be translucent.
What is going on exactly? As far as I can tell this is not WAD. Is it a bug in Chrome?
The text is not translucent. What is happening is that the translucent image is on top of your text, so you see the text lighter.
Here's a modified version of your CSS. The important addition is position:relative and z-index: -1 on the .background-image-div
.content {
height: 480px;
margin-top: -271px;
max-width: 1200px;
padding-top: 15px;
padding-bottom: 15px;
color: black; font-size: 40px; font-weight: bold;
}
.background-image-div {
position: relative;
z-index: -1;
width: 600px;
height: 600px;
background: url(https://upload.wikimedia.org/wikipedia/commons/2/21/EverestfromKalarPatarcrop.JPG) no-repeat right;
opacity: .5;
}
On CodePen: https://codepen.io/vic3685/pen/PzdEEJ
Try this and tell me how it works, it worked for me.
HTML
<div id="picture">
<div class="background-image-div"></div>
<div class="content">
<p>Text goes here</p>
</div>
</div>
CSS
.content {
top:400px;
left:200px;
background-color:red;
position:absolute;
}
.background-image-div {
/*place your image in here*/ background: url('http://hk.blouinartinfo.com/sites/default/files/1349378871-56591.jpg') no-repeat;
opacity: .5;
background-size:cover;
/*or whatever size you want*/
height:500px;
width:500px;
}

My page wont scroll down?

I'm trying to make this page but as soon as the screen is smaller it wont make me scroll down to see more of my text.
Here is the link fiddle
<html>
<div class="container_12 container clearfix">
<div class="grid_12 clearfix main_content">
<div class="content">
<div><img src="http://placehold.it/780x150"></div>
<div class="text">
<h1>title</h1>
<p> text<p>
<p> text<p>
<p> text<p>
<p> text<p>
</p>
</div>
</div>
</div>
</div>
</html>
<style>
.content{
width: 780px;
padding: 20px;
position: fixed;
left: 50%;
top: 50%;
color: #000000;
font-family: Lora BoldItalic, Lora;
margin-top: -312px;
margin-left: -390px;
}
.text {
background: gray;
opacity: 0.6;
padding: 20px;
}
</style>
Thank you so much in advance!
I removed a few things from your CSS:
position: fixed;
left: 50%;
top: 50%;
margin-top: -312px;
margin-left: -390px;
In general (unless you really know what are you doing) using margin (especially negative values), position fixed, left and top is a bad idea because you are forcing elements to stay in a fixed position so your page will not work in all screen sizes.
I saw in your code that you are trying something with a background (is not visible in the demo) try to add the background to body not to html. I don't know what you are trying but I have a feeling that you want the page content to scroll without moving the background you will need to check this out http://jsfiddle.net/gF7Af/31/
I have the following:
.myimg{
margin: auto;
}
.content{
margin: auto;
width: 780px;
color: #000000;
font-family: Lora BoldItalic, Lora;
}
i dont see any of your text.. i dont understand why you put fixed position to the content nor those negative margins, so i removed those odd rules and at least i can see the text now.
Modify .content like this:
.content{
width: 780px;
padding: 20px;
/*margin: auto;*/
color: #000;
font-family: Lora BoldItalic, Lora;
}