Hello I'm trying to achieve this
So in this case you can see, we have 3 divs. Top one will have a width of 100% and an height:auto. Also will be relative positioned of course.
Second one the same, but in this case I'll add a dummy text that will define the height of the div.
And the 3rd one just like the first one, the problem is that, they're not alinged. Not one before the other. Could someone tell me what is wrong with my code? Thanks
#block1 {
position:relative;
width:100%;
height:auto;
background-color: blue;
}
#img1 {
width:100px;
height:100px;
position:absolute;
left:50%;
transform:translate(-50%);
-webkit-transform:translate(-50%);
}
#block2 {
position:relative;
width:100%;
height:auto;
background-color: orange;
}
.dummytext {
font-family: 'Ralleway, sans-serif';
font-size: 20px;
text-align: justify;
margin:10px;
}
#block3 {
position:relative;
width:100%;
height:auto;
background-color: brown;
}
#img2 {
width:100px;
height:90px;
position:absolute;
left:50%;
transform:translate(-50%);
-webkit-transform:translate(-50%);
}
<div id="block1">
<img src="images/img1.png" id="img1"/>
</div>
<div id="block2">
<h3 class="dummytext">Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, </h3>
</div>
<div id="block3">
<img id="img2" src="images/img2.png"/>
</div>
Could someone help me to understand?
This is because your image is abolutely positioned, which won't contribute to the size of the container.
You should remove the absolute position of the image.
Try this:
div {
text-align: center; /* center everything inside the divs */
}
#block1 {
width: 100%;
height: auto;
background-color: blue;
}
#img1 {
width: 100px;
height: 100px;
}
#block2 {
width: 100%;
height: auto;
background-color: orange;
}
.dummytext {
font-family: 'Ralleway, sans-serif';
font-size: 20px;
text-align: justify;
margin: 10px;
}
#block3 {
width: 100%;
height: auto;
background-color: brown;
}
#img2 {
width: 100px;
height: 90px;
}
<div id="block1">
<img src="images/img1.png" id="img1" />
</div>
<div id="block2">
<h3 class="dummytext">Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, </h3>
</div>
<div id="block3">
<img id="img2" src="images/img2.png" />
</div>
Your elements aren't showing, due to having set the property position on them.
To make this work, add table elements around the img tags and set the margin: auto property on them.
#block1 {
width: 100%;
height: auto;
background-color: blue;
}
#img1 {
width: 100px;
height: 100px;
left: 50%;
transform: translate(-50%);
-webkit-transform: translate(-50%);
}
#block2 {
width: 100%;
height: auto;
background-color: orange;
}
.dummytext {
font-family: 'Ralleway, sans-serif';
font-size: 20px;
text-align: justify;
margin: 10px;
}
#block3 {
width: 100%;
height: auto;
background-color: brown;
}
#img2 {
width: 100px;
height: 90px;
left: 50%;
transform: translate(-50%);
-webkit-transform: translate(-50%);
}
table {
margin: auto;
}
<div id="block1">
<table>
<tbody>
<tr>
<td>
<img id="img1" src="images/img1.png"></td></tr></tbody><table>
</div>
<div id="block2">
<h3 class="dummytext">Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, Text Example, </h3>
</div>
<div id="block3">
<table>
<tbody>
<tr>
<td>
<img id="img2" src="images/img2.png"></td></tr></tbody><table>
</div>
To control the layout of your divs you should give them a display property. Try adding display: table-row; for each block
You don't need to use absolute positioning to accomplish this. It is easier (and safer) to use the default static positioning and center things using margin: 0 auto like so:
#block1 {
width:100%;
background-color: blue;
}
#img1 {
height: 100px;
width: 100px;
margin: 0 auto;
}
#block2 {
width:100%;
background-color: orange;
}
.dummytext {
font-family: 'Ralleway, sans-serif';
font-size: 20px;
text-align: justify;
margin:10px;
}
#block3 {
width:100%;
background-color: brown;
}
#img2 {
width:100px;
height:90px;
margin 0 auto;
}
This is the most standard solution for achieving the layout you want.
Related
I am looking to align my text with this skewed image, but the problem is the text is scrolling. Is there a way to combat this or no?
My goal is to keep the bolded "TITLE HERE" straight across the image but the placeholder text to continue to scroll, but aligning it with the large image to the left. Is this possible? Thanks for your help in advance.
/*BODY STUFF HERE*/
body {
background: WHITE;
background-attachment: fixed;
font-family: montserrat;
}
a {
text-decoration: none;
color: #999;
}
a:hover {
color: indianred;
}
.title {
font-family: montserrat;
font-weight: 900;
font-size: 6vw;
position: relative;
width: 90%;
left: 200px;
margin-top: 0%;
}
.title2 {
font-family: montserrat;
font-weight: 900;
font-size: 1.10vw;
position: static;
width: 90%;
margin-left: 45%;
}
.scrollingtext p {
width: 100%;
padding: 0 10%;
font-size: 13px;
}
/*LEFT PROFILE IMAGE HERE*/
.image {
z-index: -1;
}
.image img {
position: fixed;
width: 50%;
left: -3.5%;
z-index: -1;
-webkit-clip-path: polygon(25% 0%, 100% 0%, 71% 100%, 0% 100%);
clip-path: polygon(25% 0%, 100% 0%, 71% 100%, 0% 100%);
}
/*CELL TABLE STUFF*/
.tablerow {
display: table-row;
width: 100%;
}
.table {
display: table;
}
.cell {
display: table-cell;
}
.right {
width: 50%;
}
.left {
width: 40%;
}
.mobile {
display: none;
}
#media screen and (max-width: 1024px) {
.image img {
width: 100%;
position: relative;
padding: px 5% 0;
margin: 0;
top: 0;
left: 0;
}
h1 {
color: #000;
letter-spacing: normal;
width: 95%;
margin-top: 0;
padding: 0;
margin: 0;
font-size: 70PX;
text-align: center;
font-style: montserrat;
}
.title {
display: none;
}
.cell {
display: block;
}
.desktop {
display: none;
}
.mobile {
display: inherit;
text-align: center;
}
.right {
width: 80%;
margin: 0;
}
.farright {
width: 0;
}
#logo {
height: 25px;
position: absolute;
}
.story {
color: #FFF;
font-family: playfair display;
width: 100%;
height: 200px;
text-shadow: 2px 2px 5px #000;
background-color: #292929;
display: table;
}
.story_inside {
vertical-align: middle;
display: table-cell;
}
.story h2 {
font-size: 40px;
width: 60%;
padding: 0 15%;
margin: 0;
line-height: 35px;
}
.story p {
font-family: montserrat;
margin: 0;
width: 70%;
padding: 10px 15% 0 15%;
}
#media screen and (max-width: 400px) {
h1 {
color: #000;
letter-spacing: normal;
width: 95%;
margin-top: 0;
padding: 0;
margin: 0;
font-size: 40px;
text-align: center;
font-style: montserrat;
}
#media screen and (max-width: 1030px) {
.byline {
font-size: 16px;
width: 100%;
right: 451%;
float: left;
position: relative;
width: 300%;
bottom: -150px;
}
<!--IMAGE GOES HERE-->
<div class="image">
<img src="http://via.placeholder.com/350x1150">
</div>
<div class="scrollingtext">
<!--DESKTOP TITLE AND BYLINE HERE-->
<div class="title">TITLE HERE
<p>
</div>
<div class="title2"><strong>AUTHOR HERE</strong> / TITLE</div>
<!--MOBILE TITLE HERE-->
<div class="table">
<div class="tablerow">
<div class="cell left desktop"></div>
<!--DESKTOP TITLE AND BYLINE HERE-->
<div class="title">
</div>
<div class="cell farright"></div>
</div>
<div class="tablerow">
<div class="cell left desktop">
</div>
<div class="cell right">
<!-- BODY TEXT GOES BELOW HERE -->
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example.</p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. This is a set of placeholder text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. This is a set of placeholder text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. This is a set of placeholder text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. This is a set of placeholder text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. </p>
<p>This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder text to show an example. This is a set of placeholder
text to show an example. </p>
</div>
</div>
</div>
</div>
A simple way to do it would be to make your image float with CSS in the same element as your text.
Like this example;
#my_container {
width: 400px;
text-align: justify;
}
#my_image {
width: 100px;
height: 100px;
float: right;
border: 1px solid #000;
margin: 10px;
}
<div id="my_container">
<div id="my_image">image here</div>
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
And a lot of copy and paste to fill this example.
<div>
Just addd this css to fix the Title
.title{font-family: montserrat;
font-weight: 900;
font-size: 6vw;
width: 90%;
position: fixed;
top: 50%;
left: 10%;}
Yes there is a way to do it but I dont know if your going to like the result when scrolling.
Try this;
Create some empty div that will have the width matching your image and make them float to the left so any text will bump on it.
#container{
width :400px;
height:400px;
border:1px solid #000;
}
.filler{
float:left;
clear:left;
border:1px solid #000;
height:15px;
}
#filler1{
width:200px;
}
#filler2{
width:190px;
}
#filler3{
width:180px;
}
#filler4{
width:170px;
}
#filler5{
width:160px;
}
#filler6{
width:150px;
}
#filler7{
width:140px;
}
#filler8{
width:130px;
}
<div id="container">
<div id="filler1" class="filler"></div>
<div id="filler2" class="filler"></div>
<div id="filler3" class="filler"></div>
<div id="filler4" class="filler"></div>
<div id="filler5" class="filler"></div>
<div id="filler6" class="filler"></div>
<div id="filler7" class="filler"></div>
<div id="filler8" class="filler"></div>
some text to copy and paste and fill the example.
some text to copy and paste and fill the example.
some text to copy and paste and fill the example.
some text to copy and paste and fill the example.
some text to copy and paste and fill the example.
</div>
When i enter text in my div he goes under the picture. If i enter just couple of words DIV floats next to picture. Where is the problem?
.container {
width: 250px;
display: block;
overflow: auto;
}
.container img {
float: left;
}
.inside {
float: left;
}
<div class="container">
<img src="lib/images/asd-261269281.jpg" width="92" height="92">
<div class="inside">text text text text text text text text text text text text </div>
</div>
This will help you..:D
.container {
width: 250px;
display: block;
overflow: auto;
}
.container img {
float: left;
}
.inside {
float: left;
max-width:138px;
}
<div class="container">
<img src="lib/images/asd-261269281.jpg" width="92" height="92">
<div class="inside">text text text text text text text text text text text text </div>
</div>
Put your image as a background. That way you can fill it with text.
Like so:
<div class="container">text text text text</div>
Jsfiddle
This is happening because your text is overflowing the bounds of the defined box when you add more text so it is moved to below the image. There are a couple of different options that you have available here. You can set the width of the inside class so that it will wrap the text instead.
.inside {
float: left;
width: 55%; // Defines the max width of the box before it can wrap vertically.
}
A second method you can use is to set the display type of the .inside class to inline-block:
.inside {
display: inline-block;
width: 55%;
}
I'm a bit of an amateur when it comes to CSS/HTML web stuff but I feel I am learning a lot and am grateful of all the help offered in all the stack overflow questions. I have run into a problem and been searching for a solution for hours already, apologies if this is a duplicate but I honestly couldn't find one.
Basically, I have created a simpler version of what I am working on that demonstrates my issue:
http://jsfiddle.net/qoqq39ss/
.full {
width: 100%;
height: 100px;
background-color: yellow;
}
.mainWide {
width: 80%;
margin: 0px auto;
background-color: grey;
}
#imageBox {
display: inline-block;
width: 35%;
background-color: orange;
}
#image {
width: 80%;
height: 190px;
vertical-align: middle;
}
#textContainer {
display: inline-block;
vertical-align: middle;
width: 65%;
background-color: blue;
}
<div class="full">
</div>
<div class="mainWide">
<div id="imageBox">
<div id="image"></div>
</div><!--
--><div id="textContainer">
<h2>heading</h2>
<p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </p>
</div><!--
--></div>
<div class="full">
</div>
Hopefully that works, first time making my own. I made them different colours to try and highlight the different divs.
The thing is, where the #image is, there would be an image, not a div. The sibling div with text in, as it varies in height due to the width of the window it can be either taller or shorter than the image. When it is taller, I need the image to be vertically centred in relation to the text, when the text is smaller I'd need the text to be vertically centred in relation to the image.
Through my searches I have seen some solutions with using a helper element of height 100% to centre elements in relation to it, though I find when I try that, it makes the helper element 100% of the height of the window as the parent element is of variable height, or maybe I am doing something wrong?
I have also seen there is an option of using tables, though I am not sure if/how that would work as I am planning of using some #media to change the image and text from being inline-blocks to blocks on top of each other for smaller screens if you get what I mean.
Apologies for the long question and if my explanation is a little off.
Many thanks in advance for any help
Since both #imageBox and #textContainer are inline-block elements, you can use
#imageBox, #textContainer {
vertical-align: middle;
}
Currently you are using it on #image, but it has no effect because #image is a block element. You should use it on #imageBox instead.
.full {
width: 100%;
height: 100px;
background-color: yellow;
}
.mainWide {
width: 80%;
margin: 0px auto;
background-color: grey;
}
#imageBox {
display: inline-block;
width: 35%;
background-color: orange;
vertical-align: middle;
}
#image {
width: 80%;
height: 100px;
}
#textContainer {
display: inline-block;
vertical-align: middle;
width: 65%;
background-color: blue;
}
<div class="full">
</div>
<div class="mainWide">
<div id="imageBox">
<div id="image"></div>
</div><!--
--><div id="textContainer">
<h2>heading</h2>
<p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </p>
</div><!--
--></div>
<div class="full">
</div>
Here is what I try to achieve:
With the following HTML:
<div id="my1">
<p> some text </p>
<div id="wrap">Awesome content</div>
</div>
Having this:
text text text text text text text text text text text text text text
text text text text text div id="wrap" text text text text text
text text text text text text text text text text text text text text
Floating divs didn't help me reaching this result so far... (considering height and width for both my1 and wrap are known)?
A fiddle where the text starts from the right side of the wrapped div, when I wish it starts from the left of "my1" div, breaks around "wrap" div.
http://jsfiddle.net/matmat/dxV4X/
Looks like you want something like float:center ? Well, the problem is that this property doesn't exist.
Here are 2 alternatives:
1) Fake it with pseudo elements - FIDDLE - See this css-tricks article
Set up markup like so:
<div>
<div id="wrap">Awesome content</div>
<div id="l">
<p>left text here</p>
</div>
<div id="r">
<p>right text here</p>
</div>
</div>
With CSS
#wrap {
width:250px;
height: 250px;
background: yellow;
position: absolute;
top: 0;
left: 50%;
margin-left: -125px;
}
#l {
float: left;
}
#r {
float: right;
}
#l, #r {
width: 49%;
}
#l:before, #r:before {
content:"";
width: 125px;
height: 250px;
}
#l:before {
float: right;
}
#r:before {
float: left;
}
Alternative #2 (IE 10+ only): CSS Exclusions - FIDDLE
Markup
<div class="container">
<div class="exclusion">Awesome content which floats in the center</div>
<div class="dummy_text">all the text here</div>
</div>
CSS
.container {
font-size: small;
background: aqua;
position: relative;
}
.exclusion {
background-color: lime;
-ms-wrap-flow: both;
-ms-wrap-margin: 10px;
z-index: 1;
position:absolute;
left:0;right:0;
top:0;bottom:0;
width: 150px;
height: 100px;
background: yellow;
margin: auto;
}
For more info about CSS exclusion browser support and further resources see my answer here.
<div id="my1">
<p>some text some text
<span id="wrap">wrapped text</span>
some text some text</p>
</div>
Should work if I am reading the question correctly? A <div> is a block level element which is breaking, a <span> is inline like what you want.
Fiddle here: http://jsfiddle.net/YbuuH/2/
Use css as below:
wrap { word-wrap:break-word; }
This css should work to wrap the text in a line and to continue on next.
I have a repeatable wrapper element with children elements: content element, with left and right elements, all divs.
I want to add some text (ie, "Retired"), rotated by few degrees, like a watermark in the background of content. This can't be a background image, because this text shall be localized (and for maintenance purpose, easier to change a text instead of an image).
Next image shows a disposition of text "Retired" (without showing left and right elements):
Here's the basic HTML layout of this element, it might be useful:
<div class="wrapper">
<div class="leftcolumn">Left column</div>
<div class="content">
<h1>Text Text Text Text Text Text</h1>
<p>Text Text Text Text Text Text Text Text Text</p>
</div>
<div class="rightcolumn">Right column</div>
</div>
And CSS:
.wrapper {
margin: 0 auto;
width: 450px;
display:block;
background-color:#222222;
border-radius: 5px;
}
.content {
float: left;
width: 318px;
padding-left: 5px;
}
.leftcolumn {
width: 50px;
float: left;
}
.rightcolumn {
width: 75px;
float: left;
}
.leftcolumn {
width: 50px;
float: left;
}
.rightcolumn {
width: 75px;
float: left;
}
Here is a working code:
Html
<div id="wrapper">
<div id="leftcolumn">Left column</div>
<div id="content">
<h1>Text Text Text Text Text Text</h1>
<p>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text</p>
</div>
<div id="rightcolumn">Right column</div>
</div>
<div id="textwatermark">
<p>Retired</p>
</div>
CSS
#textwatermark {
color: #d0d0d0;
font-size: 50pt;
-webkit-transform: rotate(-30deg);
-moz-transform: rotate(-45deg);
position: absolute;
width: 100%;
height: 100%;
margin: 0;
z-index: -1;
left:170px;
top:-100px;
}
Check the demo here:http://jsfiddle.net/x6FwG/
You could use transform:rotate(). Check this out http://www.w3schools.com/cssref/css3_pr_transform.asp . You'll have to put an Element inside an Element to get the effect you want.
Note: This won't work in older Browsers, so you may want to just use something like:
background-image:url('location.png');