CSS background compile from 5 part images, size to text - css

I'm currently working on a heading in joomla with background formed from 5 parts of images. Should look like this (just an ASCII example)
{=<Text>=--------}
which is split into
Left ({=<)
Title (Background for the text)
Title-Right (>=-)
Middle (-)
Right (-})
Hope you guys can visualize this. Now, Title and Middle need to be repeated x, but I want Title to size according to the text, supposedly background for the text's div. I can't seems to get the right combination of div and css to do it correctly. Right now I wrap div in div for each part until the text. After the text, they just goes to the next line. display: inline can't help much also. Guess I'm not so good with CSS after all.
Thanks in advance.
NOTE: I can't attach print screen as the images are copyrighted.
EDIT: the Middle part has to expand so that the Right part hits the end, basically occupying the whole width.
|<-----------------------------Full Width of DIV------------------------------->|
{=<Short Text>=------------------------------------------------------------------}
{=<Much Longer Text>=------------------------------------------------------------}
{=<Much Much Much Longer Text>=--------------------------------------------------}
Thanks to Bazzz, I've found a way to do it.
Since Middle when set to width: 100% will reach the right end, so the only way to pull back a little is by using a shorter wrapper. Then place the "Right" part after the wrapper.
HTML
<div id="Header">
<div id="Wrapper">
<span id="Left"> </span>
<h1 id="Title">Title text</h1>
<span id="Title-Right"> </span>
<span id="Mid"> </span>
</div>
<span id="Right"> </span>
</div>
CSS
#Header span, #Header h1 {
display: inline-block;
white-space:nowrap;
overflow: hidden;
width: 570px;
}
#Wrapper span, #Header h1 {
display: inline-block;
white-space:nowrap;//Don't wrap into 2nd line
overflow: hidden;//This help with the 100% width setting
width: 550px;//Header width - "Right" width
}
#Left {
width: 20px;
background: blue;
}
#Title {
background: yellow;
}
#Title-Right {
width: 20px;
background: grey;
#Mid {
width: 100%; //Maximize this
background: green;
}
#Right {
width: 20px;
background: red;
}

Here is my attempt to create what you asked for, see if it matches your requirement:
http://jsfiddle.net/47Aej/
You obviously can replace the background: blue;, background:red; etc. with your images. also feel free to change the "Title text" to see that the yellow part will size according to the text (it is the same h1 in the end).
HTML
<div id="Header">
<span id="Left"> </span><h1 id="Title">Title text</h1><span id="Mid"> </span><span id="Right"> </span>
</div>
CSS
#Header span, #Header h1 {
display: inline-block;
}
#Left {
width: 20px;
background: blue;
}
#Title {
background: yellow;
}
#Mid {
width: 60px;
background: green;
}
#Right {
width: 20px;
background: red;
}

Related

Divs overlapping h1 only in chrome

I am new to web development and am creating a website portfolio. My website is www.laurenschaller.com. Everything is working the way I want it to, except sometimes (not always, if I refresh it goes back to normal) when I open it up in chrome, the two waves that wrap the text "Who I Am" overlap that text, like this http://imgur.com/Zxt7bEE
here is the html:
<div class="wave1div">
<div id="waveBlue1"></div>
<img class="wave1" src="img/loadingwave.png" alt="leftwave">
</div>
<div class="whoIAm">
<h1>WHO I AM</h1>
</div>
<div id="waveBlue2"></div>
<div class="wave2div">
<img class="wave2" src="img/loadingwave.png" alt="rightwave">
</div>
</div>
<!-- Waves end -->
and here is how I styled it:
.waveHeader {
text-align: center;
}
.wave1div, .wave2div, .whoIAm {
display: inline-block;
}
.wave1div, .wave2div, #waveBlue2 {
position: absolute;
top: 270px;
}
.wave1, .wave2{
width: 200px;
position: absolute;
display: block !important;
}
#waveBlue2, #waveBlue1 {
height: 43px;
background: $blue;
position: absolute;
display: inline-block;
text-align: center;
}
#waveBlue1 {
width: 0px;
max-width: 198px;
right:15px;
bottom:-43px;
margin-left: -50px;
}
#waveBlue2 {
max-width: 200px;
}
.prog-bar1, .wave1 {
left: -213px;
}
I apologize if any of that is poorly coded. Like I said, I am very new to learning and appreciate the help.
I would delete the "waves" divs and just leave the heading, like this:
<section class="about">
<h1>WHO I AM</h1>
</section>
Then add the waves as a background for the :before and :after pseudo elements on the heading itself.
.about h1:before, .about h1:after {
content:'';
width:200px;
height:44px;
display:inline-block;
background:url('img/loadingwave.png') no-repeat;
background-color:#86c3c1;
background-size:200px 44px;
}
.about h1:before {
margin-right:30px;
}
.about h1:after {
margin-left:30px;
}
Pseudo elements are very cool and you can do a lot of effects with them. Have a read:
Learning To Use The :before And :after Pseudo-Elements In CSS
A Whole Bunch of Amazing Stuff Pseudo Elements Can Do
Another way that you can do this is by putting the content of your heading inside a span, like this:
<h1><span>WHO I AM</span></h1>
Then you can set the background of the span to white and have the waves as the background for the h1 element:
.about span {
background:#FFF;
}
.about h1 {
background:url('files/wave-orig.png') center repeat-x;
background-color:#86c3c1;
background-size:200px 44px;
}
You have to fix up a lot of your markup if you decide to go the span way though - make your headings block level elements, declare proper heights, adjust your container's width etc.
I'm just telling you about this as another option, but the pseudo element way would be the easiest to implement with your current layout.
By the way, I also noticed that you are using margin-bottom:rhythm on a fair amount of your elements - that's not valid CSS and it doesn't do anything.

Image coloured hover over overflowing

