I have three divs that I am trying to put on a single line. I want one to always snap left, and I want one to always snap right. The third one, which the display will be toggled using javascript, has to always be center. I've tried float. I've tried display:inline-block. Nothing works. Below is my code, any help would be greatly appreciated.
<div id="header" class="AppBackColor" style="color:#FFFFFF; padding:2px; width:100%; height:34px;">
<div style="height:100%;display:inline-block;float:left;">
<img src="Images/Logo/uss_logo_white.gif" height="30px" width="31px" alt="USS" />
<label>Change Control</label>
</div>
<div id="TimeoutWarning" style="height:100%; width:450px;display:inline-block;margin:0 auto;">Your session will expire in <label id="lblSessionCountDown">5:00</label>. Click <a style="color: Red;" href="#" onclick="ResetSession();void(0);">OK</a> to continue your session.</div>
<div style="height:100%;display:inline-block;float:right;">
<label>User:</label>
<asp:Label ID="lblUser" runat="server"></asp:Label>
<asp:ImageButton ID="btnLogout" runat="server" BorderStyle="None" ImageUrl="~/Images/Logout-icon.png" onclick="btnLogout_Click" Height="30px" Width="30px"/>
</div>
You can use absolute positioning like this:
.container {
position: relative;
width: 100%;
height: 50px;
}
.first {
width: 100px;
height: inherit;
position: absolute;
left: 0;
background-color: #FAA;
}
.second {
width: auto;
height: inherit;
position: absolute;
top: 0;
margin-left: 100px; // 1st div width
margin-right: 200px; // 3rd div width
background-color: #AFA;
}
.third {
width: 200px;
height: inherit;
position: absolute;
right: 0;
top: 0;
background-color: #AAF;
}
And then use a <div class="container"> which has inside the 3 divs with classes first, second and third.
If you set the margins of the second equals to the with of the first and third, like in the sample, it will fill up all the space.
You can look at it working in this fiddle: http://jsfiddle.net/jbustos/Bq2rw/
Here's an example of one way to do it. The order of the divs in the HTML being left, right, center is important, since otherwise the right will place itself below the left and center elements. See it live at jsfiddle (with JS to hide/show the center). Here's the HTML:
<div class="left">left text</div>
<div class="right">right</div>
<div class="center">center</div>
And CSS:
.left, .center, .right {
background-color: red;
width: 100px;
}
.left {
float: left;
}
.center {
margin: auto;
}
.right {
float: right;
}
Related
I have a vertical line running down the middle of my page, but it only goes as far as the first section. What I want it to do is run all the way down to the very end of the page when you scroll all the way down. I'm not sure how to achieve this.
Right now my CSS for my line is this:
.line{
position: absolute;
top: 100px;
margin: auto;
width: 50%;
height: 100%;
border-right: 1px dotted black;
}
I don't want to have a set height, because as I start adding more projects to the site, I would like the line to grow with the page without having to change the height every time.
Here's a codepen: https://codepen.io/Furr/pen/gJLapb
This website is my inspiration, I would like it to be something like this: https://www.rezo-zero.com/projects/
Thanks in advance.
I think you may actually want 3 divs like this. ( the line is a div)
.vl {
border-left: 1px dotted black;
height: 500px;
}
#parent {
display: flex;
}
#right {
width: 300px;
margin-left: 5px;
}
#left {
flex: 1;
}
<div id="parent">
<div id="left">Left Side</div>
<div class="vl"></div>
<div id="right">Right Side</div>
</div>
another reason to have 3 divs is that you can "break up" the line with clickable content just like in your example
One of feasible way is to use pseudo element to make the vertical line so that it will expand according to the container. Here is an simple example.
.timeline-container {
position: relative;
width: 500px;
margin: 0 auto;
}
.timeline-container:after {
content: " ";
position: absolute;
top: 0;
left: 50%;
width: 1px;
height: 100%;
background-color: #000;
}
.timeline-container .event {
width: 50%;
}
.timeline-container .event.left {
text-align: right;
}
.timeline-container .event.right {
margin-left: 50%;
}
.timeline-container .event-content {
margin: 10px;
}
<div class="timeline-container">
<div class="event left">
<div class="event-content">2019-05-14<br>Testing Events</div>
</div>
<div class="event right">
<div class="event-content">2019-05-10<br>Another Events</div>
</div>
<div class="event left">
<div class="event-content">2019-04-25<br>Great Exhibition</div>
</div>
<div class="event right">
<div class="event-content">2019-03-27<br>School Festival</div>
</div>
</div>
You can look at the source code for the website you wanted to emulate by typing CTRL + SHIFT + I in Chrome after opening it.
I have a problem with my images. I want to make 4 images look like this:
Image
But unfortunately image number 4 is under the rest of them and sticked to the left side of the document. I want it to be sticked to number 2 and 3.
Here is my code:
<div id="images">
<div class="off1"><img src='img/off1.jpg' /></div>
<div class="off2"><img src='img/off2.jpg' /></div>
<div class="off3"><img src='img/off3.jpg' /></div>
<div class="off4"><img src='img/off4.jpg' /></div>
</div>
And css:
.off1
{
float: left;
display: block;
}
.off2
{
display: block;
}
.off3
{
display: block;
position: relative;
bottom: 3px;
}
.off4
{
display: inline-block;
}
Thanks for help!
Add a wrapper element for image div 2 and 3, make that and divs 1 and 4 floats and give div 3 line-height: 0 to avoid a gap between 2 and 3:
http://codepen.io/anon/pen/gLdOyY
Use a mix of floats, positioning, and source-ordering. NO ADDED MARKUP.
Hope this helps you. Source-ordering can be a burden (which is why it's hard to do float:right on .off4. Yet, with CSS there's always a way!
/* added style for example only */
.off1 {
background-color: red;
height: 300px;
width: 100px;
}
.off2 {
background-color: #AAA;
width: auto;
height: 150px;
}
.off3 {
background-color: #ae5433;
width: auto;
height: 150px;
}
.off4 {
background-color: purple;
width: 100px;
height: 300px;
}
/* end added, example style */
#images {
position: relative;
}
.off1 {
float: left;
}
.off2,
.off3 {
width: auto;
}
.off4 {
position: absolute;
top: 0;
right: 0;
}
<div id="images">
<div class="off1">
<img src='img/off1.jpg' />
</div>
<div class="off2">
<img src='img/off2.jpg' />
</div>
<div class="off3">
<img src='img/off3.jpg' />
</div>
<div class="off4">
<img src='img/off4.jpg' />
</div>
</div>
I would like to have a table of elements (pictures) arranged horizontally, and such that the elements partially overlap, in order to save some space.
I attempted to solve it through CSS. Here is my code,
<!DOCTYPE html>
<html>
<head>
<style>
div.tableel
{
height : 100px;
width : 100px;
display: table-cell;
position: relative;
}
div.tableel ~ div.tableel
{
left: -30px;
font-size: 24pt;
}
div.row
{
display: table-row;
}
div.table
{
display: table;
}
</style>
</head>
<body>
<div class="table">
<div class="row">
<div class="tableel" style="background-color: red;">
reg
</div>
<div class="tableel" style="background-color: blue;">
ge
</div>
<div class="tableel" style="background-color: yellow;">
rg
</div>
</div>
</div>
</body>
</html>
What I do not understand is why the font is set correctly, but the third element is not shifted to the left, as I would expect to.
Thanks!
What I do not understand is why the font is set correctly, but the
third element is not shifted to the left
It is being shifted exactly as you intended it to.
The reason you are not able to see it is because when the second div shifts to left, it creates a gap between itself and the third, which is being filled up by the third.
This fiddle will help you see this: http://jsfiddle.net/abhitalks/byayxob0/
If you want to stick to doing it this way, then you will have to get the last div to move left by double the amount:
div.tableel:last-child { left: -60px !important; }
See here: http://jsfiddle.net/abhitalks/byayxob0/1/
But, this will be a problem for you if you have indeterminate number of divs. You will have to change the left property cumulatively, which CSS cannot do for you.
That said, a simpler way to do what you want, would be to just keep the divs inline and then use negative margins to control the overlap.
Demo Fiddle: http://jsfiddle.net/abhitalks/4gaotuwL/
Demo Snippet:
div.tableel {
height: 100px; width: 100px;
display: inline-block;
}
div.tableel:nth-child(1) { background-color: rgba(255,0,0,0.5); }
div.tableel:nth-child(2) { background-color: rgba(0,0,255,0.5); }
div.tableel:nth-child(3) { background-color: rgba(255,255,0,0.5); }
div.tableel:not(:first-child) {
margin-left: -10px;
}
<div class="table">
<div class="row">
<div class="tableel">reg</div>
<div class="tableel">ge</div>
<div class="tableel">rg</div>
</div>
</div>
It's because the second element is moved 30px to the left so that it would be 30px further away from the 3rd element, then when you shift the 3rd element 30px to the left it just closes the gap you made. If you want to move the 3rd element to overlap the second by 30px, you'd need to move it 60px to catch up to it and overlap it.
.table {
width: 300px;
table-layout: fixed;
display: table;
}
.tableel {
height: 100px;
width: 100px;
display: table-cell;
position: relative;
vertical-align: middle;
text-align: center;
}
.row {
display: table-row;
}
.default .tableel ~ .tableel {
left: -30px;
}
/* I just moved the second block*/
.scene-1 .tableel:nth-child(2) {
left: -30px;
}
.scene-2 .tableel:nth-child(2) {
left: -30px;
}
/* I also moved the third block - but 60pixels. (as 30pixel will move it beside 2nd block*/
.scene-2 .tableel:nth-child(3) {
left: -60px;
}
<h2>Your code</h2>
<div class="table default">
<div class="row">
<div class="tableel" style="background-color: rgba(255,0,0,0.7);">
reg
</div>
<div class="tableel" style="background-color: rgba(0,255,0,0.7);">
ge
</div>
<div class="tableel" style="background-color: rgba(0,0,255,0.7);">
rg
</div>
</div>
</div>
<h2>Scene 1</h2>
<div class="table scene-1">
<div class="row">
<div class="tableel" style="background-color: rgba(255,0,0,0.7);">
reg
</div>
<div class="tableel" style="background-color: rgba(0,255,0,0.7);">
ge
</div>
<div class="tableel" style="background-color: rgba(0,0,255,0.7);">
rg
</div>
</div>
</div>
<h2>Scene 2</h2>
<div class="table scene-2">
<div class="row">
<div class="tableel" style="background-color: rgba(255,0,0,0.7);">
reg
</div>
<div class="tableel" style="background-color: rgba(0,255,0,0.7);">
ge
</div>
<div class="tableel" style="background-color: rgba(0,0,255,0.7);">
rg
</div>
</div>
</div>
You should do left: -60px; to the third element in order to go -30px left because the second element is -30px left.
UPDATE
If you are having an unknown number of divs and wanted to make this work regardless of how many divs you have without having to specify incrementing left values then I suggest using a negative margin.
Simply change this:
div.tableel {
height : 100px;
width : 100px;
display: table-cell;
position: relative;
}
To This:
div.tableel {
height : 100px;
width : 100px;
display: inline-block;
position: relative;
}
and then give the blocks a negative margin by replacing this:
div.tableel ~ div.tableel
{
left: -30px;
font-size: 24pt;
}
to this:
div.tableel {
font-size: 24pt;
opacity: 0.5;
margin-left: -30px;
}
So looking at the code and various answers; I think you're getting confused on the
div.tableel ~ div.tableel
{
position: relative;
left: -30px; /* <------------------This */
font-size: 24pt;
}
left: -30px portion.
Looking at your 3 boxes. You have Box number 1, 2 and 3. Based on your selector; You are moving box 2 to the left -30px and moving box number 3 to the left by -30px.
When you move the first box to the left by -30px; you are creating a gap between box 2 and box 3 of 30px:
This means that Box 3 needs -30px to close the gap. and an additional -30px to overlap so box 3 needs to be -60px for this to work:
-30px:
-60px:
So in short.. I would replace this portion of your code:
div.tableel ~ div.tableel
{
left: -30px;
font-size: 24pt;
}
with this simplified fix:
div.tableel{
font-size: 24pt;
}
div.tableel:nth-child(2){
left: -30px;
}
div.tableel:nth-child(3){
left: -60px;
}
Here is the Fiddle: https://jsfiddle.net/8uhnwhwt/
I've searched the many similar questions like this, but none of the solutions are working. It should also be noted that I am using twitter bootstrap. I want a bunch of divs to span the entire length of the parent div at the bottom of it. I have tried putting them inside a div that text-align:center and then using float-left inside the gridPics class, and using display: inline-block, text-align :left and nothing seems to do it. The two in the example below are in the exact same spot, and I want them side by side. Here is what I have:
HTML:
<div class="row-fluid">
<div class="span8 offset2 articleContent">
<!-- These are the divs to span across, when it works there would be more than two -->
<div class="gridPics"></div>
<div class="gridPics"></div>
<!-- They will also go over this image -->
<img id="sidePic" src="img/about/aboutHeader_Mid1.png" alt="about">
</div>
<div class="span2"></div>
</div>
CSS:
.gridPics{
position: absolute;
z-index: 1;
width: 10%;
height: 20%;
background: #0000b3;
bottom: 0;
float: left;
}
.articleContent{
position: relative;
box-shadow: 0 0 5px 5px #888;
}
#sidePic{
position: relative;
z-index: -1;
}
Here is where I am doing this, the blue divs would be pics (akin to thumbnails) that can be clicked. I want them to go all the way across:
/ScreenShot2013-01-09at85450PM_zps550e8e4a.png[/IMG]
Here's a fiddle:
http://jsfiddle.net/pureux/Er9eG/
You need a container for your gridPics and have it be absolute positioned (instead of the gridPics) at the bottom. Then float the gridPics inside of the container.
.picContainer {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
min-height: 50px;
}
.gridPics {
width: 50px;
height: 50px;
float: left;
display: block;
margin-right: 4px;
margin-top: 4px;
}
Is this what you're trying to do:DEMO
HTML
<div class="row-fluid">
<div class="span8 offset2 articleContent">
<div class="gridPics"></div>
<div class="gridPics"></div>
<div class="clear"></div>
<img id="sidePic" src="img/about/aboutHeader_Mid1.png" alt="about">
</div>
<div class="span2"></div>
</div>
CSS
.gridPics{
width: 10%;
height: 20px;
background: #0000b3;
float: left;
border:solid #FFF 1px;
}
.articleContent{
box-shadow: 0 0 5px 5px #888;
}
#sidePic{
z-index: -1;
}
I'd like to put two columns on the side of the content div. The part I have problems with is that I want the columns being built from 3 parts. The top and bottom should have fixed heights, but the middle one would adjust depending on the content height. Look at the sample with one column:
<html>
<head>
<style>
* { border: 1px solid black;}
#contentWrapper { width:450px; }
#leftColumn { width:100px; float: left; }
#leftColumnTop { width:100px; height:50px;
background-color: gray; }
#leftColumnMiddle { background-color: red; }
#leftColumnBottom { width: 100px; height:50px;
background-color: gray; }
#content { width: 300px; float: left; }
#footer { width: 400px; clear: both; }
</style>
</head>
<body>
<div id="contentWrapper">
<div id="leftColumn">
<div id="leftColumnTop"> </div>
<div id="leftColumnMiddle"> </div>
<div id="leftColumnBottom"> </div>
</div>
<div id="content">content<br> here <br>more
<br>more <br>more <br>more <br>more
<br>more <br>
</div>
<div id="footer">footer text</div>
</div>
</body>
</html>
What I want is the #leftColumnBottom stick at the top of the footer and red #leftColumnMiddle to fill the space between top and bottom part.
This works in everything except IE6; for that you'll need a conditional comment and css expression to set a height instead of bottom on #leftColumnMiddle
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<style>* { border: 1px solid black;}
#contentWrapper { position: relative; float:left; width: 450px; }
#leftColumnTop { position: absolute; width: 100px; height: 50px; left: 0; background-color: gray; }
#leftColumnMiddle { position: absolute; width: 100px; top: 50px; bottom: 50px; left: 0; background-color: red; }
#leftColumnBottom { position: absolute; width: 100px; height: 50px; left: 0; bottom: 0; background-color: gray; }
#content { width: 300px; float: left; margin-left: 100px;}
#footer { width: 400px; clear: both; }
</style>
</head>
<body>
<div id="contentWrapper">
<div id="leftColumnTop"> </div>
<div id="leftColumnMiddle"> </div>
<div id="leftColumnBottom"> </div>
<div id="content">content<br>
here<br>more<br>more<br>more<br>more<br>more<br>more<br>
</div>
</div>
<div id="footer">footer text</div>
</body>
</html>
And to the commenter - it nearly worked, so that's why. ;)
try min-height for the one that needs to grow
If you need both columns to be of equal height, and work in IE6, you basically have to hack.
A solution I've used in the past involves setting up a fake margin/padding for one of the columns. This assumes that you know a upper limit of how large the columns can grow (could be in the magnitude of several thousand px's).
This solution is outlined here.
Quoting from the page I linked:
The basic method works like this:
Blocks which will act as columns must be wrapped in a container element
Apply overflow: hidden to the container element
Apply padding-bottom: $big_value [2] to the column blocks, where $big_value is a large enough value to guarantee that it's equal to or larger than the tallest column
Apply margin-bottom: -$big_value to the column blocks