how to override main containers max-width using css - css

I'm working on a wordpress blog template, which has a main container:
.container {
width: 100%;
max-width: 1040px;
On one page I need to have an image, that will be a full size background image: 100% of available width. But no matter what I do, I can't get the image to go outside of the template main container (1040px). Any ideas?

While its possible using absolute positioning to get an image outside the container it was made in, why would you want to do that when you can just use CSS backgrounds!
So I'm assuming you have a container inside a bigger container.... what you want to do is set the image to be the background of the bigger container like this (i'm doing this assuming the container it is in is the whole page... but it can be any div) :
html {
background: url(YOURIMAGE.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Edit Ok I see what you want to do. You want a nested div to have 100% page width right?
#wrapper {
width: 100px;
margin-left: auto;
margin-right: auto;
}
.item {
height: 300px;
background-color:#0000FF;
width:100%;
}
.fullblock {
position: absolute;
width: 100%;
z-index: -1;
background-color: #FF0000;
height:300px;
left:0;
right:0;
}
<div id="wrapper">
<div class="item">
<div class="fullblock">
</div>
</div>
</div>
This will allow your nested div to burst out of its container.

Related

Fully display background image

I'm setting up a site, and want to create a responsive background image but I'm getting only single line with background image. What property should i need to use to make the entire background image to fit?
I created 2 files,
index.html :
<div id="logo">Test</div>
style.css :
#logo {
background-image: url("bg.png");
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
I tried many times but only single line gets background image. I want the background image to be fully displayed on screen without using height property which i think makes site less responsive.
you should change the height of logo div and set it as full height by adding height:100% for the body and logo div, your code should look like below code
html, body
{
height: 100%;
}
#logo {
background-image: url("bg.png");
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
height:100%;
}
If you want the image to have the same height as the screen you can use height:100vh. But if you want only the image full size you can do this like this :
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#image{
max-height: 100%;
max-width: 100%;
}
#text{
position: absolute;
color: white;
top: 0
}
<img id="image" src="https://images.unsplash.com/photo-1528920304568-7aa06b3dda8b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80">
<div id="text">test</div>

I would like to get a whole image as my header

Hey,
I would like to get a whole image, in the width of the browser, as my header.
But the thing is, i get a horizontal scroll bar, and I don't want that.
What I want is that the image adjust if the browser also adjust.
Is this possible with css?
Sorry for my bad english.
This is my code
#header {
Margin-left:auto;
Margin-right:auto;
heigth:400px;
position: center center;
min-width: 100%;
max-width: 1024;
}
<body>
<div id="header">
<img src="header.png" />
</div>
You could chose to set your image as background image and use background-size: cover; like this:
#header {
width: 100%; height 400px;
margin: 0 auto;
background: url("../header.png");
background-size: cover;
}
<div id="header"></div>
You can find more explanation about background-size here:
http://www.css3.info/preview/background-size/
Try.
#header {
max-width: 100%;
background:#ffffff url("header.png") repeat-x;
}
You may be looking for a background cover:
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Using the cover method will scale the images to fill the container.
You can set #header img { max-width: 100%; }
Hmm, if i do a background-image, the image itself does not show up. Maybe beacause its 1400px in width, can css crop this for each diffrent width of the browser witout any horizontal scrolling bar.

CSS 100% height with sidebar and content (divs within)

I've asked this question before and got a solution but as I work my way into it, I found out that the solution wasn't the best (the suggestion was to set both into display:table-cell)
As I add in divs within, the height changes and the layout gets out of hand.
what I want is really simple, something like the image shown
[EDIT : this is the main reason why i'm having problem, i'm trying to add a div to include a shadow ]
I want the textured BG to stretch all the way, as tall as how the page would be (so as the content varies the textured bg would follow)
So I made something such as
<body>
<div id="page">
<div id="sidecolumn">
<div id="sidebar"></div>
</div>
<div id="maincolumn">
<div id="content"></div>
</div>
</div>
</body>
by setting all the divs and body style to have height:100%; but the problem is that as my content stretches beyond the page limits (a scroll bar appears) the textured BG doesn't flow over, it just stop at where it was. Say the screen is of 800px tall, if the content goes beyond and reaches 1000px, the textured bg stops at 800px.
As I tried what was recommended for me by using display:table-cell, the textured bg flows with the content, but I can't add in my side bar because when I do, there will be a blank space above the content div. Any suggestion on how I should handle this problem?
EDIT: Using Xun Yang's approach would work. It's just, as he put it himself, unconventional ;)
The fiddle: http://jsfiddle.net/Nu2wH/
html, body {
height: 100%:
padding: 0;
margin: 0;
}
#page {
background: #444444;
min-height: 100%;
height:auto !important;
height:100%;
overflow: hidden !important;
background: url("http://upload.wikimedia.org/wikipedia/commons/3/3e/Social_icons-google-22x22.png?uselang=de") repeat;
}
#sidecolumn {
width: 45%;
padding-left: 5%;
padding-top: 5%;
padding-bottom: 5%;
float: left;
}
#sidebar {
background: #ddd;
}
#maincolumn {
padding: 5%;
width: 40%;
float: right;
background: #AA9933;
height: 100%:
}
#content {
background: #ddd;
}
​
You Can Use the css 3 declaration background-size, for all browsers
background: url(images/bg.jpg) no-repeat center center fixed; //fallback for unsupported browsers and sets the background image
-webkit-background-size: 100% 100%;
-moz-background-size: 100% 100%;
-o-background-size: 100% 100%;
background-size: 100% 100%;
#page
{
background:url(images/bg.png);
width:200px;/*Width of your sidebar*/
}
#maincolumn
{
margin-left:200px;/*width of your sidebar*/
}
Not very conventional but works :)

centering a div inside of a div with background-size: cover property

I want to center an image on top of my background image.
#home is the background image that stretches to the size of the browser
#hometitle is the image i want on top
I would like to center #hometitle on top of my #home background so no matter the size of the browser, it'll be spaced into the center of the background image.
I have tried margin: 0 auto; and then margin-top: 250px; right after, but that just creates a white gap above the entire background image of 250px;
Position: absolute; and top/left don't really help because the position will be static and not be center as you resize the browser.
#home {
height: 1000px;
margin: 0 auto;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-image: url("images/bigheader.png");
}
#hometitle {
background-image:url(images/title.png);
height: 260px;
width: 435px;
}
HTML:
<div id="home">
<div id="hometitle">
</div>
</div>
#hometitle {
background-image:url(images/title.png);
height: 260px;
width: 435px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -130px;
margin-left: -217px;
}
This should do since we postion the home title image absolutely at the center of the browser rendering space.
If you are having some issues with the position of image add
body {position: relative;}
This is one of the easiest and best techniques to position an element at the center that i use often
You can't use margin-top to move the <div id="hometitle"> down relative to the <div id="home"> because of margin collapsing, but you could add top padding on the <div id="home"> instead.

Slide div below an absolute positioned div

http://jsfiddle.net/FUqhb/
I need to move the player so that it always stays below the cd cover.
I can't change the html (I can add things but I can't change the order or delete stuff inside) and I can't set a fixed margin-top for the player. Other than that, any ideas?
I tried display:block but it doesn't work, probably because it's an absolute positioned div.
jsFiddle: http://jsfiddle.net/FUqhb/11/
You can add a div with height:200px which will push the bar down.
<div class="audio_player">
<div style="height:200px"></div>
<embed type="application/x-shockwave-flash" src="http://assets.tumblr.com/swf/audio_player_black.swf?audio_file=somefile.mp3" height="27" width="207"/>
</div>
Turn off absolute positioning of the sleeve:
.turntable {
width: 100%;
height: 200px; /* cd height */
position: relative;
}
.artwork,
.gloss,
.sleeve {
width: 100%;
height: 100%;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
.gloss {
background: url('http://i.imgur.com/JrVdR.png');
position:absolute;
top:0;left:0
}
.sleeve {
background: url('http://i.imgur.com/VjVh1.jpg') no-repeat;
width: 200px; /* cd width */
}

Resources