Css help - background images and margins - css

im trying to change the custom CSS of my page headers, but every time i try to add a top-margin to one of the nested divs, it moves the entire background image down.
Current code (abridged):
<header id="fancy-header" style="
background-color: #ffffff; background-size: cover;
background-repeat: no-repeat;
background-image: url(http://thegsc.co.il/wp-content/uploads/2014/07/about-header.jpg);
background-position: center center; min-height: 150px">
<div class="wf-wrap">
<div class="wf-table" style="
background:rgba(32,117,200, .6) !important;
margin-top:25px;">
<div class="title">title</div><div class="breadcrumbs">breadcrumbs</div>
</div>
</div>
</header>
Ideally, all Im trying to do is have a background image that spans the entire header (150px), and then a transparent-color overlay on the background text.
Using margin-top:25px because when i tried adding a vertical-align:middle to .wf-table, nothing happened.
Suggestions?

The trouble is that your .wf-table element was not respecting #fancy-header as its parent. The trick is to add float: left and it'll behave in this case as you expect. Check it out here - https://jsfiddle.net/96hf0nqa/
Floats are a little tricky but super important for effective CSS. You can read a lot about them here. Good luck!

If your <header> is the main container to be full-screen then ideally you should be using a grid approach.
Not sure if you use a grid or not? In this case the wf-wrap is your grid-row:
.wf-wrap {
box-sizing: border-box; /* box model fix */
max-width: 94rem; /* 960px - gutter */
padding: 0 1rem; /* grid gutter */
margin: 0 auto; /* to center */
height: 100%;
position: relative; /* to init the absolute offset of it's children */
}
Then your wf-table should be positioned absolute to have full control:
.wf-table {
position: absolute; /* to control top left right bottom */
top: 2.5rem; /* default offset */
z-index: 1 /* if overlap requires it */;
}
DEMO
Typically a grid-row is divided into columns. The position relative belongs on a column actually.
.column {
box-sizing: border-box;
padding: 0 1rem;
float: left;
height: 100%;
position: relative;
}
.g50 { max-width: 50%; width: 100%; }
So your HTML can be made a little bit more generic to gain control on the position of elements inside columns.
<div class="header">
<div class="row">
<div class="column g50">
<div class="wf-table"><!--content here--></div>
</div>
<div class="column g50"></div>
</div>
</div>
DEMO
Additionally there is a way to vertically align a block element in CSS3:
.middle-y {
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-o-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}

Related

How to make a clipped half circle (D shape) using CSS?

I need help understanding clip-path CSS property in order to make my version of a clipped circle below...
More like the design version:
If you can see on the grey background, my circle appears a lot larger and less round when it's clipped.
What can I do to make a more round circle? My ideas were:
Use clip-path as in the snippet below
Use a pseudo :after element or a right border with radius
Cut a circle image from photoshop and use it as a background image.
Preferably, I'd like to avoid using a background image. However, I need to keep responsiveness in mind as the circle cannot change shapes drastically as we resize the window.
Is clip-path the right way to go? Can someone suggest a simpler and elegant solution with another way using CSS?
Thank you in advance, here's a snippet I wrote that illustrates how I clipped the "green/blue" background:
.page-banner {
background: grey;
width: 100%;
height: 300px;
background-position: top;
overflow: hidden;
}
.page-banner-text {
position: absolute;
background: #00525d8a;
padding-left: 100px;
width: 60%;
/* adjustments to snippet */
top: 10px;
left: 10px;
height: 300px;
/* this is the code for circle */
clip-path: circle(560px at left);
padding-right: 250px;
}
<div class="page-banner">
<div class="container">
<div class="page-banner-text">
<h1 class="block-title">Programs For Adults</h1>
<p>Programs to help children with disabilities in Western MA at all ages and levels of need.</p>
<div id="banner-donate-button">DONATE</div>
</div>
</div>
</div>
Per my comment, instead of using clip path to create your D (which is not supported very well), why not use border radius on your div.
* {
box-sizing: border-box;
}
.page-banner {
position: relative;
background: url(https://www.fillmurray.com/300/900) center center no-repeat;
background-size: cover;
width: 100%;
overflow: hidden; /* hide overflowing bits of circle */
min-height: 300px; /* just give enough height to fit text at smallest screen width size */
}
.circle {
background-color: rgba(50, 108, 116, 0.9); /* use rgba for transparent effect */
color: white;
transform: translate(-50%, -50%); /* move the circle left 50% of it's own width and up 50% of it's own height */
border-radius: 50%;
padding-top: 100%; /* this gives us a responsive square */
position: absolute;
top:50%; /* this vertically centers the circle */
left:0;
width:100%;
min-width:600px; /* this is the miniimum dimensions to allow circle to fill smaller screens */
min-height:600px;
}
.page-banner-text {
position: absolute; /* just positions the text on the right of the cirecle */
left: 50%;
top: 50%;
transform: translateY(-50%);
padding:2em;
width:40%;
}
<div class="page-banner">
<div class="circle">
<div class="page-banner-text">
<h1 class="block-title">Programs For Adults</h1>
<p>Programs to help children with disabilities in Western MA at all ages and levels of need.</p>
<div id="banner-donate-button">DONATE</div>
</div>
</div>
</div>
The only problem with it being responsive though is that as the screen gets wider, the D gets flatter (as the radius extends), but you can combat this by adding a max width and height to the circle div
To anyone looking to solve this with the clip-path property, you have a bit more control with the ellipse clip path. Using the code provided by the OP, I replaced circle with ellipse, and switched to percentages to allow for a slightly better responsive feel.
clip-path:ellipse(67% 100% at 8% 50%);
The first two numbers represent the height and width of the ellipse. The larger the first number, the wider the visible area is. The larger the second number, the wider the height. We're aiming for a D shape, so by adjusting the first number, we can make the D more or less prominent.
This is where the second two numbers, the positioning, comes into play. at 50% 50% centers it. By adjusting the first number, the X positioning, we can move it over where need fit . After playing around with the numbers, you should be able to get the D exactly how you'd like.
.page-banner {
background: grey;
width: 100%;
height: 300px;
background-position: top;
overflow: hidden;
}
.page-banner-text {
position: absolute;
background: #00525d8a;
padding-left: 100px;
width: 60%;
/* adjustments to snippet */
top: 10px;
left: 10px;
height: 300px;
/* this is the code for circle */
clip-path: ellipse(67% 100% at 8% 50%);
padding-right: 250px;
}
<div class="page-banner">
<div class="container">
<div class="page-banner-text">
<h1 class="block-title">Programs For Adults</h1>
<p>Programs to help children with disabilities in Western MA at all ages and levels of need.</p>
<div id="banner-donate-button">DONATE</div>
</div>
</div>
</div>
You could simply use
an inner circle element, which you can achieve with a border-radius equal to half the element's height and width
positioned via position: relative with negative top and left values
inside of an outer bounding box, clipped via overflow: hidden
A simple implementation:
#container {
height: 300px;
width: 100%;
background-color: gray;
overflow: hidden;
}
#circle {
height: 600px;
width: 600px;
background-color: rgba(0, 0, 255, 0.5);
position: relative;
top: -150px;
left: -375px;
}
<div id="container">
<div id="circle"></div>
</div>

Adding a shaped border-bottom to the section heading

I am looking for a design like the following screenshot for the section heading. ( The bottom line)
So far I could achieve
h1 {
position: relative;
text-align: center;
width: 100%;
}
h1:after {
content: '';
position: absolute;
width: 100px;
left: 50%;
transform: translateX(-50%);
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
bottom: 0;
border-bottom: 3px solid #8d8f90;
}
<h1 style="text-transform: none">How it works</h1>
Now I want the both end of the border-bottom to be shaped.
Example of using responsive background-image as requested in comments!
So im assuming that the border image will need to be that same length as the text, here is a working example:
div {
text-align: center;
}
h1 {
display: inline-block;
background-image: url(https://ded7t1cra1lh5.cloudfront.net/media/76045/a7fdf291661d9baab9b767d833c70183ba6ee3ce/original/divider-37709_1280.png?1448468523);
height: 120px;
background-repeat: no-repeat;
background-position: center;
background-size: cover/*contain*/
;
}
<div>
<h1 id="_1">I am a header</h1>
</div>
<div>
<h1 id="_2">I am a really really really really long header</h1>
</div>
So in this i grabbed a pretty large image from google as an example so it wouldnt be stretched at larger screen sizes. You will need to use #media screen command to alter the height of the header tag when the text breaks. However this will only be needed on longer headers, and if the header border needs to be the same length as the text. If it doesnt you can use a much shorter image and possibly change the size from cover to contain. The inline block makes it so the background image will always be the length of the text as well.
If you do decide to go this route some minor tweaking to the css should yield you acceptable results. Hope this is helpful as a back up solution Ramesh!

Absolute div inside Relative Div with slide up transition

I am trying to create a display of an element.
The element needs to have an image and an overlay (which contains text). The overlay on hover needs to have a slide up transition on hover. I have achieved this.
But the problem is that the overlay div goes beyond the image div. While it should appear exactly inside of it.
I am using Bootstrap.
The Div in blue should not go beyond the image left and right boundaries and also should be visible when not hovered only 50px. While hovered, the remaining content should be visible.
This is my HTML Code:
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="main-container">
<img class="image" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97300&w=350&h=300">
<div class="content">
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.
Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.
</div>
</div>
</div>
</div>
</div>
This is my CSS Code:
/* Set to 100% of col-md-6 */
.main-container {
width: 100%;
height: 300px;
}
/* Image Container */
.main-container > img.image {
position: relative;
top: 0;
left: 0;
width: 100%;
height: 300px;
z-index: 100;
}
/* Overlay */
.main-container > .content {
width: 100%;
position: absolute;
height: 150px;
bottom: -110px;
left: 0;
right: 0;
z-index: 101;
padding: 10px 20px;
background-color: rgba(52, 152, 219, 0.8);
color: #ffffff;
transition: all ease 1s;
}
/* Overlay Hover */
.main-container > .content:hover {
bottom: 0px;
transition: all ease 1s;
}
FIDDLE
You are using position: absolute, which will position itself relatively to the first parent that also have a position set (other than static), and as you want it to relate to the .main-container, add position: relative; to its rule
Updated based on a comment
Updated fiddle
.main-container {
position: relative; /* added property */
width: 100%;
height: 300px;
overflow: hidden; /* added property */
}

Vertical align: Flexbox VS Table/Table-cell on elements with unknown height

I'm building a website within a CMS. There are quite a few elements that require vertically centered content. However, since I don't have the final content (and whatever content can and will be change in the future) I cannot set a fixed height to those containers.
I just spent a good few minutes trying to figure out why my elements won't vertically align using flexbox...until I found out it's for the lack of a fixed height.
In the past I built such layouts using the display:table/table-cell combination. I started using flexbox models more and more lately and really start to like those and would rather stop using table/table-cell.
Now I wonder how (or if) I could use flexbox to vertically align content no matter what height a container will have.
If your flex container is flex-direction: row (the default orientation), to vertically center content you can use:
align-items: center; /* for a single line of flex items */
align-content: center; /* for multiple lines of flex items */
If your flex container is flex-direction: column, to vertically center content you can use:
justify-content: center;
These methods work without the need to define any heights.
For more details, illustrations, and live demos, see my answer here: https://stackoverflow.com/a/33049198/3597276
From that answer:
Below are two general centering solutions. One for vertically aligned flex items (flex-direction: column) and the other for horizontally aligned flex items (flex-direction: row). In both cases the height of the centered divs can be variable, undefined, unknown, whatever. The height of the centered divs doesn't matter.
May I suggest you use both, like this, as there are still a few IE8/9 users out there and this fallback variant will make it work for them too.
And for other older browser versions that require prefix or use the older flexbox model (like IE10, Safari8/7/6 and some mobile version such as Android, Blackberry, UC Browser), the table version kicks in. More on flexbox support here
html, body {
margin: 0;
height: 100%;
}
.parent {
display: table;
display: flex;
justify-content: center;
/* for this demo */
width: 50%;
height: 50%;
border: 1px solid black;
}
.child {
display: table-cell;
vertical-align: middle;
text-align: center;
display: flex;
align-items: center;
}
<div class="parent">
<div class="child">Centered<br>content</div>
</div>
To vertically center content (or totally centered), you can use CSS transform with translate property. With that method, you don't need to know the size of the element, and combined with a relative parent you achieve a perfect vertical center or horizontal center. See the snippet:
.relative {
position: relative;
width: 400px;
height: 300px;
background-color:yellow;
border: 1px solid black;
margin: 20px 0;
}
.relative .center {
position: absolute;
background-color: black;
color: white;
width: 120px;
height: 150px;
}
.relative .center.vertical {
top: 50%;
-ms-transform: translateY(-50%); /* ie9/ie10 */
-webkit-transform: translateY(-50%); /* safari ios */
transform: translateY(-50%); /* standard */
}
.relative .center.horizontal {
left: 50%;
-ms-transform: translateX(-50%);
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.relative .center.total {
top: 50%;
left:50%;
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<div class="relative">
<div class="center vertical">Vertical center</div>
</div>
<div class="relative">
<div class="center horizontal">Horizontal center</div>
</div>
<div class="relative">
<div class="center total">Total center</div>
</div>

positioning multiple images in various places around the page

Hi I am having problems positioning several images. It is very important that max height of the site stays at approximately 580 pixels as I want to give the impression of a picture frame around the site. I have attached a picture to show how exactly the site is laid out and where I want to position my images in the top, middle and bottom divs. I do not want to have them as background images because I want to have some as links and I want to have some jquery animations (i.e. fadeIn and toggle) with the other images. This is a fluid layout but I do not want the vertical width to expand when the browser is at the min width of 780px, I also would like that the images are some what centred on the page.
I am still learning CSS so I have done the best I can but it is still out of position.
Thanks for your help
Site Layout Picture
.container {
width: 100%;
max-width: 1096px;
min-width: 780px;
margin: 0 auto;}
.header {
background:#231f20;
height: 65px;
}
.sidebar1 {
padding: 0px;
float: left;
width: 65px;
background: #231f20;
margin: 0;
min-height: 450px;}
.sidebar2 {
float: right;
width: 65px;
background:#231f20;
margin: 0;
min-height: 450px;}
.main_content{
padding: 0px;
width: 80%;
float: left;
}
.footer {
height: 65px;
background:#231f20;
position: relative;
}
HTML
<body>
<div class="container">
<div class="header"></div>
<div class="sidebar1"></div>
<div class="main_content">
<div class="top"></div>
<div class=”middle"></div>
<div class=”bottom"></div>
</div>
<div class="sidebar2"></div>
</div>
</body>
Add position: relative to all the containing div's (you may have to set the height of them to the height of the tallest image also). Then position all the images something like:
.img1 { /* or whatever class name works for you */
position: absolute;
left: 50%; /* this centers it, if you want thirds, us 33%, 66%, etc. */
margin-right: -50px; /* note: 50px is an example, it needs to be half the width of your image width */
}
Try adding clear: both; to the CSS for the .footer. This will force it to the bottom of the "picture frame".

Resources