I made an image to easier explain what Im after:
Image Illustration http://bayimg.com/image/eabahaaci.jpg
Ive read some other questions on the subject but Im not sure the solutions will work for me because my div needs to be expandable and grow as more content is added.
Does anyone know how to accomplish this in a simple way?
#body {background: transparent url(background/image.png) 0 0 repeat-y;
}
#content-wrap {width: 60%;
margin: 0 auto;
background: transparent url(partially/transparent/60percent-opaque.png) 0 0 repeat;
}
#main-content {width: 90%;
margin: 1em auto 0 auto;
background-color: #fff;
}
#footer {width: 90%;
margin: 1em auto 0 auto;
background-color: #fff;
}
This sets a partially-transparent .png image as the background for the #content-wrap section, with a solid color background for the divs (I've used #main-content and #footer, but they've got the same style so you could just use #content-wrap div and shorten the css a little.
<div id="content-wrap">
<!-- this is the outer wrapping div -->
<div id="main-content">
<!-- this I'm assuming is the main content portion -->
</div>
<div id="footer">
<!-- the name explains my assumption, I think... -->
</div>
</div>
body {
background: #fff url(http://i.stack.imgur.com/9uIxu.png) 0 0 repeat;
}
#content-wrap {
width: 60%;
margin: 1em auto;
padding: 1em 0;
background-color: rgba(0, 0, 0, 0.3);
-moz-border-radius: 1em;
-webkit-border-radius: 1em;
}
#content-wrap div {
width: 90%;
margin: 1em auto;
background-color: #fff;
}
#content-wrap div p {
margin: 1em 0;
}
<div id="content-wrap">
<div id="main-content">
<p>I presume the main content will sit here...</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
quis, sem. Nulla consequat massa quis enim.</p>
<p>Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean
vulputate eleifend tellus.</p>
<p>Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue.
Curabitur ullamcorper ultricies nisi.</p>
<p>Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus.
Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit
cursus nunc,</p>
</div>
<div id="footer">
<p>This'd be the footer. And so on...</p>
</div>
</div>
...if you know that your audience will be using FF3.x (and probably webkit based browsers), you could use background-color: rgba(0,0,0, 0.6); to define the background-colour (red=0, green=0, blue=0, alpha=0.4 or 40% opaque (or 60% transparent) -the values being between 0 (entirely transparent) and 1 (entirely opaque).)
Using the rgba for colour prevents problems from using opacity to make the parent div transparent, while trying to make the children visible. But it's got limited use because of browser adoption, of course...
A working demo is over at my site: http://www.davidrhysthomas.co.uk/so/transparent.html
You will need an 1px high image slice for the transperncy
and one for the rounded corders at the bottom
.background{
background:url(/image/path);
}
.wrapper{
background:url(/image/path/trans.png) repeat-y;
width:500px;
position:relative;
}
.wrapper .bottom{
background:url(path/to/image) no-repeat;
position:absolute;
bottom:0;
left:0;
height:20px;
}
.inner{
background:#fff;
margin:10px;
}
I have made the widths and margins up. You should put in the right sizes yourself
Related
The ::before selector doesn't extend vertically in a fixed element.
Is there a way to make the background fill the whole height? Now, when a user scrolls, the ::before elemeent stops as soon as the user has scrolled outside the viewport.
Preferably a non-javascript way.
Thanks in advance.
NB: I'm using SASS, feel free to provide an answer in SCSS or just plain CSS.
Full code: https://jsfiddle.net/u7fvb2nq/
Snippet:
.outer
position: fixed
&::before
content: ''
position: absolute
left: 0
top: 0
bottom: 0
right: 0
background-image: linear-gradient(rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.3))
You can use position fixed for :before pseudo element.
.outer{
position: fixed;
background: url('https://images.unsplash.com/photo-1473830394358-91588751b241?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60');
width: 100%;
height: 100%;
overflow-y: auto;
padding: 30px;
}
.outer:before{
content: '';
position: fixed;
left: 0;
top: 0;
bottom: 0;
right: 0;
background-image: linear-gradient(rgba(255, 255, 255, 0.5) , rgba(255, 255, 255, 0.4));
}
.outer p{
color: #fff;
font-family: sans-serif;
max-width: 400px;
font-size: 2rem;
}
<div class="outer">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eu dignissim felis, sit amet ultricies justo. Praesent consequat at nulla nec eleifend. Sed convallis, metus non pellentesque elementum, nunc arcu condimentum leo, sit amet pellentesque turpis augue ac sapien. Phasellus facilisis lacinia mauris at consectetur. Morbi sapien augue, condimentum vel erat vitae, semper rutrum erat. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum porttitor pharetra faucibus. Donec lobortis massa id dui porta aliquam. Integer eu velit lacinia, cursus libero in, vulputate ligula. Ut ut vestibulum nunc. Nulla facilisi. In turpis augue, luctus pellentesque nibh vel, ullamcorper feugiat orci. Mauris ut metus nec mauris venenatis viverra ut eu mi. Integer quis sem sed tortor dignissim lobortis et at dui. Proin pretium id lectus non semper.dfsdf</p>
</div>
I'm encountering a problem when trying to pad a div with overflow: hidden with two child divs where the content overflows the bottom of the padding if the parent doesn't have a height set, despite a max-height being set. On top of that, using overflow: hidden on the child div causes it to act like it's display: inline-block where the content doesn't flow around its sibling that's float: left. Below is my example case.
Descriptive picture of example case
So my two main questions are, is there a way to achieve the child div (.content) growing until it reaches the max-height of the parent without overshooting, primarily so that the child div will be hidden by the parent's padding? And is overflow: hidden on .content supposed to cause .content to behave oddly when the text wraps or is that a bug?
.wrapper {
max-height: 150px;
/* height: 150px; /* Required for .content to get correct height. Why isn't max-height sufficient? */
overflow: hidden;
padding: 25px;
border: 1px solid #000;
}
.left {
float: left;
border: 1px solid #000;
}
.content {
/* height: 100%; /* Doesn't do anything if the parent has no height set. */
max-height: 150px; /* Resolves not being able to inherit the parent's height. */
overflow: hidden; /* <- Required to hide overflow text but causes odd text wrapping behavior. */
}
<div class="wrapper">
<div class="left">
Left
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla aliquam quam sit amet neque ullamcorper varius. Aliquam porta, nulla a accumsan laoreet, ipsum nibh rhoncus lectus, sit amet placerat nibh felis ut leo. Nam in turpis at felis rutrum euismod a a sem. Donec efficitur lorem non vehicula luctus. Nulla pulvinar ultrices blandit. Donec ipsum arcu, tempus nec vulputate quis, porta nec sapien. Curabitur pellentesque, felis ut suscipit sodales, risus arcu consequat odio, vel porta ligula leo et quam. Praesent quam nisi, eleifend non viverra non, molestie nec nulla. Curabitur vel scelerisque dui, facilisis tempus enim. Etiam ac scelerisque dui. Etiam pretium tortor ac dictum eleifend. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam ornare malesuada risus, sed iaculis tellus lacinia vitae. Vivamus ut rhoncus nisl. Pellentesque vel sapien diam. Duis id felis massa.
</div>
</div>
Edit:
I've realized I could move the max-height amount to the child div, but the text still wraps strangely due to the overflow: hidden rule. I want to believe that this is a bug, but I am not certain.
Try This:
.wrapper {
overflow: auto;
padding: 25px;
border: 1px solid #000;
}
.left {
float: left;
border: 1px solid #000;
}
.content {
display: block;
overflow: auto;
/* Required but causes inline-block behavior? */
}
::-webkit-scrollbar {
width: 0px;
background: transparent; /* make scrollbar transparent */
}
<div class="wrapper">
<div class="left">
Left
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla aliquam quam sit amet neque ullamcorper varius. Aliquam porta, nulla a accumsan laoreet, ipsum nibh rhoncus lectus, sit amet placerat nibh felis ut leo. Nam in turpis at felis rutrum euismod a a sem. Donec efficitur lorem non vehicula luctus. Nulla pulvinar ultrices blandit. Donec ipsum arcu, tempus nec vulputate quis, porta nec sapien. Curabitur pellentesque, felis ut suscipit sodales, risus arcu consequat odio, vel porta ligula leo et quam. Praesent quam nisi, eleifend non viverra non, molestie nec nulla. Curabitur vel scelerisque dui, facilisis tempus enim. Etiam ac scelerisque dui. Etiam pretium tortor ac dictum eleifend. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam ornare malesuada risus, sed iaculis tellus lacinia vitae. Vivamus ut rhoncus nisl. Pellentesque vel sapien diam. Duis id felis massa.
</div>
</div>
So I have an application where I display user data, the div containing this data has an auto width attribute so text won't split into multiple lines. But now I have a problem because this div also contains a block of text. which obviously should be longer than one rule. This results in that the div becomes really wide. which I don't want. I am looking for a solution to make CSS ignore this specific block of text. Is there anyone who knows a solution?
This is the containing div
#GenerateInfo{
overflow: scroll;
position: fixed;
top: 0;
bottom: 0;
right: 76%;
margin: auto;
width: auto;
height: 65%;
padding: 0;
z-index: 100;
font-size: 20px;
text-align: left;
-webkit-box-shadow: 6px 18px 30px 0px rgba(0,0,0,0.36);
-moz-box-shadow: 6px 18px 30px 0px rgba(0,0,0,0.36);
box-shadow: 6px 18px 30px 0px rgba(0,0,0,0.36);
}
HTML:
<div id="GenerateInfo" class="card">
<div class="card-body">
<h3>Information</h3><strong>name:</strong>
<br>Name
<hr>
<strong>Email:</strong><br>email#hotmail.nl<hr>
<strong>message:</strong>
<br>
<span class="limit">rem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam u</span>
</div>
</div>
sorry for the Dutch language in images.
this is what it should look like (even if it has a long message):
This is what it looks like:
When I resize my window to 1280 x 720 or below I just realized I'm getting some behavior I do not want. The right column (.right class) is getting "bumped down" below when I resize my window
What is it in my CSS code (or not in the code) that's causing this? I have a feeling that I'm missing a very important concept here. :)
Here is what happens to the right column on smaller screens: http://s11.postimg.org/vp9c7o3dv/css.png
And here is the faulty code:
http://codepen.io/cosmonaut/pen/yyvZjZ?editors=110
html {
background: url(http://s16.postimg.org/k5re12691/bg_radium.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body {
width: 95%;
font-family: courier;
font-size: 15px;
color: #E7DFC2;
margin-left: 30px;
}
.container {
width: 90%;
margin: 10px auto;
background-color: #273E23;
opacity: 0.97;
margin-top: 25px;
}
.header {
text-align:center;
font-size: 40px;
padding: 1em;
border-bottom: 1px solid gray; /* Temporary. */
background-color: #273E23;
}
.header p {
font-size: 25px;
padding: 0px;
margin: 0px;
background-color: #273E23;
}
.header img {
padding: 0px;
margin: 0px;
width: 200px;
height: 200px;
}
.menu {
text-align: center;
}
.menu ul {
}
.menu ul li {
margin: 0 20px;
padding: 0;
list-style-type: none;
display: inline-block;
}
.menu ul li a {
text-decoration: none;
background-color: #273E23;
color: #D3B474;
}
.left {
float: left;
width: 160px;
margin: 0;
padding: 1em;
}
.right {
padding: 1em;
float: right;
width: 860px;
background-color: #273E23;;
}
.right p {
background-color: #273E23;
}
.footer {
clear: both;
margin: 0px;
padding: .5em;
text-align: center;
background-color: #273E23;
}
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet_v2.css"/>
<title>Radium Recordings</title>
</head>
<body>
<div class="container">
<div class="header">
<img src="http://s11.postimg.org/z08mz7o9f/radium4.png">
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Releases</li>
<li>Tours</li>
<li>Contact</li>
</ul>
</div>
<div class="left"><p>Hi, I'm the left side. Not sure if I'm even going to keep this column. Lorem Ipsum added:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
</div>
<div class="right">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
<p>Aliquam convallis nulla commodo convallis scelerisque. Curabitur elementum porttitor purus, posuere tincidunt turpis sagittis et. Proin non nulla vitae velit rutrum egestas id vitae dolor. Mauris placerat nec metus vel ultrices. Integer molestie lobortis eros a dapibus. Pellentesque commodo iaculis magna fringilla rhoncus. Nullam luctus dui elit, nec ornare erat volutpat vitae. Vestibulum nulla velit, porttitor in hendrerit vel, varius sit amet elit. Aliquam erat volutpat.
</p>
</div>
<div class="footer">
<p>P.O. Box 321, Anywhere, USA 31721 | Tel: (888) 888-8888</p>
</div>
</div>
</body>
</html>
Change your column widths to percentages. One example is this Codepen.
I used:
.left {
float: left;
width: 20%;
margin: 0;
padding: 1em;
}
.right {
padding: 1em;
float: right;
width: 67%;
background-color: #273E23;;
}
but you can use any percentages that look right to you.
You have two column in your site. One have class name "left" another have class named "right". Now each of those class have fixed width. So when the screen size goes less than the declared width the 2nd column get down to get it desire size.
If we see the explanation:
.right {
padding: 1em;
float: right;
width: 860px;
background-color: #273E23;
}
.left {
float: left;
width: 160px;
margin: 0;
padding: 1em;
}
Here we can see right class have width of 860px and the left class have width of 160px. Also the right class have a padding of 1em which is 15 in pixel. So if you want to show both of the element in single line then the minimum screen size should be 1050px (860 + 30 + 160). Here 30 is summation of both side padding 15 px.
If you want to do the code in such way that you what ever the screen size is both column should maintain size ratio then instead of using fixed width you should use %. For batter understanding you can check example of #bobdye
On small screen you have not enough space in .container for two columns.
You should set .container width in px, or declare min-width for it, or declare width of left and right columns in %.
I've created a very simple web page layout which can be seen here: http://s361608839.websitehome.co.uk/greengold/www/index.html as you can see, there seems to be a problem. The div #rightcol seems to be pushed down the page by the top div on the left (#leftcolbanner).
The CSS for #leftcolbanner is:
#leftcolbanner{
width: 707px;
height: 266px;
float: left;
background: url(../images/banner_home.gif) no-repeat;
margin: 20px 0 20px 20px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid #e1dbce;
}
and #rightcol:
#rightcol{
width: 190px;
background: #f4f2ec url(../images/bg_rightcol.gif) no-repeat right bottom;
float: right;
min-height: 550px;
padding: 25px;
-moz-border-radius-topleft: 0px;
-moz-border-radius-topright: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 0px;
-webkit-border-radius: 0px 5px 5px 0px;
border-radius: 0px 5px 5px 0px;
border-left: 1px solid #e1dbce;
}
The width of #leftcolbanner shouldn't be the issue why #rightcol is being pushed down. This would seem to be the only cause usually in my experience, but this time not so.
Can anyone see anything I cannot see causing this?
Many Thanks
Move #rightCol div above #leftCol div.
You can put the right column in first position of your 3 div containers and it should solve the problem.
<div id="main">
<div id="leftcolbanner">
<h2>Willkommen im Ausbildungsstall Green&Gold</h2>
<p>Ut ligula eros, consequat vitae varius eget, consequat ac neque. Vestibulum venenatis odio vitae erat tristique gravida in in elit. Duis molestie ante turpis.</p>
</div>
<div id="rightcol">
<h2>Kontact</h2>
<p><strong>GREEN&GOLD GmbH</strong><br>
Dressurausbildungsstall<br>
Hauptstrasse 3<br>
4525 Balm b. Günsberg</p>
<p>green-gold#bluewin.ch</p>
<div id="rightcolline"></div>
<p><strong>Christian Pläge</strong><br>
+41 79 4 73 52 10</p>
<p><strong>Birgit Wientzek Pläge</strong><br>
+41 79 2 74 27 67<br>
Fax +41 32 6 37 08 53</p>
</div>
<div id="leftcol">
<p>Curabitur gravida tristique felis, eu lobortis neque iaculis vitae. In lacus dui, feugiat eu iaculis sit amet, laoreet ut quam. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
<p>Nullam interdum, justo in porta rutrum, sem velit pulvinar purus, id scelerisque orci sem sit amet lacus. Proin posuere nunc quis sapien hendrerit sollicitudin sollicitudin dolor egestas. </p>
<p>Sed nibh magna, imperdiet a ullamcorper vel, elementum at turpis. Quisque sed sem et tellus pretium pretium sed vel nulla. Suspendisse potenti. Vivamus vehicula ultrices enim, quis sagittis tortor dignissim ut. Nulla quis neque sed erat interdum porta. Donec iaculis libero eu justo volutpat volutpat condimentum metus rutrum. Quisque viverra mattis suscipit.</p>
</div>
</div>
I think you should add a div with float: left; and place there leftcolbanner and leftcol then it should work.
Better way is to put #leftcolbanner & #leftcol in one DIV. Then give float to them write like this:
HTML
<div class="left">
<div id="leftcolbanner"></div>
<div id="leftcol"></div>
</div>
<div id="rightcol"></div>
CSS
.left{float:left}
#rightcol{float:right}
You need to put these divs in a container div that accommodates the dimensions of its content. See in this jsfiddle, by putting them both in a div with a width:1000px, they line side by side.