CSS div align horizontal in same line - html

Hi I have use CSS to positioning my div box and this is my result:
-------
div i
box1 i
-------
----------
i div i
i box2 i
----------
-------
i div
i box3
-------
I'm sorry that I was unable to upload an image becuz my reputation point is just 2 only, Ok let's continue, the result above I get is breaking each div box into new line but I don't want to be like that, the result I want is align the 3 div boxes into same horizontal line like this:
------ --------- ------
i i i i
i i i i
------ --------- ------
this is my CSS code, can someone correct my mistake?
#divbox1{
display: flex;
height: auto;
width: 40%;
margin-top: 5%;
margin-left: -25%;
position: relative;
border-style: solid;
border-color: #888888;
}
#divbox2{
display: flex;
height: auto;
width: 60%;
margin-top: 5%;
margin-left: auto;
margin-right: auto;
position: relative;
border-style: solid;
border-color: #888888;
}
#divbox3{
display: flex;
height: auto;
width: 40%;
margin-top: 5%;
margin-left: 85%;
position: relative;
border-style: solid;
border-color: #888888;
}
Addition point: I want to show 20% display of the the divbox1 and 3 only that's why im using -% margin

#divbox1{
float:left;
height: 50px;
width: 10%;
position: relative;
border-style: solid;
border-color: #888888;
}
#divbox2{
float:left;
height: 50px;
width: 50%;
position: relative;
border-style: solid;
border-color: #888888;
}
#divbox3{
float:left;
height: 50px;
width: 20%;
position: relative;
border-style: solid;
border-color: #888888;
}
<div id='divbox1'></div>
<div id='divbox2'></div>
<div id='divbox3'></div>
Don't use
display:flex;
Instead just go
float:left;
in each of the boxes. And play around with the widths, you might need to lessen the values a little bit. and get rid of those margins.

You are using display:flex; wrong. It needs to be applied to a parent container to work the way you are expecting it to. You'll need to add an extra div encasing the whole thing like this:
<div id="group">
<div id="divbox1"></div>
<div id="divbox2"></div>
<div id="divbox3"></div>
</div>
After doing that, you will need to remove display:flex; from the inner divs. And add it to the grouping div. The resulting CSS should look something like this:
#group{
display:flex;
width:100%;
}
#divbox1{
flex:4;
margin-top: 5%;
margin-left: -25%;
position: relative;
border-style: solid;
border-color: #888888;
}
#divbox2{
flex:6;
margin-top: 5%;
margin-left: auto;
margin-right: auto;
position: relative;
border-style: solid;
border-color: #888888;
}
#divbox3{
flex:4;
margin-top: 5%;
margin-left: 85%;
position: relative;
border-style: solid;
border-color: #888888;
}
Adding the flex:4; or flex:6; to each inner div is basically telling the flexbox what size you want your divs in relation to each other. Then, by default, flexbox will fit them to the width of the screen unless you have things like min-width on your divs.
Hope I helped. Cheers.

Is this were you looking for..?
.container {
width: 960px; /* define your container width */
}
.box {
width: 30%; /* whatever width */
height: 200px; /* whatever height */
background: #ccc;
margin: 30px 1%;
float: left;
}
<div class="container">
<div class="box box1">
<!-- your content goes here -->
</div>
<div class="box box2">
<!-- your content goes here -->
</div>
<div class="box box3">
<!-- your content goes here -->
</div>
</div>

Related

Have an arrow from one div go into another

I need to achieve something like this:
representation
I have found similar issues but they do not completely cover my task. Here is an example of a thing I have found:
.blue-background {
background-color: blue;
border-radius: 5px;
top: 3em;
left: 230px;
padding: 10px;
font-family: Roboto, sans-serif;
font-size: 14px;
line-height: 22px;
color: #313333;
display: flex;
align-items: center;
width: 260px;
}
.blue-background::after {
content: ' ';
width: 0px;
height: 0px;
border-top: 25px solid transparent;
border-left: 37px solid blue;
border-bottom: 25px solid transparent;
border-right: 0px solid transparent;
position: absolute;
top: 43%;
left: 47%;
}
.child-image-wrapper {
max-width: 260px;
margin: auto;
img {
max-width: 260px;
}
}
<div class="col-md-4 col-xs-12">
<div class="image-block">
<div class="blue-background">
<h2>Some Text <span class="arrow"></span></h2>
</div>
<div class="child-image-wrapper">
<img src="This is an image" />
</div>
</div>
Now the problem with the above CSS is that this works only at particular screen size (like 585px or so) otherwise the arrow "detaches" from the left div and goes into the right div. What I need is for the blue arrow to be stuck to the left div even if the screen size changes. Would it be possible to achieve this in some way? Sorry I am pretty new to front-end design
You can do it like so:
.wrapper {
width: 10em;
height: 2em; /* Height needs to match .right::after height and width */
display: flex;
}
.left {
background-color: lightblue;
width: 50%;
}
.right {
background-color: lightpink;
border-left: 1px solid purple;
width: 50%;
position: relative;
overflow: hidden;
}
.right:before {
height: 2em; /* Match height above*/
width: 2em; /* Match height above*/
background-color: #b77681;
position: absolute;
top: 50%;
left: 0%;
content: "";
border: 1px solid #864954;
transform: translate(-73%, -50%) rotate(45deg);
}
<div class='wrapper'>
<div class='left'>
</div>
<div class='right'>
</div>
</div>
I encourage you to read more about the position property (in our case specifically absolute and relative). here you can find some introduction.
As per your question change the top and left properties in .blue-background::after to fit the position for the arrow as you want.
here is an example: https://jsfiddle.net/qa9un7fy/

CSS three layer div

My code:
#Parent {
border-radius: 8px;
background-color:#cccdce;
width:70%;
height:500px;
float:left;
}
#child {
padding:15px;
border-radius: 8px;
background-color:blue;
width:100%;
height:20px;
float:left;
}
<div id="Parent">
<div id="child">
<div>aaaa</div>
</div>
</div>
What I now have is:
I want to know why padding is not working? Isn't padding is supposed to set the space between parent and child element? Why it is not working and overlapping?
I want to do this:
use flexbox and remove floats, and FYI your padding needed to be set in parent not child
#Parent {
border-radius: 8px;
background-color: #cccdce;
width: 70%;
height: 500px;
display:flex;
padding: 15px;
}
#child {
padding: inherit;
border-radius: 16px;
background-color: blue;
height: 20px;
flex:1
}
<div id="Parent">
<div id="child">
aaaa
</div>
</div>
Check this out.
#Parent {
border-radius: 8px;
background-color: black;
width: 70%;
height: 500px;
padding: 15px;
}
#child {
border-radius: 8px;
background-color: white;
padding: 15px;
height: 470px;
}
#grand {
border-radius: 8px;
background-color: blue;
width: 100%;
height: 20px;
}
<div id="Parent">
<div id="child">
<div id="grand">aaaa</div>
</div>
</div>
It would help if you give padding to the right element. Right now you are assigning 15px padding to the child. That's the reason why there is 15px space between the text and the child. If you add a padding to the parent-id, you create "space between parent and child element":
#Parent {
padding: 15px;
}
You can move your padding to the parent and remove the floats. This will give you the expected result.

How to center CSS-shapes within a wrapper in a row

