Here is the site I'm currently working on: http://willcrichton.net/
If you click on the arrows on each side of the hexagon in the middle, you can see that it transitions left and right using jQuery + jQuery Cycle + jQuery Easing. However, you can also see that it is rather ugly -- because I'm using hexagons and not squares and because divs are square shaped, the content hexagon overlaps with with the background in an unpleasant way.
So, my question is: how would I essentially hack a div into a hexagon? That hexagon should be the same size/shape of the content div, and when content is outside the area of the hexagon it should be invisible.
Edit:
HTML
<div id="content">
<div class="slide">
<div class="arrow left"></div>
<div class="arrow right"></div>
<div id="websites-title"></div>
<div class="website">
</div>
</div>
<div class="slide">
<div class="arrow left"></div>
<div class="arrow right"></div>
</div></div>
<script type="text/javascript">
$("#content").cycle({
fx: 'scrollHorz',
timeout: 0,
prev: ".left",
next: ".right",
easing: "easeInOutBack"
});
</script>
CSS
/* Container styles */
#container {
width: 908px;
height: 787px;
left: 50%;
top: 50%;
position: absolute;
margin-top: -393.5px;
margin-left: -452px;
background-image: url("images/background.png");
font: 12px "Lucida Sans Unicode", "Arial", sans-serif;
z-index: 3;
}
#content {
width: 686px;
height: 598px;
position: absolute;
left: 50%;
top: 50%;
margin-top: -282px;
margin-left: -343.5px;
/*background-image: url("images/hacky_hole2.png");*/
z-index: 1;
}
.slide {
width: 100%;
height: 100%;
background-image: url("images/content.png");
position: relative;
z-index: 2;
}
UPDATE: If you check the site now, you'd see my failed attempt at using the "window" method and you can see why the z-index did not work.
You can't make a div into a hexagon, but you could use PNG files with alpha transparencies to mask the area you want. So, you would need to make four divs, each with a background that has a PNG file with the transparency that acts as a mask. These divs would be positioned absolutely over your div with the slider.
EDIT: As Pekka noted below, this could also be done with a single, large PNG file acting as a mask.
EDIT #2: Looking at the code you posted, I would revise it like this:
<div id="content"></div>
<div class="slide">
<div class="arrow left"></div>
<div class="arrow right"></div>
<div id="websites-title"></div>
<div class="website">
</div>
</div>
<div class="slide">
<div class="arrow left"></div>
<div class="arrow right"></div>
</div>
Note that I closed the <div id="content"> element. This element should be a sibling of your slides, but be positioned above the slides with a higher z-index. Or, you may need to create a new element dedicated to displaying the mask, if your "content" div is used for other purposes than just displaying the mask.
If it was me developing, I would make that two layer link of yours, into a tree layer...
ex:
1. Layer with the existing background
2. Layer with the gray hexagon
3. Layer with the surrounding words and the surrounding background
Like that, when you click the left and right arrows, the gray hexagon will me sliding in the middle of the 1. and 3. layers, thus preventing that ugliness that you've mentioned :)
Hope it helps!
Eric Meyer's curvelicious concept and demo might point you in the right direction. It's a complicated hack from the "early days of CSS", but it's a powerful technique.
Related
I'm kinda stuck with this small issue that's breaking my layout. On the home page I have a blue box which is serving as my main container. Within my main container there are two more boxes which are on the right side of the screen which contain contact info. Also within the headline-container there is an H2 which say's -- "Satisfaction is our strongest point"
So what's wrong? Well nothing looks wrong atm but what if wanted to accurately center the H2 "Satisfaction is our strongest point" within it's headline-container which is the light blue large rectangle. So I write this CSS to try accurately center the text within headline-container
%align {
position: relative;
top: 50%;
-webkit-transform:translateY(-50%);
-ms-transform:translateY(-50%);
transform:translateY(-50%);
}
Hold my breath and bang crash..
My entire layout breaks..I'm thinking this due to a parenting issue with the H2. In my HTML I am inserting the h2 class just bellow the div class for large-8 columns which in this case is not the correct parent to (center the text within.) The element that I want to center the text within is headline-container (light blue box). To simply put it -- My layout seems to be breaking as soon as I change the h2's parent to headline-container and add the styles above.
Here is the HTML
<div class="headline-container">
<div class="row">
<div class="large-8 columns">
<h2 class="satisfaction">Satisfaction is,</br>Our Strongest Point</h2>
</div>
<div id="contact-info" class="large-4 columns">
<div class="phone-box">
<div class="number">
<a id="phone-number" href="tel:808-848-8821">808-848-8821</a>
</div>
</div>
<div class="email">
<div class="email-box"><a id="email-contact" href="mailto:etoile#hawaii.rr.com">etoile#hawaii.rr.com</a>
</div>
</div>
</div>
</div>
</div>
I've used a temporary not so accurate way of centering my H2 by applying this padding to the text. It looks fine but something deep down tells me it's not 100% accurate and that bothers me..Any suggestions on why my layout is breaking?
padding-top: 40px;
Here's the link
http://kapena.github.io/pp_web/
Thax for reading and I look forward to you're suggestions and comments.
Setting a fixed height to the container (div.columns) of the h2 fixes this.
Example
<div class="large-8 columns">
<h2 class="satisfaction">Satisfaction is,</br>Our Strongest Point</h2>
</div>
CSS
.columns {
height: 218px;
}
.satisfaction {
position: relative;
top: 50%;
transform: translateY(-50%);
}
You could just use h2{text-align: center} or failing that .row{display: block; position: relative; margin: 0 auto; width: 100%;} you dont need the translates
try this for h1 element
h2{
display:inline-block;
margin: 0 auto;
}
How to size/wrap a div container around an image inside It? Where float: right and margin-left: auto are potentially causing issues.
I'm struggling to get a div to be sized by wrapping properly around the image inside it. Please have a look at the example I'm referring to here:
Link to Example
(Might be worth playing around with the window size to help explain my problem)
I'm practicing with Bootstrap for the first time. The red blocks on each side are grid blocks 1 and 12, with the blue, and green sections filling the remaining 10. The big orange rectangles are responsive images that I want to be kept central spaced 20px apart at all times.
Using Chrome's "Inspect Element" (or similar) - If you inspect the orange rectangle on the right hand side, and have a look at the container div (class="container-img-r") - This div is wrapping around the orange image exactly how I wanted (albeit including the invisible border). But I'm not having much luck achieving the same result with the div container for the orange image on the left side (it still fills the blue parent element)
I've played around with different options for float/margins/position but can't seem to crack it.
Here's the CSS I have for the relevent content:
.container-img-l {
/* float:right; ??? Nothing I tried here seemed to make a difference */
}
.container-img-r {
float:left;
}
.item-pos-l {
margin-left:auto;
border-right:10px solid transparent; /* Margins just collapsed when resizing window */
height:323px;
width:510px;
}
.item-pos-r {
float:left;
border-left:10px solid transparent;
height:323px;
width:510px;
}
The reason for me wanting the div to accurately wrap around the responsive images is that I want to overlay some more CSS content over the images, scaling/re-positioning automatically as the window/device size changes (Click here and you'll clearly see where I'm hoping to implement this responsive style).
Maybe there are clashes with the Bootstrap CSS at play but I'm out of ideas.
Your first link doesn't remotely look like the html you want to make responsive. It would be best to learn responsive and fluid (no pixels heights or widths if possible) css before attempting to modify a framework you are unfamiliar with. Also, you have an error in your html - validate it to make sure you've closed all your elements. Also indent and comment all your code and avoid the use of inline styles.
Demo: http://jsbin.com/wazanu/2/
http://jsbin.com/wazanu/2/edit -- edit link
CSS:
body {background:#eee}
.header {padding:20px;}
.portfolio-grid .col-sm-6 {
margin-bottom: 30px
}
.img-wrapper .title {
text-align:center;
}
#media (min-width:768px) {
.img-wrapper {
position: relative;
overflow: hidden;
}
.img-wrapper img {width:100%;}
.img-wrapper .title {
position: absolute;
text-align:left;
bottom: -90px;
padding: 0 20px 20px 20px;
height: 150px;
background: red;
transition: all .5s ease-in-out;
}
.img-wrapper .title h3 {
margin: 0;
height: 60px;
line-height: 60px;
}
.img-wrapper:hover .title {
bottom: 0
}
}
HTML:
<header class="header text-center">
My header
</header>
<div class="container">
<div class="row portfolio-grid">
<div class="col-sm-6">
<div class="img-wrapper">
<img src="http://placekitten.com/g/400/300" class="img-responsive center-block" alt="">
<div class="title">
<h3>Title of Project</h3>
<p>Content about project goes here</p>
</div>
</div>
</div>
<!--/.col-sm-6 -->
<div class="col-sm-6">
<div class="img-wrapper">
<img src="http://placebear.com/g/400/300" class="img-responsive center-block" alt="">
</div>
</div>
<!--/.col-sm-6 -->
<div class="clearfix visible-sm"></div>
<div class="col-sm-6">
<div class="img-wrapper">
<img src="http://placekitten.com/g/400/300" class="img-responsive center-block" alt="">
</div>
</div>
<!--/.col-sm-6 -->
<div class="col-sm-6">
<div class="img-wrapper">
<img src="http://placekitten.com/g/400/300" class="img-responsive center-block" alt="">
</div>
</div>
<!--/.col-sm-6 -->
</div>
<!--/.row-->
</div>
<!--/.container-->
I am building a website with Zurb Foundation. I want to include a DIV. This div will have two columns. The left column will show an image. The second column will hold a paragraph and a button. I want the button to be vertically aligned against the bottom of the grid. In other words, I want the bottom of my button to align with the bottom of my image. Currently, I am trying the following:
<div class="sample">
<h1>This is the title</h1>
<ul class="inline-list">
<li>John Smith</li>
<li>October 12, 2013</li>
</ul>
<div class="row">
<div class="large-5 columns">
<div>
<img src="/images/paper.jpg" style="width:100%;" />
</div>
</div>
<div class="large-7 columns" style="background-color:yellow;">
<p>A paragraph will go here</p>
<a class="button small" href="[someUrl]">
<span>keep reading</span>
<span class="icon-arrow-right5" style="font-weight:lighter; vertical-align:middle;"></span>
</a>
</div>
</div>
</div>
I can't get the "keep reading" button to vertically align with the bottom of the image in the left column. Is there a way to do this in Zurb Foundation? If so, how?
The easiest way to get this done is to float two containers (one for image and one for text) next to each other, with a paragraph text box and a button box inside of the text container.
Give the paragraph box a max-height that would approximate about 70-80% of your image's height (depending on how wide the paragraph box is) and put an overflow:hidden; on it in case your text runs long and you don't want your layout breaking. Place the button below the fixed height paragraph box with a simple top margin and you should be good.
You could align these boxes I've made with Zerb's grid to get this done, but Zerb's grid has horizontal columns only: you'll have to add in these vertical alignments to achieve your goal.
Check the code out here:
http://jsfiddle.net/73fct/2/
HTML:
<div class="container">
<div class="image-box">
<img src="http://nutritionwonderland.com/wp-content/uploads/2010/10/bee-emrank-flickr-300x300.png" width="300" height="300" alt="A Honey Bee" />
</div>
<div class="text-box">
<p class="paragraph">
Bees are an important part of the ecosystem that are increasingly being threatened by pesticides, fungi and a host of other pathogens. Bees are an important part of the ecosystem that are increasingly being threatened by pesticides, fungi and a host of other pathogens. Bees are an important part of the ecosystem that are increasingly being threatened by pesticides, fungi and a host of other pathogens.
</p>
<div class="button">Bees!</div>
</div>
</div>
CSS (backgrounds on the elements are just to show structure for you):
.container {
min-width: 480px;
}
.image-box {
float: left;
position: relative;
}
.text-box {
background: #ffa3d0;
min-height: 300px;
float: left;
position: relative;
width: 180px;
}
.paragraph {
background: #a3cdff;
padding: 10px;
max-height: 205px;
overflow: hidden;
}
.button {
background: #c5ffa3;
margin: 5px auto;
padding: 10px;
text-align: center;
width: 50px;
}
http://tinypic.com/r/9km2v8/5
In the image, you see the floating box. The top left corner of the box (0,0) is aligned with the top of the parent div which is line 3.
I am trying to get the bottom left corner of the floating box to align with the middle of the parent div.
I am using CSS:
.video_desc_box_open {
position: absolute;
left: 500px;
width: 301px;
}
bottom: 0; does not work. It pushes it down very far on the page.
I am open to JS solutions too :)
Thanks!
EDIT: Almost forgot, the height is dynamic.
HTML:
<div class="video_odd">
<div class="video_list_viewed" >
<img src="viewed_no_odd.jpg" />
</div>
<div class="video_list_number">
3
</div>
<div class="video_list_title">
<a id="show-panel" class="show-panel" href="#">Title to vid</a>
</div>
<div class="video_list_desc">
Text goes here
</div>
<div class="video_desc_box">
<img src="desc_box_top.png" />
<div class="video_desc_box_text">
Text for the desc goes here
Run Time:1:21
<br>
Desc goes here
</div>
<img src="desc_box_bottom.png" />
</div>
<div class="video_list_post_date">
02/01/2011
</div>
<div class="video_list_run_time">
1:21
</div>
</div>
I think I kinda understand your question, try this:
#parent_div {
position:relative
}
.video_desc_box_open {
position: absolute;
top:-50%
left: 500px;
width: 301px;
}
if you could provide live code it will be easier to help :)
Add position:relative; to the box's parent then align using bottom.
When i have a div with position: absolute, and in it is another div with position: absolute the inner div will position in the frame given through the outer (wrapper) div.
Now i want to create a class (css) called error_message that positions itself exactly in the center middle of the site, indifferent from where the it is called, so i need it to break out of every div wrapped around the error_message div.. how do i do this?
i had a similar problem with positioning a hoover-text centered below a floated image button list.
for me the solution was using the "fixed" value for the "position" property
position: fixed
then you can position your error message from top left of the body again.
i use another wrapper div to position all hoover texts center center.
found the solution here:
CSS nested Div with position absolute?
the code is not the code from the picture you see, the picture is just for illustration.
stylesheet in less format (see http://lesscss.org/)
<style>
.button
{
float: left;
position: relative;
a
{
&:hover, &:focus
{
.titlePos
{
.title
{
display: block;
}
}
}
.titlePos
{
position: fixed;
top:50%;
left:50%;
width: 400px;
margin-left: -200px;
.title
{
position:relative;
display: none;
top: 130px;
text-align: center;
}
}
}
</style>
html:
<div id="wrapper">
<div id="content">
<ul>
<li>
<div class="button">
<a href="#" >
<div class="buttonImage">
<img />
</div>
<div class="titlePos">
<div class="title">Button Hoover Text1</div>
</div>
</a>
</div>
</li>
<li>
<div class="button">
<a href="#" >
<div class="buttonImage">
<img />
</div>
<div class="titlePos">
<div class="title">Button Hoover Text2</div>
</div>
</a>
</div>
</li>
<li>
<div class="button">
<a href="#" >
<div class="buttonImage">
<img />
</div>
<div class="titlePos">
<div class="title">Button Hoover Text3</div>
</div>
</a>
</div>
</li>
<li>
<div class="button">
<a href="#" >
<div class="buttonImage">
<img />
</div>
<div class="titlePos">
<div class="title">Button Hoover Text4</div>
</div>
</a>
</div>
</li>
</ul>
</div>
</div>
You should try using css's position:fixed property, instead of position:absolute, for the error div. position:fixed will position an element based on the browser window, with no regard for where it falls in the DOM. If you want it to be centered in the window, regardless of window size, you could make the fixed-position div cover the entire screen (left: 0, right: 0, etc). and then text-align the error message inside of it.
I'm not sure why would you want that div to break out of parent div. Maybe try working on a fresh html structure for those?
http://haslayout.net/css-tuts/Horizontal-Centering and http://haslayout.net/css-tuts/Vertical-Centering
These should help you out!
I think the only way to have a div break out of all parent divs is to have an absolute positioning on all of them, which will obviously create its own set of problems.
Why not simply have a pre-defined, hidden div as a direct child of the body, instead of wrapping it in the markup. You can then easily position it as you want, and insert the error messages in it with the help of jQuery. An obvious advantage to this method is that you would only have to write this div once, and dynamically insert the error message into it. I would even suggest having a look at jQuery UI which allows you to easily create dialogs, both normal and modal, besides tons of other features.
UPDATE
Since JS is not allowed, an easy way to do this would indeed be displaying the div only if there was an error. So the PHP code would be ...
if (isset($error)) {
echo '<div class="show_error">' . $error . '</div>';
}
... and the CSS class for it would be ...
.show_error {
width: 400px; // error element's width
height: 200px; // error element's height
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px; // minus half the height
margin-left: -200px; // minus half the width
}
Of course, you can further style the error div as you wish, but these are needed to position it dead-center.
Hope this helps !
I have found a solid CSS solution here:
https://front-back.com/how-to-make-absolute-positioned-elements-overlap-their-overflow-hidden-parent/
Let’s add another parent and move the position:relative one level up
(or, in your context, you could maybe simply use an existing upper
parent).
HTML
<div class="grand-parent">
<div class="parent">
<div class="child"></div>
</div>
</div>
CSS
.grand-parent {
position: relative;
}
.parent {
/*position: relative;*/
overflow: hidden;
}
.child {
position: absolute;
top: -10px;
left: -5px;
}
Result: