I am trying to create a horizontal bar the spreads across the full width of my container. In the middle of the bar, I want a circle that is both horizontally/vertically centered. The circle will overlap the horizontal bar. Right now I can get it so be horizontally aligned but I'm having difficulty vertically centering the bar behind the circle. Here is my code:
#wrapper {
width: 1200px;
height: auto;
margin: 0 auto;
}
#navigation {
display: block;
width: 100%;
height: 50px;
background-color: #275337;
}
#navstamp {
background: white;
width: 218px;
height: 218px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
margin: 0 auto;
border: 1px solid;
border-color: rgba(19, 36, 17, 1);
}
And my HTML:
<div id="wrapper">
<div id="navigation">
<div id="navstamp">
</div>
</div>
</div>
Any help would be greatly appreciated!
I'd make use of the css3 ::before pseudo element here, if ancient browser support is not a problem,
<div id="wrapper"> <!-- replaced the navigation with ::before-->
<div id="navstamp">
</div>
</div>
#navstamp::before {
display: block;
content:""; // add the content you need here
position:absolute;
top:50%;
left:0;
width: 100%;
height: 50px;
background-color: #275337;
}
as in this JSFiddle
Your first div tag has not been closed if that's your complete html . As in the fiddle your output is as you are explaining.
<div id="wrapper">
<div id="navigation">
<div id="navstamp">
<div id="headlinetext">
<p class="headline">Lorem Ipsum</p>
<p class="subheadline">- Ipsum -</p>
</div>
</div>
</div>
</div>
Fiddle here:
http://jsfiddle.net/b6n2C/
#navstamp {
background: white;
width: 218px;
height: 218px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
margin: 0 auto;
border: 1px solid;
border-color: rgba(19, 36, 17, 1);
display:table;
}
#headlinetext{
text-align:center;
vertical-align:middle;
display: table-cell;
}
with the help of display:table; and display:table-cell to child.
it will be aligned using vertical-align:middle;
demo: http://jsfiddle.net/8q4zP/1/
Related
I've been trying to achieve the following:
Note: The dashed line is just a guide showing that .inner-a and .inner-b are both horizontally and vertically middle aligned to an imaginary split of .outer down the middle.
Is this possible using just CSS? Or would it need some javascript to achieve?
Here is what I have till now:
HTML
<div class="outer">
<div class="inner-a"></div>
<div class="inner-b"></div>
</div>
CSS
.outer {
width: 300px;
height: 300px;
}
.inner-a, inner-b {
width: 100px;
height: 100px;
}
.inner-a {
float:left;
}
.inner-b {
float: right;
}
.outer { display: inline-flex; align-items: center; }
Try This:
.outer {
width: 500px;
height: 300px;
text-align:center;
border:2px solid red
}
.inner-a, .inner-b {
width: 100px;
height: 100px;
display:inline-block;
border: 2px solid #000;
margin: 10px;
position: relative;
top: 50%;
transform: translateY(-50%);
border:2px solid #000;
margin:10px;
}
<div class="outer">
<div class="inner-a"></div>
<div class="inner-b"></div>
</div>
Since you're using Bootstrap 4 you can use the flexbox utils and avoid the extra CSS..
<div class="outer d-inline-flex justify-content-center align-items-center">
<div class="inner-a">a</div>
<div class="inner-b">b</div>
</div>
https://www.codeply.com/go/fA7OzCOQVp
i have a web page with an image panel and a few div elements, with the same width, each containing an image.
I want to put them into 2 cascading columns with no spaces between them (except for the padding)
I have the following css code for image container:
.imageContainer
{
position:relative;
margin:4px 4px 4px 4px;
border:4px solid #333;
float: left;
display:inline-block;
min-height: 40px;
width: 48%;
}
This causes the columns to like like image 1 but i need the columns to look like number 2
Thank you!
EDIT:
.pg-main
{
float: left;
width: 100%;
padding: 0;
}
.entries
{
float: left;
width: 800px;
padding: 8px 20px 0 0;
}
.entries p
{
display: block;
}
.imageContainer
{
position:relative;
margin:4px 4px 4px 4px;
border:4px solid #333;
float: left;
display:inline-block;
min-height: 40px;
width: 48%;
}
Here is a possible solutions using columns -- does not work on IE9 or earlier.
FIDDLE: http://jsfiddle.net/YjHzd/
HTML
<div id="container">
<div class="block" style="height:30px"></div>
<div class="block" style="height:30px"></div>
<div class="block" style="height:70px"></div>
<div class="block" style="height:70px"></div>
<div class="block" style="height:50px"></div>
</div>
CSS
#container {
-moz-column-count:2;
-webkit-column-count:2;
column-count:2;
height: 145px;
width: 80px;
}
.block {
width: 40px;
background-color: red;
margin: 0 0 5px 0;
}
Unlike many of the other solutions on this page, mine works in all semi-modern browsers, including IE 6, 7, 8, 9; Firefox 3.6 through 29, and all versions of Chrome. See below for screenshots.
If they are of fixed widths, as illustrated, just 1) wrap your boxes inside another div and 2) do the following:
Here's the JSFiddle: http://jsfiddle.net/SqQqZ/
HTML:
<div>
<div id="leftBoxesBox">
<div class="redbox"></div>
<div class="redbox"></div>
<div class="redbox" style="height: 15em"></div>
</div>
<div id="rightBoxesBox">
<div class="redbox" style="height: 12em"></div>
<div class="redbox"></div>
</div>
</div>
CSS:
div.redbox {
background: red;
width: 10em;
height: 5em;
margin: 10px;
}
div#leftBoxesBox {
position: absolute;
left: 0;
width: 12em;
}
div#rightBoxesBox {
position: absolute;
left: 13em;
width: 12em;
}
Internet Explorer 6:
Firefox 3.6:
Please post your HTML, it would help.
Maybe this will help :
clear:left;
after your 2nd imagediv. so the 3rd div can float without problems.
Basically there are only two ways to do this. You can use Javascript to determine the position of the element. Or you can create two seperate columns that have the images contained within them. Left and Right Column
I'm trying to position clid divs in parent div but the height of parent div should be dynamic so it should either expand or shrink after child divs are positioned inside. How can I accomplish it? Childs should remain inside of parent all times.
Since I'm not designer at all I read "Learn CSS Positioning in Ten Steps" to learn a bit.
And this question "Make absolute positioned div expand parent div height".
Thanks
JSFIDDLE
CSS
#header
{
margin: 0 auto;
border: 1px solid #000000;
width: 500px;
background: #aa0000;
}
#body
{
margin: 0 auto;
border: 1px solid #000000;
width: 500px;
background: #ff0000;
}
#footer
{
margin: 0 auto;
border: 1px solid #000000;
width: 500px;
background: #dd0000;
}
#section_one
{
position: relative;
width: 100px;
height: 100px;
background: #EEEEEE;
top: 10px;
left: 10px;
}
#section_two
{
position: relative;
width: 100px;
height: 100px;
background: #EEEEEE;
top: 10px;
left: 150px;
}
HTML
<div id="header">HEARDER</div>
<div id="body">
<div id="section_one">SECTION ONE</div>
<div id="section_two">SECTION TWO</div>
</div>
<div id="footer">FOOTER</div>
You could use float:left and then postion the sections with margin
FIDDLE
Markup
<div id="header">HEARDER</div>
<div id="body">
<div class="section one">SECTION ONE</div>
<div class="section two">SECTION TWO</div>
<div class="section three">SECTION THREE</div>
<div class="section four">SECTION FOUR</div>
</div>
<div id="footer">FOOTER</div>
CSS
.section
{
width: 100px;
height: 100px;
background: #EEEEEE;
float:left;
}
.two
{
margin: 20px 0 0 10px;
}
.three
{
margin: 80px 0 0 50px;
}
.four
{
margin: 220px 0 0 -200px;
}
if it's just a matter of aligning those boxes, use margin&padding and inline-block instead of absolute positioning.
like this: http://jsfiddle.net/avrahamcool/JVh8e/1/
HTML:
<div id="cover">
<div id="section_one">SECTION ONE</div>
<div id="section_two">SECTION TWO</div>
</div>
CSS
#cover
{
margin: 0 auto;
padding: 5px;
width: 500px;
background-color: #000000;
}
#section_one, #section_two
{
display: inline-block;
width: 100px;
height: 100px;
margin: 5px;
background-color: #EEEEEE;
}
as you already read in the link you provided, an absolute element is removed from the flow, so unless you're willing to write a script that finds the necessary height of the cover, its impossible.
also: use background-color instead of background (if you apply only the color)
Update
this is the new fiddle (after your editing):
http://jsfiddle.net/avrahamcool/JVh8e/5/
Update 2:
check out this working example with script.
http://jsfiddle.net/avrahamcool/JVh8e/6/
I'm a tables guy, but I'll need to drag and drop some divs, so I tried doing it tabeless (the right way).
This is what I want to do:
The space between all elements should be 24px. My main problem is having the divs (1,2,3) occupying 100% of available space. The width: 100% its sending them beyond the main container.
This is my code so far:
html
<div id="mainContainer">
<div id="topContainer">Just the top one
</div>
<div id="table">
<div id="Line1Container">
<div id="container1" class="container">1
</div>
<div id="container2" class="container">2
</div>
<div id="container3" class="container">3
</div>
</div>
<div id="Line2Container">
<div id="container4" class="container">4
</div>
<div id="container5" class="container">5
</div>
<div id="container6" class="container">6
</div>
</div>
</div>
</div>
And my css
#mainContainer {
border: 1px solid lightgray;
position:fixed;
top: 80px;
bottom:20px;
left:80px;
right:80px;
overflow-y: scroll;
overflow-x: hidden;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
#topContainer {
border: 1px solid lightgray;
border-radius: 10px;
margin-left: 24px;
margin-right: 24px;
margin-top: 24px;
}
#table {
display: table;
margin: 24px;
width: 95%;
}
#Line1Container, #Line2Container {
display: table-row;
}
.container {
border: 1px solid lightgray;
display: table-cell;
width: 33%;
border-radius: 10px;
}
As you see I tried the table-cell approach, but before I have tried the float: left approach.
Thanks
Fiddle
You can't properly use px values with % values together with dynamic sizes.
You should use x% instead of 24px.
And you can use float: left on the "cells"
How about using a table for separating the divs? that way with the td padding there will always be 24px between them
check out this fiddle:
http://jsfiddle.net/5zfEq/
added:
#Line1Container {
padding:12px;
}
#inner-table {
width: 100%;
}
#inner-table td {
padding: 12px;
}
based on #Edifice fiddle .... thanks ;)
I am looking to create a vertically scrolling website. I'll have a set of 5 divs that I want to have a height of 100% that are stacked on one another, basically making the body 1500% in height. Yeah?
Here is my code so far:
CSS
#contentWrapper {
position: relative;
width: 600px;
height: 1500%;
margin: 0 auto;
border: 1px solid red;
}
.panel {
position: relative;
height: 6.66%;
border: 1px solid blue;
}
.panelGuts {
position: relative;
top: 50%;
width: 100%;
height: 600px;
margin: -300px 0 0 0;
border: 1px solid green;
}
HTML:
<div id="contentWrapper">
<div class="panel">
<div class="panelGuts">
content
</div>
</div>
<div class="panel">
<div class="panelGuts">
content
</div>
</div>
<div class="panel">
<div class="panelGuts">
content
</div>
</div>
</div>
This seems to work in Safari, Firefox, and Chrome but it doesn't work on an iPad or iPhone, and knowing how IE like's to behave, it probably won't work there either.
What I am wanting to know is 1) Why is won't work on an iPad/iPhone, 2) is there a better way to do this, maybe with jQuery?
I need each panel to have a height of 100% and have the content (panelGuts) be vertically centered. I'll be using jQuery ScrollTo (or some scrollTo plugin) to scroll to each div. I'd like to NOT have to set a specific height to each div...
Can anyone help?
I actually figured this out with HTML5. It was pretty simple. For anyone who wants to see my results
CSS
body, html {
margin: 0px;
padding: 0px;
background: #FFF;
height: 100%;
}
#contentWrapper {
position: relative;
width: 600px;
height: 100%;
margin: 0 auto;
}
.panelContainer { display: inline; }
.panel {
position: relative;
display: table;
height: 100%;
width: 100%;
background:green;
}
article.panel:nth-child(2n+2) {
background:blue;
}
.panelGuts {
position: absolute;
top: 50%;
width: 100%;
height: 600px;
margin: -300px 0 0 0;
border: 1px solid black;
}
And my HTML
<div id="contentWrapper">
<section class="panelContainer">
<article class="panel">
<div class="panelGuts">
text 1
</div>
</article>
<article class="panel">
<div class="panelGuts">
text 2
</div>
</article>
</section>
</div>
And a Fiddle for you: http://jsfiddle.net/ryanjay/dwspJ/