Just a simple image that uses some jQuery to fade some content over the top when moused over.
Only problem is that when the hover over takes effect, the hover spills into the div gutter making the hover over bigger than the actual container.
each image is layed out like so
<li class="large-4 columns item">
<div class="description"><h1>Image hover</h1></div>
<img class="display" src="http://placehold.it/400x300">
</li>
Can see a live example here.
http://jsfiddle.net/QLUMH/
Any ideas on ways to fix/improve what I am doing here? Cheers
Demo
Here you have live example,
you are giving 100% to width and height.
so that really goes overflow.
Code edited-
#portfolio .description {
position: absolute;
background: rgba(0,199,134,0.8);
display: none;
width: 400px;
height: 300px;
}
The issue is that your description fills the entire column, which is wider than your image. If you add an "inner column"/container that collapse to the same width as your image, it will work alright. I've created a fork of your demo that demonstrates this.
I've added a wrapper "ib" (Just stands for inner block. rename this to a proper name) inside each .column.item like so:
<div class="ib">
<div class="description">
<h1>Image hover</h1>
</div>
<img class="display" src="http://placehold.it/400x300">
</div>
And then just created a very simple CSS rule for making this wrapper collapse to its contents:
.ib {
display: inline-block;
position: relative;
}
You did not style your li. The issue is that in foundation.css it is getting padding-left and padding-right. You need to remove that and use margin-left and margin-right instead. And you also need to fix the width of the li. As .description will get its 100% height. So you need to include a small css in your own file (don not modify foundation.css).
#portfolio li.columns{
/* You can use the width in '%' if you want to make the design fluid */
width: 400px;
padding: 0px;
margin: 0px 0.9375em;
}
Fiddle
You'll just have to get rid of the padding on tne li
li{ padding:0 }
or use the the box-sizing property:
`li { box-sizing:border-box; -moz-box-sizing:border-box; }
Change in CSs will help,
I have updated the same in fiddle
with change in CSS,
#portfolio .description {
position: absolute;
background: rgba(0,199,134,0.8);
display: none;
width: 400px;
height: 300px;
}
#portfolio .description h1 {
color: white;
opacity: 1;
font-size: 1.4em;
text-transform: uppercase;
text-align: center;
margin-top: 20%;
width:400px;
height:300px;
overflow:hidden;
}
Update:
If the H1 created extra cutter and wrapping issue(for some), please use the DIV tag instead, which should work fine!
I hope this will solve your problem :)

CSS: Locking the boxes?

___________div class=MAIN_________________
div id=LEFT div id=RIGHT
__________________________________________
How can I achive that all the bottoms of the MAIN + LEFT + RIGHT box are glued together?
Basically locking the bottoms, say if there is a lot of contents in the LEFT box -> the RIGHT box will grow along with the LEFT and MAIN box.
__ follow up __
I don't know how to correctly implement into my code :(
http://jsfiddle.net/v572V/
I have copied the whole CSS file so it looks very messy. But the boxes are as follow
<div class="content home">
<div id="main">
<div id="sidebar">
Do you mean something like this : http://jsfiddle.net/teresko/EkTVv/
This is a variation on so-called "holy grail layout". Should work on all browsers, including IE6. The layout will expand to fit the longest of parts. If content is shorter then browser's height, then layout will extend to the height of the browser.
http://jsfiddle.net/rlemon/DjQup/
you float the left and right columns in the container. then have an 'inner' content container with padding to offset the floats... see the example above.
<div class="container">
<div class="left">asd</div>
<div class="right">asd</div>
<div class="middle">
<div class="middle-inner">
asdf
</div>
</div>
</div>​
.container {
height: 600px;
widht: 800px;
background-color: #aaa;
clear: both;
}
.left, .right {
width: 100px;
height: 100%;
background-color: blue;
}
.left { float: left; }
.right { float: right; }
.middle {
background-color: green;
float: none;
height: 100%;
width: 100%;
}
.middle-inner {
padding: 0 100px;
}
​
it's not perfect but at least you can see the technique in play. gl.

Making two adjacent div's rollover together if you hover over either div

I have created a DIV with two DIV's inside it; A DIV with a rollover image and A DIV below it with text and normal rollover behaviors.
They text describes the image and they are both links to the same place so I want them to both rollover together when the mouse is hovering over either one.
Can anyone tell me how I could do that with just CSS?
Much thanks!
You could put the :hover on the outer <div> and then use that to effect the rollovers on the inner <div>s. For example:
<div class="outer">
<div class="inner-img">
</div>
<div class="inner-text">
Where is pancakes house?
</div>
</div>
And some CSS:
.outer {
width: 200px;
border: 1px solid #000;
}
.inner-img {
width: 200px;
height: 100px;
background-image: url(http://placekitten.com/200/100);
}
.inner-text {
width: 200px;
}
.outer:hover .inner-img {
background-image: url(http://placekitten.com/201/100);
}
.outer:hover .inner-text {
background-color: #dfd;
}
And an example: http://jsfiddle.net/ambiguous/3bXhA/

Split Div Into 2 Columns Using CSS

I have been attempting to split a div into two columns using CSS, but I have not managed to get it working yet. My basic structure is as follows:
<div id="content">
<div id="left">
<div id="object1"></div>
<div id="object2"></div>
</div>
<div id="right">
<div id="object3"></div>
<div id="object4"></div>
</div>
</div>
If I attempt to float the right and left divs to their respective positions (right and left), it seems to ignore the content div's background-color. And other code that I have tried from various websites doesn't seem to be able to translate to my structure.
Thanks for any help!
This works good for me. I have divided the screen into two halfs: 20% and 80%:
<div style="width: 20%; float:left">
#left content in here
</div>
<div style="width: 80%; float:right">
#right content in there
</div>
When you float those two divs, the content div collapses to zero height. Just add
<br style="clear:both;"/>
after the #right div but inside the content div. That will force the content div to surround the two internal, floating divs.
Another way to do this is to add overflow:hidden; to the parent element of the floated elements.
overflow:hidden will make the element grow to fit in floated elements.
This way, it can all be done in css rather than adding another html element.
None of the answers given answer the original question.
The question is how to separate a div into 2 columns using css.
All of the above answers actually embed 2 divs into a single div in order to simulate 2 columns. This is a bad idea because you won't be able to flow content into the 2 columns in any dynamic fashion.
So, instead of the above, use a single div that is defined to contain 2 columns using CSS as follows...
.two-column-div {
column-count: 2;
}
assign the above as a class to a div, and it will actually flow its contents into the 2 columns. You can go further and define gaps between margins as well. Depending on the content of the div, you may need to mess with the word break values so your content doesn't get cut up between the columns.
The most flexible way to do this:
#content::after {
display:block;
content:"";
clear:both;
}
This acts exactly the same as appending the element to #content:
<br style="clear:both;"/>
but without actually adding an element. ::after is called a pseudo element. The only reason this is better than adding overflow:hidden; to #content is that you can have absolute positioned child elements overflow and still be visible. Also it will allow box-shadow's to still be visible.
For whatever reason I've never liked the clearing approaches, I rely on floats and percentage widths for things like this.
Here's something that works in simple cases:
#content {
overflow:auto;
width: 600px;
background: gray;
}
#left, #right {
width: 40%;
margin:5px;
padding: 1em;
background: white;
}
#left { float:left; }
#right { float:right; }
If you put some content in you'll see that it works:
<div id="content">
<div id="left">
<div id="object1">some stuff</div>
<div id="object2">some more stuff</div>
</div>
<div id="right">
<div id="object3">unas cosas</div>
<div id="object4">mas cosas para ti</div>
</div>
</div>
You can see it here: http://cssdesk.com/d64uy
Make children divs inline-block and they will position side by side:
#content {
width: 500px;
height: 500px;
}
#left, #right {
display: inline-block;
width: 45%;
height: 100%;
}
See Demo
You can use flexbox to control the layout of your div element:
* { box-sizing: border-box; }
#content {
background-color: rgba(210, 210, 210, 0.5);
border: 1px solid #000;
padding: 0.5rem;
display: flex;
}
#left,
#right {
background-color: rgba(10, 10, 10, 0.5);
border: 1px solid #fff;
padding: 0.5rem;
flex-grow: 1;
color: #fff;
}
<div id="content">
<div id="left">
<div id="object1">lorem ipsum</div>
<div id="object2">dolor site amet</div>
</div>
<div id="right">
<div id="object3">lorem ipsum</div>
<div id="object4">dolor site amet</div>
</div>
</div>
Best way to divide a div vertically --
#parent {
margin: 0;
width: 100%;
}
.left {
float: left;
width: 60%;
}
.right {
overflow: hidden;
width: 40%;
}
Pure old school CSS
I know this post is old, but if any of you still looking for a simpler solution.
#container .left,
#container .right {
display: inline-block;
}
#container .left {
width: 20%;
float: left;
}
#container .right {
width: 80%;
float: right;
}
If you don't care old browser and need a simple way.
#content {
display: flex;
}
#left,
#right {
flex: 50%;
}
Floats don't affect the flow. What I tend to do is add a
<p class="extro" style="clear: both">possibly some content</p>
at the end of the 'wrapping div' (in this case content). I can justify this on a semantic basis by saying that such a paragraph might be needed. Another approach is to use a clearfix CSS:
#content:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
#content {
display: inline-block;
}
/* \*/
* html #content {
height: 1%;
}
#content {
display: block;
}
/* */
The trickery with the comments is for cross-browser compatibility.
This is best answered here Question 211383
These days, any self-respecting person should be using the stated "micro-clearfix" approach of clearing floats.
Make font size equal to zero in parent DIV.
Set width % for each of child DIVs.
#content {
font-size: 0;
}
#content > div {
font-size: 16px;
width: 50%;
}
*In Safari you may need to set 49% to make it works.
Divide a division in two columns is very easy, just specify the width of your column better if you put this (like width:50%) and set the float:left for left column and float:right for right column.

Resources