how do I center shapes that are within a wrapper in a row. So far Iv got them into the row but I cant get them to center horizontally.
Here is the html code that deals with that part:
.wrapper {
overflow: hidden;
/*make sure the wrapper has no dimension*/
margin-bottom: 10px;
margin-left: 25%;
margin-right: 25%;
}
.pMan {
width: 0px;
height: 0px;
border-right: 60px solid transparent;
border-top: 60px solid red;
border-left: 60px solid red;
border-bottom: 60px solid red;
border-top-left-radius: 60px;
border-top-right-radius: 60px;
border-bottom-left-radius: 60px;
border-bottom-right-radius: 60px;
float: left;
}
<div class="wrapper">
<div class="pMan"></div>
<div class="pMan"></div>
<div class="pMan"></div>
</div>
<div id="todoapp" ng-controller="ToDoCtrl">
Thanks :-)
You need to remove your float:left property from your pac man class, and add a text-align:center to your wrapper class.
Text-align;
This property describes how inline-level content of a block container is aligned. Values have the following meanings:
Demo:
.wrapper {
overflow: hidden;
/*make sure the wrapper has no dimension*/
margin-bottom: 10px;
text-align: center;
}
.pMan {
width: 0px;
height: 0px;
border-right: 60px solid transparent;
border-top: 60px solid red;
border-left: 60px solid red;
border-bottom: 60px solid red;
border-top-left-radius: 60px;
border-top-right-radius: 60px;
border-bottom-left-radius: 60px;
border-bottom-right-radius: 60px;
display: inline-block;
}
<div class="wrapper">
<div class="pMan"></div>
<div class="pMan"></div>
<div class="pMan"></div>
</div>
<div id="todoapp" ng-controller="ToDoCtrl">
Reasoning behind Actions:
Removing Float:left and adding display:inline-block
The float property takes the element out of the normal document flow, meaning it no longer 'acts' like it is within the wrapper div (in basic terms). Since the div element is defaulted to display:block, we need to add display:inline-block so that the pac man can be in the same line.
Adding text-align to the wrapper
Adding a text-align declaration means that all internal/child elements will be aligned in this way. This means that you can align the pac men to the center of the parent.
Removing the margin-left and margin-right
Since the wrapper is 100% width by default (since this wasn't edited/declared before), the extra 25% margin either side was making the pacmen 'wrap' to the next line. Removing that allows all three to sit on the one line as outlined in your question.
Remove the float:left on the elements, set them to display:inline-block, and set the wrapper to text-align:center;
.wrapper {
overflow: hidden;
/*make sure the wrapper has no dimension*/
margin-bottom: 10px;
margin-left: 25%;
margin-right: 25%;
/*add this*/
text-align:center;
}
.pMan {
/*add this*/
display:inline-block;
/* and remove the float */
width: 0px;
height: 0px;
border-right: 60px solid transparent;
border-top: 60px solid red;
border-left: 60px solid red;
border-bottom: 60px solid red;
border-top-left-radius: 60px;
border-top-right-radius: 60px;
border-bottom-left-radius: 60px;
border-bottom-right-radius: 60px;
}
<div class="wrapper">
<div class="pMan"></div>
<div class="pMan"></div>
<div class="pMan"></div>
</div>
<div id="todoapp" ng-controller="ToDoCtrl">

Aligning a div within another div

Ok here is my site http://joshadik307.github.io/. And here is the specific code I need help with
CSS:
.pagemenu {
padding-top: 25px;
padding-right: 2%;
padding-left: 2%;
text-align: center;
}
.bubblewrap {
display: inline-block;
vertical-align: top;
width: 23%;
margin-right: 5%;
margin-left: 5%;
text-align:center;
}
.bubble {
background-color: white;
border-radius: 50%;
border-style: solid;
border-width: 5px;
border-color: black;
width: 250px;
height: 250px;
display: inline-block;
}
HTML for one of the 5 circles (I figured it would save space to just show one, but they all use the same html and are all wrapped in the same pagemenu div)
<div class = "pagemenu">
<div class = "bubblewrap">
<div class="bubble">
<div class="text">
ABOUT
</div>
</div>
</div>
</div>
Ok now here is the problem. If you look at my sight (linked to above) basically I have 5 circle divs set up to align themselves in the shape of a W at the top of the page (under the header.) The problem is the W is not always center aligned on the page, and after looking at the source on chrome, I realized that this is because the "bubbles" are not always horizontally centered within the bubble wrapper. Does anyone know how I can fix it so that the bubble div always aligns itself horizontally within the bubblewrapper div?
Add margin: auto; into your .bubble class
.bubble {
background-color: white;
border-radius: 50%;
border-style: solid;
border-width: 5px;
border-color: black;
width: 250px;
height: 250px;
margin: auto;
}
A margin:0 auto; to your .bubble class will do the fix :)

2 Divs next to eachother

I'm trying to put a logo and a sidebar next to eachother, but it just won't work. The logo container needs to be centered at the top. And the sidebar needs the be at the top-left Can you help me? I already tried float, no succes. :(
code:
<body>
<center>
<div id="logo1">
<div id="logo2"></div>
</div>
</center>
<div id="sidebar1">
<a href="https://test.com/" target="blank">
<div id="test1"></div>
</a>
</div>
</body>
CSS:
#test1 {
display: inline-block;
position: absolute;
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/2.png');
height: 45px;
width: 45px;
}
#test1:hover {
display: inline-block;
position: absolute;
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/1.png');
height: 45px;
width: 45px;
}
#sidebar1 {
display: inline-block;
position: relative;
border: 1px solid;
margin-top: -10px;
margin-left: -15px;
background-image:url('Afbeeldingen/lol.png');
height: 1080px;
width: 118px;
}
#logo1 {
display: inline-block;
position: relative;
border: 1px solid;
margin-top: 10px;
height: 100px;
width: 700px;
}
Ok, This is what you have to do :
You need to remove the display:inline-block from #logo1
And instead of just writing margin-top:10px , you need to use margin:0px auto, or you could write margin:10px auto. By this, it will center your #logo1 div.
But to center a "div" , you need to have another container(div) that wrap within your div. So that it will know, from which side to which side that it will have to be "centered".
For that reason, you will need to create another div or container around your #logo1 div, and lets assume it is called "right" (see the code below).
And for this div/container to be just beside your sidebar, it will need to have a relative position same as your sidebar. Now, you can just float both of your #sidebar1 and also your #logo1 to the left.
Thus, you dont have to use that negative margin for your sidebar anymore (remove that). If you wanted to use the negative margin, you have to use the absolute position in this case. But you will then have to restructure your whole #logo1 div which will create a lot of works.
This is the full code for your reference :
HTML code :
<div id="container">
<div id="sidebar1">
<a href="https://test.com/" target="blank">
<div id="test1">This is sidebar</div>
</a>
</div>
<div id="right">
<div id="logo1">
<div id="logo2"><This is logo</div>
</div>
</div>
</div>
And use this CSS :
#container{
width:1000px;
height:1080px;
position:absolute;
border:1px solid #000;
}
#test1 {
display: inline-block;
position: relative;
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/2.png');
height: 45px;
width: 45px;
}
#test1:hover {
display: inline-block;
position: relative;
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/1.png');
height: 45px;
width: 45px;
}
#sidebar1 {
display: inline-block;
position:relative;
float:left;
border: 1px solid;
background-image:url('Afbeeldingen/lol.png');
height: 1080px;
width: 118px;
border:1px solid red;
}
#right{
position:relative;
float:left;
margin-top:0px;
width:870px;
height:100px;
}
#logo1 {
position:relative;
border: 1px solid;
margin: 0px auto;
height: 100px;
width: 700px;
}
Do you want this ?
#test1 {
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/2.png');
height: 45px;
width: 45px;
}
#test1:hover {
background-image:url('Afbeeldingen/1.png');
}
#sidebar1 {
position:absolute;
border: 1px solid;
background-image:url('Afbeeldingen/lol.png');
height: 1080px;
width: 118px;
}
#logo1 {
border: 1px solid;
margin-top: 10px;
height: 100px;
width: 700px;
}
<div id="sidebar1">
<a href="https://test.com/" target="blank">
<div id="test1"></div>
</a>
</div>
<div id="logo1">
<div id="logo2"></div>
</div>
I assume this is what you want? http://jsfiddle.net/Le6PH/
You should do:
Remove the negative margins (If you don't know what you are doing, don't use negative margins)
Remove the <center> tag (This tag is deprecated since EVER)
Remove the margin of your logo
Add a wrapper div around your whole structure
Add the following CSS to that div
CSS
.wrapper{
position:relative;
width:818px; /* sidebar width + logo width */
}
Change position:relative; to position:absolute for your logo & sidebar divs.
Add top:0; for both divs
Add right:0; for the sidebar div
EDIT:
With a centered logo, like this (http://jsfiddle.net/Le6PH/1/) you'll need to change 2 things:
Add a margin-left:118px; to the logo div
Change the width of the wrapper to width of logo + margin logo + width of sidebar.
Try floating your div, it should look like this..
<div class="row">
<div id="log"></div>
</div>
<div class="row">
<div id="sidebar"></div>
</div>
css
.row{
float: left;
width: 50%;
}