I have div content-3 which is inside container. I want to make this background color 100% for his height which may increase. I think this possible using css. Here is image of my requirement.
*{padding:0; margin:0; box-sizzing:border-box;}
.container{margin: 0px auto; width: 80%; border: 1px solid #333;}
.content{min-height:50px}
.content-3{background:green}
<div class="container">
<div class="content content-1">content 1</div>
<div class="content content-2">content 2</div>
<div class="content content-3">content 3</div>
<div class="content content-4">content 4</div>
</div>
As an alternative answer you could use the :before and :after pseudo-elements to achieve the same effect.
No changes to the HTML.
Add this to your CSS:
.content.content-3 {
position: relative;
}
.content.content-3:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: -10vw;
right: 100%;
background: green;
}
.content.content-3:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 100%;
right: -10vw;
background: green;
}
Edit: Changed -100% to -10vw for left/right positions. vw means viewport width so given your container is 80% wide, you want each side to extend 10vw to make the full 100% with no horizontal scrolling.
As a visual trick, you can add extra padding to the div and counteract using negative margins. However you have to add overflow-x:hidden to body to prevent horizontal scroll:
*{padding:0; margin:0; box-sizzing:border-box;}
.container{margin: 0px auto; width: 80%; border: 1px solid #333;}
.content{min-height:50px}
.content-3{
background:green;
padding-left:100%;
padding-right:100%;
margin-left:-100%;
margin-right:-100%;
}
body{overflow-x:hidden}
<div class="container">
<div class="content content-1">content 1</div>
<div class="content content-2">content 2</div>
<div class="content content-3">content 3</div>
<div class="content content-4">content 4</div>
</div>
If you're able to create multiple container elements you could do something like:
<div class="container">
<div class="content content-1">content 1</div>
<div class="content content-2">content 2</div>
</div>
<div class="container-wrapper">
<div class="container">
<div class="content content-3">content 3</div>
</div>
</div>
<div class="container">
<div class="content content-4">content 4</div>
</div>
Then just make container-wrapper full-width with a green background.
Related
For the following HTML list I want to make only it only vertically scrollable and horizontally it should be visible by default.
Even after giving overflow-x as visible it is treating as scroll
<div class="container">
<div class="inner-container">
<div>Item 1</div>
<div class="hover-arrow"></div>
</div>
<div class="inner-container">
<div>Item 2</div>
<div class="hover-arrow"></div>
</div>
<div class="inner-container">
<div>Item 3</div>
<div class="hover-arrow"></div>
</div>
<div class="inner-container">
<div>Item 4</div>
<div class="hover-arrow"></div>
</div>
</div>
.container {
width: 100px;
overflow-y: scroll;
overflow-x: visible;
border: 1px solid black;
height: 200px;
}
.inner-container {
position: relative;
height: 100px;
background: grey;
}
.hover-arrow {
position: absolute;
right: -20px;
bottom: 0;
border-left: 20px solid grey;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
}
JS fiddle for the same
https://jsfiddle.net/m148ujcn/
According to W3Specs:
The computed values of ‘overflow-x’ and ‘overflow-y’ are the same as their specified values, except that some combinations with ‘visible’ are not possible: if one is specified as ‘visible’ and the other is ‘scroll’ or ‘auto’, then ‘visible’ is set to ‘auto’. The computed value of ‘overflow’ is equal to the computed value of ‘overflow-x’ if ‘overflow-y’ is the same; otherwise, it is the pair of computed values of ‘overflow-x’ and ‘overflow-y’.
In short:
If we set overflow-x or overflow-y to visible and something else for
the others, then visible value gets treated as auto
Made some changes in your fiddle check this: JSFiddle
<div class="wrapper">
<div class="container">
<div class="inner-container">
<div style="padding: 20px 20px 20px 30px;">Item 1</div>
<div class="hover-arrow"></div>
</div>
<div class="inner-container">
<div style="padding: 20px 20px 20px 30px;">Item 2</div>
<div class="hover-arrow"></div>
</div>
<div class="inner-container">
<div style="padding: 20px 20px 20px 30px;">Item 3</div>
<div class="hover-arrow"></div>
</div>
</div>
</div>
What does my css for fixed-left, fixed-right and content have to be such that the left and right divs are fixed, the content div is max width less the width of the two fixed width div and that the divs don't roll one under the other even if the width of the screen is less than (fixed-left.width + fixed-right.width)?
<div class="row" id="row01">
<div class="fixed-left">
<div class="fixed-left-a">001</div>
<div class="fixed-left-b">Item 1</div>
</div>
<div class="content">
<div class="row">
<div class="col-xs-4 col-md-3">1,234</div>
<div class="col-xs-4 col-md-3">1,234</div>
<div class="col-xs-4 col-md-3">1,234</div>
<div class="col-xs-4 col-md-3">1,234</div>
</div>
</div>
<div class="fixed-right">
<span>A</span>
</div>
</div>
<div class="row" id="row02">
...
</div>
I want to use bootstrap 3 grid within the main content, but have fixed attributes of every row that don't require the left and right pieces to be variable sized.
Edit:
I want the output to look something like the attached image.
You can use calc to set the width of the content
.fixed-left, .fixed-right {
position: fixed;
width: 100px;
top: 0;
bottom: 0;
}
.fixed-left {
left: 0;
background: yellow;
}
.fixed-right {
right: 0;
background: purple;
}
.content {
background: pink;
width: calc(100% - 200px);
margin: 0 auto;
height: 100vh;
}
<div class="row" id="row01">
<div class="fixed-left">
<div class="fixed-left-a">001</div>
<div class="fixed-left-b">Item 1</div>
</div>
<div class="content">
<div class="row">
<div class="col-xs-4 col-md-3">1,234</div>
<div class="col-xs-4 col-md-3">1,234</div>
<div class="col-xs-4 col-md-3">1,234</div>
</div>
</div>
<div class="fixed-right">
<span>A</span>
</div>
</div>
see the snippet in full-page and try to resize the browser window
you set margin to content margin: 0 100px; like this.
Here 100px is your fixed element width.
* {
margin: 0;
padding:0;
box-sizing:border-box;
}
.fixed-left, .fixed-right {
position: fixed;
width: 100px;
top: 0;
bottom: 0;
}
.fixed-left {
left: 0;
background: yellow;
}
.fixed-right {
right: 0;
background: purple;
}
.content {
background: pink;
width: 100%;
margin: 0 100px;
height: 100vh;
}
<div class="row" id="row01">
<div class="fixed-left">
<div class="fixed-left-a">001</div>
<div class="fixed-left-b">Item 1</div>
</div>
<div class="content">
<div class="row">
<div class="col-xs-4 col-md-3">1,234</div>
<div class="col-xs-4 col-md-3">1,234</div>
<div class="col-xs-4 col-md-3">1,234</div>
</div>
</div>
<div class="fixed-right">
<span>A</span>
</div>
</div>
https://stackoverflow.com/a/29532261/2193381 offers a very simple solution that appears to work. It is not the approach I had in mind, and may have unintended effects, but is interesting nonetheless.
In short, pull-left and pull-right the fixed width divs before the central floating width div is set.
I have four tabs developed with HTML5/CSS3/JS shown below.
I have used display:inline-block; for tab divs and text-align:center for their parent div to locate all four tabs at the center of the page.
<div class='parent'>
<div class='tabItem'>YOU</div>
<div class='tabItem'>DATABASE</div>
<div class='tabItem'>TASKS</div>
<div class='tabItem'>HELP</div>
</div>
CSS3:
.parent{text-align:center;}
.tabItem{display:inline-block;}
Now I want to locate two of the tabs i.e. YOU and HELP at the right-side of the page, and the rest of the tabs i.e. DATABASE and TASKS at the center of the page. I wonder how I can do that.
It's preferred to have div elements follow the natural flow of the page.
Do something like this
.parent{text-align:center;}
.tabItem{display:inline-block;}
.right{float:right;}
.left{float:left;}
<div class='parent'>
<div class='tabItem left'>Content for Left</div>
<div class='tabItem'>DATABASE</div>
<div class='tabItem'>TASKS</div>
<div class='tabItem right'>YOU</div>
<div class='tabItem right'>HELP</div>
</div>
here is your solution!
.parent{text-align:center;}
.tabItem{display:inline-block;}
.right {
float: right;
}
<div class='parent center'>
<div class='tabItem'>DATABASE</div>
<div class='tabItem'>TASKS</div>
<div class='parent right'>
<div class='tabItem'>YOU</div>
<div class='tabItem'>HELP</div>
</div>
</div>
Hope this helps!!
<html>
<head>
<style>
.parent{text-align:center;}
.tabItem{display:inline-block;}
#right {float: right;}
</style>
</head>
<body>
<div class='parent'>
<div class='tabItem'>DATABASE</div>
<div class='tabItem'>TASKS</div>
<div id="right" class='tabItem'>YOU</div>
<div id="right" class='tabItem'>HELP</div>
</div>
</body>
</html>
Or just put those two divs in a parent container and give it an id="right" to avoid repeating id !!
I think you will need to set the tabs you need to relocate to absolute position, so they will be out of the normal content flow, then you can truly center the other two tabs.
.parent {
background: pink;
text-align: center;
position: relative;
}
.tabItem {
margin: 0 5px;
display: inline-block;
background: aqua;
}
.tabItem:nth-child(1) {
position: absolute;
right: 50px; /* width of "HELP" tab */
}
.tabItem:nth-child(4) {
position: absolute;
right: 0;
}
<div class='parent'>
<div class='tabItem'>YOU</div>
<div class='tabItem'>DATABASE</div>
<div class='tabItem'>TASKS</div>
<div class='tabItem'>HELP</div>
</div>
CSS3 feature display:flex is an option too. Can play around with it to see if it would work.
.parent{
display:flex;
justify-content:center;
}
.item{
padding: 10px;
text-transform:uppercase;
}
.right{
margin-left:auto;
}
.left{
margin-right:auto;
}
<div class="parent">
<div class="item left">you</div>
<div class="item">database</div>
<div class="item">tasks</div>
<div class="item right">help</div>
</div>
I have some content at the top of a fixed (it has to be positioned relative to the viewport) div and a (scrollable) list below.
I want the list to start at the bottom of the sibling elements, and end at the bottom of the fixed parent element. I could use top: 123px;, but the top content is of variable height (same for height:calc(100%-123px); and margin).
There is something in every position that makes them unsuitable for this job (eg: absolute elements do not take siblings into account).
Fiddle (borders and margins aren't needed)
#fixed-wrapper {
border: 1px solid blue;
position: fixed;
top: 32px;
bottom: 30px;
left: 5px;
right: calc(30%-5px);
}
#fixed-wrapper .scrollable-list {
position: absolute;
overflow-y: scroll;
top: 50px;
bottom: 0px;
color: red;
border: 1px solid red;
}
.some-bar, .some-other-bar {
border: 1px solid green;
margin: 2px;
padding 2px;
}
<div id="fixed-wrapper">
<div class="some-bar">some variable length text</div>
<div class="some-other-bar">some image or text</div>
<div class="scrollable-list">
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
</div>
</div>
How could I make this design work? Or, alternatively, how could I possibly reorganize the DOM (or use other tags, ugly tables maybe) to have these properties?
Edit: the solution only needs to work under Chrome.
You can do it using javascript like this: https://jsfiddle.net/DIRTY_SMITH/komfhjdj/3/
<div id="fixed-wrapper">
<div id="varHeight" class="some-bar">some variable length text</div>
<div id="staticHeight" class="some-other-bar">some image or text</div>
<div class="scrollable-list" id="list">
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
</div>
</div>
<script>
var sHeight = document.getElementById('staticHeight').offsetHeight;
var vHeight = document.getElementById('varHeight').offsetHeight;
var totalHeight = sHeight + vHeight;
totalHeight = totalHeight + 6;
document.getElementById("list").style.top = totalHeight + "px";
</script>
You could use CSS3 flexbox. I added <div class="scrollable-wrapper"> to make it possible for the layout you are trying to achieve.
See the comments inside the code snippet, it's quite easy to understand. So flex: 1; means flex-grow: 1; to take all space available.
https://jsfiddle.net/komfhjdj/1/
#fixed-wrapper {
border: 1px solid blue;
position: fixed;
top: 32px;
bottom: 30px;
left: 5px;
right: calc(30%-5px);
display: flex; /*added*/
flex-direction: column; /*added*/
}
.scrollable-wrapper {
position: relative; /*added*/
flex: 1; /*added*/
}
.scrollable-list {
position: absolute;
overflow-y: scroll;
top: 0; /*updated*/
bottom: 0;
color: red;
border: 1px solid red;
}
.some-bar, .some-other-bar {
border: 1px solid green;
margin: 2px;
padding 2px;
}
<div id="fixed-wrapper">
<div class="some-bar">some variable length text</div>
<div class="some-other-bar">some image or text</div>
<div class="scrollable-wrapper"> <!-- added this div -->
<div class="scrollable-list">
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
<div class="list-item">item2</div>
<div class="list-item">item1</div>
</div>
</div>
</div>
I am currently building a wordpress site, where I need a 100% width background (css color, no image) for a div. My div is inside a container and I can't modify the html. So, I was wondering if there was any way with css to do this. I have already tried the padding+margin hack, but it didn't work.
HTML:
<div class="container">
<div class="row-fluid">
<div class="main span12">
<div class="row-fluid blue"> <!--this is the div that needs the background-->
<div class="span4">some content</div>
<div class="span4">some content</div>
<div class="span4">some content</div>
</div>
<div class="row-fluid">
<div class="span12"> some other content, doesn't need the background</div>
</div>
</div>
</div>
</div>
Any help is much appreciated. I tried this one : http://www.sitepoint.com/css-extend-full-width-bars/ but it didn't work.
Based on this article from CSS Tricks (Full Width Browser Bars ).
HTML
<div class="container">
<div class="level"></div>
<div class="level purple"></div>
<div class="level"></div>
</div>
CSS
html, body {
overflow-x: hidden;
}
.container {
width:960px;
margin: 0 auto;
border:1px solid black;
}
.level {
height:100px;
background: #bada55;
}
.purple {
position: relative;
background: #663399;
}
.purple:before,
.purple:after {
content: "";
position: absolute;
background: #663399; /* Match the background */
top: 0;
bottom: 0;
width: 9999px; /* some huge width */
}
.purple:before {
right: 100%;
}
.purple:after {
left: 100%;
}
Codepen Demo
Support should be IE8 & up