I need a vertical line on the middle of the page, here above i've got horizontal. What i really want is a vertical line with same style of this horizontal line.
hr.style-six {
border: 0;
height: 0;
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}
How could that be done?
EDIT:
the below codes work but i cannot add anything until the vertical line ends, from the point it ends i can add stuffs but not before that.
I'm trying to add things on the right and left side of the vertical line.
How could i fix it?
This is example with fixed vertical line, always presented, on the middle of page. None other element will move it up or down.
.vline
{
position:fixed;
top:0;
left:50%;
bottom:0; margin:0;
border:none;
border-right:solid 1px black;
z-index:10;
}
<hr class="vline" />
Update : There is example, based on Your edit. If that's what You need. Two divs floated left and right, with some padding and vertical divider line (hr)
body, html {margin:0;padding:0;}
.dleft, .dright
{
display:inline;
width:calc(50% - 20px); /*50% width minus 2xpadding = 20px*/
padding:10px;
}
.dleft
{
float:left;
background-color:yellow;
}
.dright
{
float:right;
background-color:lightblue;
}
.vline
{
position:fixed;
top:0; bottom:0;
left:50%;
border:none;
border-right:solid 1px black;
z-index:10;
margin:0;
}
<hr class="vline" />
<div class="dleft">
aslkjfklasdjfsadlkf
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>asd;lfkj<br>
</div>
<div class="dright">
aslkdjflsadkjf<br>aslkdjflsadkjf<br>aslkdjflsadkjf<br>
aslkdjflsadkjf<br>aslkdjflsadkjf<br>aslkdjflsadkjf<br>
aslkdjflsadkjf<br>aslkdjflsadkjf<br>aslkdjflsadkjf<br>
</div>
<div style="clear:both;"></div>
Here's a fast example I've made. This is one way of achieving this.
<div class="verticalLine"></div>
.verticalLine {
background-color: #000;
height: 100vh;
margin: 0 auto;
width: 1px;
}
Example 1
Another way is using absolute position like this:
.verticalLine {
background-color: #000;
height: 100%;
left: 50%;
position: absolute;
transform: transitionX(-50%);
top: 0;
width: 1px;
}
Example 2
And third way without the height property
.verticalLine {
background-color: #000;
bottom: 0;
left: 50%;
position: absolute;
transform: transitionX(-50%);
top: 0;
width: 1px;
}
Example 3
Since elements in HTML are rendered from top to bottom, there's no way of adding a vertical line as easily as using a <hr>. One way would be to split up the page in two <div>s and adding a border to one of the two <div>s like this:
.left-col {
width: 50%;
min-height: 200px;
border-right: 1px solid black;
float: left;
box-sizing: border-box;
}
.right-col {
width: 50%;
min-height: 200px;
float: right;
}
<div class='page'>
<div class='left-col'>
Content in the left column
</div>
<div class='right-col'>
Content in the right column
</div>
</div>
You could also use display: inline-block instead of float: right, but it will have some issues with spaces taking up a part of the 100% width (so you can't use 50% + 50% divs without using hacks). CSS-Tricks has some information on inline-block.
Depending on if you need content to the right of the vertical line, you may of course skip the .right-col entirely.
box-sizing: border-box makes the 1px border count as a part of the width, so that we can have 50% + 50% = 100%.
Related
I have a screen that contains 4 divs, divs these are resizable on the monitor screen until a certain point, as you can see in this link
All I'm trying to do is get a way to put the div Main D beside of Main B and Main C, I tried to put the float: left; with a width of 100% encompassing these two divs, but it did not work.
If I remove the width of 100%, the Main D go to left, but changes the original size of the divs (Main B, Main C), and this is becoming a big problem, how can I solve this?
Is this what you're trying to do? http://jsfiddle.net/r5vsb/1/
Wrap Menu B and Menu C in a div and float it:
HTML
<div id="topo" style="">
<br>
<br>Main A</div>
<div id="sidebar">
<div id="Menu_B" style="">
<br>
<br>Menu B</div>
<div id="Menu_C" style=" ">
<br>
<br>Menu C</div>
</div>
<div id="main-content">
<div id="Feed" style="">
<br>
<br>Main D</div>
</div>
css
#topo {
background:#EEEEEE;
text-align:center;
border:1px solid #BBBBBB;
height:10%;
width:100%;
border-radius:5px;
position: relative;
min-width:839px;
min-height:86px;
max-width:1920px;
max-height:1080px;
}
#sidebar {
width:40%;
max-width:764px;
min-width:337px;
float:left;
}
#main-content {
width:60%;
min-width:500px;
float:left;
}
#Menu_B {
background:#EEEEEE;
text-align:center;
border:1px solid #BBBBBB;
max-height:428px;
min-height:290px;
height:40%;
border-radius:5px;
position: relative;
margin-top:5px;
}
#Menu_C {
background:#EEEEEE;
text-align:center;
border:1px solid #BBBBBB;
max-height:513px;
min-height:320px;
height:48%;
border-radius:5px;
position: relative;
margin-top:5px;
}
#Feed {
background:#EEEEEE;
text-align:center;
border:1px solid #BBBBBB;
border-radius:5px;
position: relative;
margin-top:5px;
margin-left:5px;
height:500px;
}
(I extracted your inline CSS to make it easier to read).
I know what you're trying to do, but you can not do it without actually going beyond limitations of CSS. I've done it before, and it involved more hassle than it was worth. Position divs next to each other with float: left is dead simple, yes, but you can not have 2 float left divs next to a floated left div with a width of 100%.
There are several methods, and most of them involve whipping out a good ol' fashioned calculator and do some number crunching. Just find the maximum width of divs B and C (as well as their padding and margins) and then in your CSS, take that number and change the width from 100% to:
width: calc(100% - x);
Assuming x is that number you got. This may or may not work, depending on your understanding of how margins and paddings work in CSS. If they don't have paddings or margins (or even borders for that matter), than getting x is easy. If you can find it, just plug and chug numbers in there.
Your next best bet is jquery, because jquery is an end all, be all solution to most problems that CSS can't solve. All you need to do is use a script like this:
function widthSetter(divB, divC) {
var getWindow = $(window).width();
var getB = $(divB).width();
var getC = $(divC).width();
var widthBC = getB + getC;
var getD = getWindow - widthBC;
$(divD).css("width", getD)
}
$(document).ready(function(){
widthSetter(divB, divC);
$(window).resize(function(){widthSetter(divB, divC)});
});
Granted you understand basic jquery, just be sure to plug in the div names where they need to be and you'll be good to go.
http://jsfiddle.net/fHZRD/
This works, you have to move the D above the other two, remove the width:100% from the container on B and C, and float the D right instead.
They will not scale down unless you add a container around all three of them with
style="width:100%;display:block;min-width:860px;height:100%;"
so that once the veiwport hits the min-width they stay that wide rather than squishing each other out. The max-width on D will cause a white space but I'm not sure if that's intended.
Here it is with that update
http://jsfiddle.net/R5DWF/
Try this:
HTML:
<div id="topo">
<br>
<br>Main A
</div>
<div id="menu-holder">
<div id="Menu_B">
<br>
<br>Menu B</div>
<div id="Menu_C">
<br>
<br>Menu C
</div>
</div>
<div id="Feed">
<br>
<br>Main D
</div>
CSS:
#topo {
background: none repeat scroll 0 0 #eeeeee;
border: 1px solid #bbbbbb;
border-radius: 5px;
height: 10%;
max-height: 1080px;
max-width: 1920px;
min-height: 86px;
min-width: 839px;
position: relative;
text-align: center;
width: 100%;
}
#menu-holder {
float: left;
max-width: 768px; /* 40% of 1920 max-width of topo*/
min-width: 335px; /* 40% of 839 min-width of topo*/
width: 40%;
}
#Menu_B {
background: none repeat scroll 0 0 #eeeeee;
border: 1px solid #bbbbbb;
border-radius: 5px;
height: 40%;
margin-top: 5px;
max-height: 428px;
max-width: 764px;
min-height: 290px;
min-width: 337px;
position: relative;
text-align: center;
width: 100%;
}
#Menu_C {
background: none repeat scroll 0 0 #eeeeee;
border: 1px solid #bbbbbb;
border-radius: 5px;
height: 48%;
margin-top: 5px;
max-height: 513px;
max-width: 764px;
min-height: 320px;
min-width: 337px;
position: relative;
text-align: center;
width: 100%;
}
#Feed {
background: none repeat scroll 0 0 #eeeeee;
border: 1px solid #bbbbbb;
border-radius: 5px;
float: left;
height: 87.2%;
margin-left: 5px;
margin-top: 5px;
max-height: 944px;
max-width: 1142px;
min-height: 678px;
min-width: 502px;
position: relative;
text-align: center;
width: 58.5%;
}
I'm trying to create a "tile" (square block) with content centered perfectly in the middle of it.
Here's the HTML
<div class="tile-facebook">
<h5>Facebook</h5>
<div class="tile-notification">4</div>
<h4>notifications</h4>
</div>
And the CSS
.tile-facebook{
width:175px;
height:175px;
background: #3b5998 ;
text-align: center;
border-radius: 10px;
border-style: solid;
border-color: #ccc;
border-width:1px;
color: white;
}
.tile-notification{
font-size:80px;
font-weight:bold;
padding:10px 0px;
}
I've got the text in the middle of the block, however I want it to be directly in the middle with the same padding from the top and bottom. Thoughts?
You might not set the height , but use a pseudo or extra element to draw your square from any width of your boxe.
vertical padding at 100% + inline-block is a way to draw a square and add content in its middle.
<div class="tile-facebook">
<div class="wrapper">
<h5>
Facebook
</h5>
<div class=" tile-notification ">
4
</div>
<h4>
notifications
</h4>
</div>
</div>
.tile-facebook {
width:175px;
background: #3b5998;
text-align: center;
border-radius: 10px;
border-style: solid;
border-color: #ccc;
border-width:1px;
color: white;
}
.tile-notification {
font-size:80px;
font-weight:bold;
}
.tile-facebook .wrapper * {
margin:0;
}
.tile-facebook:before {
padding-top:100%;
content:'';
}
.tile-facebook:before,
.wrapper {
display:inline-block;
vertical-align:middle;
}
http://jsfiddle.net/cnq82/
some explanation about vertical % padding or margin : http://www.w3.org/TR/CSS2/box.html#padding-properties & http://www.w3.org/TR/CSS2/box.html#propdef-margin-top
So, (hope it makes it a bit more clear : ) )
If you give a vertical padding of 100% its height will be equal to width of parent.
If you want height to be taller of 20px you can do : padding:100% 0 20px 0 ; or padding:20px 0 100% 0;
If you want a box with a ration of 4:3 , just do padding-top:75%; or padding:50% 0 25% 0;.
pseudo or extra element can be floatting, or inline-block for vertical alignment.
You do not need to set a width in parent's CSS.
This fix tequires that the contents height never changes, and you need to add another <div>.
<div class="tile-facebook">
<div class="center">
<h5>Facebook</h5>
<div class="tile-notification">4</div>
<h4>notifications</h4>
</div>
</div>
And add the CSS:
.title-facebook {
position: relative;
}
.center {
position: absolute;
top: 50%;
margin-top: -[half height];
left:0;
width: 100%;
}
Where [half height] is half the height of the .center div.
Add margin: -30px; to your CSS here:
.tile-notification {
font-size:80px;
font-weight: bold;
padding: 10px 0px;
margin: -30px;
}
I'm trying to achieve a 1 column flexible / 1 column fixed layout. 'col-a' should be flexible, taking up 100% - 110px, 'col-b' should be fixed and aligned right.
I' trying to use negative margins but having little luck.
<div class="cont">
<div class="col-a">
Be flexible
</div>
<div class="col-b">
Be fixed
</div>
</div>
.cont {
background-color: #00f;
padding: 10px;
overflow:hidden;
}
.col-a {
background-color: #0ff;
padding-right: 110px;
margin-right: -110px;
float: left;
}
.col-b {
background-color: #ff0;
width: 110px;
float: left;
}
Can it be done using just this mark-up?
/*Answer found */
Here is the solution
.cont {
background-color: #00f;
overflow:hidden;
padding: 10px;
}
.col-a {
width: 100%;
background-color: #0ff;
margin-right: -110px;
float: left;
}
.col-b {
background-color: #ff0;
width: 110px;
float: right;
}
I wouldn't use a negative margin for this.
This is how I would set it up.
Set your column parent container to position relative.
Set your column A to have a padding-right of 110px (to make space for Column B)
Set your column B to be absolutely positioned to the top, right with a fixed width of 110px.
This will allow your Column A to expand 100% horizontally, while leaving space on the right for Column B.
Here's an example of what I outlined above: http://jsfiddle.net/NPn8d/
How about something like this, then.
<style type="text/css">
.cont{position:relative;}
.col-a{
border:1px solid #0000ff;
width:auto;
margin:0,110,0,0;
}
.col-b{
border:1px solid #ff0000;
width:110px;
float:right;
top:0;
position:absolute;
margin:0,0,0,-110
}
</style>
<div class="cont">
<div class="col-a">Be flexible</div>
<div class="col-b">Be fixed</div>
</div>
Somehow I can't figure out what I'm missing...
I try to position a number of absolute divs between two fixed bars (header and footer). Header contains some tabs and footer contains an copyright. I want to use the window's scrollbar and not an overflowed div and I know it should be possible!
Every absolute positioned div should carry an extra margin, so that the bottom of that div does not disappear behind the footer.
It should become something like this:
A snippet of my problem is available here on jsfiddle.
My HTML:
<ul class="cf tabs">
<li>Tab 1</li>
<li>Tab 2</li>
</ul>
<div style="margin-top: 40px; padding-bottom: 30px; position:relative">
<div style="position:absolute;top:300px; height:100px; width: 250px; left:200px; border: 1px solid purple;">aaa</div>
<div style="position:absolute;top:0px; height:100px; width: 100px; left:100px; border: 1px solid purple;">bbb</div>
<div style="position:absolute;top:450px; height:100px; width: 250px; left:400px; border: 1px solid purple;">ccc</div>
</div>
<div class="cf footer">Copyright ©</div>
The stylesheet I'm using:
ul.tabs {
list-style-type: none;
list-style-position: outside;
padding:5px;
margin: 0;
position:fixed;
top:0;
z-index: 999;
background-color: white;
left:0;
right:0;
border-bottom: 1px solid green;
opacity: 0.7;
}
ul.tabs li {
float: left;
margin:1px;
padding: 4px 10px 2px 10px;
border: 1px solid black;
}
div.footer {
position: fixed;
bottom: 0;
left: 0;
right:0;
background-color:#DEDEE9;
border-top: 3px outset #BBBBBB;
padding: 5px;
opacity: 0.6;
}
.cf:before,
.cf:after {
content: " ";
display: table;
}
.cf:after {
clear: both;
}
Do you guys have any hints?
Extra info
As you can see in the attached image the purple border of squared div at bottom right is overlapping the fixed footer. I do not want this. There should be given a bottom margin somewhere, so that every div carries an extra margin so it should match the top of the footer
Here's the solution I've come up with. Wrap the bottommost absolutely positioned div inside with another div, on which put bottom margin equal to footer height and the border. I gave it class .inner.
See my fiddle.
Add bottom padding to the document body equivalent to the height of the footer:
body {
padding-bottom: 31px;
}
(JSFiddle doesn't seem to let you modify styling of the body element, so I can't post a fiddle. It should work, though.)
Instead of using absolute positioning, do something like:
margin - left : 800px
Margin - top: 500px
I have following code
div {
width: 200px;
border-bottom: 1px solid magenta;
height: 50px;
}
<div></div>
The div width is 200px so border-bottom is also 200px but what should I do if I want border-bottom only 100px without changing div width?
You can use pseudoelements. E.g.
div {
width : 200px;
height : 50px;
position: relative;
z-index : 1;
background: #eee;
}
div:before {
content : "";
position: absolute;
left : 0;
bottom : 0;
height : 1px;
width : 50%; /* or 100px */
border-bottom:1px solid magenta;
}
<div>Item 1</div>
<div>Item 2</div>
No need to use extra markup for presentational purpose. :after is also supported from IE8.
edit:
if you need a right-aligned border, just change left: 0 with right: 0
if you need a center-aligned border just simply set left: 50px;
Another way to do this (in modern browsers) is with a negative spread box-shadow. Check out this updated fiddle: http://jsfiddle.net/WuZat/290/
box-shadow: 0px 24px 3px -24px magenta;
I think the safest and most compatible way is the accepted answer above, though. Just thought I'd share another technique.
I added line under under h3 tag like this
<h3 class="home_title">Your title here</h3>
.home_title{
display:block;
}
.home_title::after {
display:block;
clear:both;
content : "";
position: relative;
left : 0;
bottom : 0;
max-width:250px;
height : 1px;
width : 50%; /* or 100px */
border-bottom:1px solid #e2000f;
margin:0 auto;
padding:4px 0px;
}
You can use a linear gradient:
div {
width:100px;
height:50px;
display:block;
background-image: linear-gradient(to right, #000 1px, rgba(255,255,255,0) 1px), linear-gradient(to left, #000 0.1rem, rgba(255,255,255,0) 1px);
background-position: bottom;
background-size: 100% 25px;
background-repeat: no-repeat;
border-bottom: 1px solid #000;
border-top: 1px solid red;
}
<div></div>
You cannot have a different sized border than the div itself.
the solution would be to just add another div under neath, centered or absolute positioned, with the desired 1pixel border and only 1pixel in height.
http://jsfiddle.net/WuZat/3/
I left the original border in so you can see the width, and have two examples -- one with 100 width, and the other with 100 width centered. Delete the one you dont wish to use.
Late to the party but for anyone who wants to make 2 borders (on the bottom and right in my case) you can use the technique in the accepted answer and add an :after psuedo-element for the second line then just change the properties like so:
http://jsfiddle.net/oeaL9fsm/
div
{
width:500px;
height:500px;
position: relative;
z-index : 1;
}
div:before {
content : "";
position: absolute;
left : 25%;
bottom : 0;
height : 1px;
width : 50%;
border-bottom:1px solid magenta;
}
div:after {
content : "";
position: absolute;
right : 0;
bottom : 25%;
height : 50%;
width : 1px;
border-right:1px solid magenta;
}
I did something like this in my project. I would like to share it here. You can add another div as a child and give it a border with small width and place it left, centre or right with usual CSS
HTML code:
<div>
content
<div class ="ac-brdr"></div>
</div>
CSS as below:
.active {
color: magneta;
}
.active .ac-brdr {
width: 20px;
margin: 0 auto;
border-bottom: 1px solid magneta;
}
This will help:
http://www.w3schools.com/tags/att_hr_width.asp
<hr width="50%">
This creates a horizontal line with a width of 50%, you would need to create/modify the class if you would like to edit the style.
I have case to have some bottom border between pictures in div container and the best one line code was - border-bottom-style: inset;
div{
font-size: 25px;
line-height: 27px;
display:inline-block;
width:200px;
text-align:center;
}
div::after {
background: #f1991b none repeat scroll 0 0;
content: "";
display: block;
height: 3px;
margin-top: 15px;
width: 100px;
margin:auto;
}
The border is given the whole html element. If you want half bottom border, you can wrap it with some other identifiable block like span.
HTML code:
<div> <span>content here </span></div>
CSS as below:
div{
width:200px;
height:50px;
}
span{
width:100px;
border-bottom:1px solid magenta;
}
I just accomplished the opposite of this using :after and ::after because I needed to make my bottom border exactly 1.3rem wider:
My element got super deformed when I used :before and :after at the same time because the elements are horizontally aligned with display: flex, flex-direction: row and align-items: center.
You could use this for making something wider or narrower, or probably any mathematical dimension mods:
a.nav_link-active {
color: $e1-red;
margin-top: 3.7rem;
}
a.nav_link-active:visited {
color: $e1-red;
}
a.nav_link-active:after {
content: '';
margin-top: 3.3rem; // margin and height should
height: 0.4rem; // add up to active link margin
background: $e1-red;
margin-left: -$nav-spacer-margin;
display: block;
}
a.nav_link-active::after {
content: '';
margin-top: 3.3rem; // margin and height should
height: 0.4rem; // add up to active link margin
background: $e1-red;
margin-right: -$nav-spacer-margin;
display: block;
}
Sorry, this is SCSS, just multiply the numbers by 10 and change the variables with some normal values.
Border right length smaller than parent div
with pseudo-elements
#import url(https://fonts.googleapis.com/css?family=Raleway);
body{
font-family: 'Raleway', sans-serif;
}
div {
width : 200px;
height : 50px;
position: relative;
z-index : 1;
background-color: #f5f5f5;
margin: 20px auto;
padding: 20px;
color:#726E97;
}
div:before {
content : "";
position: absolute;
right : 0;
top : 25%;
height : 50px;
width : 50%;
border-right:5px solid #726E97;
}
<div>BOX 1</div>