I have 2 divs, one should be on left side and the other on right side but in same line.
Behind I want to have parent div (#author-box) with grey background that will have height depending on the right div text height, so when you change devices if author-txt goes below author-img the gray background should be behind both of the divs.
I tried float left but then the gray background is really small and doesn't follow author-txt and author-img height.
Also I tried display:inline, but then text starts from the lower part of the image.
<div id="author-box">
<div class="author-img"><img src="img.jpg" width="150px" height="149px" /></div>
<div class="author-txt"><strong>About the author</strong><br/>author text<br/><strong>Connect with me:</strong> FaceBook | LinedIn | Twitter</div>
</div>
#author-box {
background-color: #ECECEC;
margin-bottom: 10px;
font-size: 15px;
padding: 10px;
}
.author-img{}
.author-img img{
border-radius: 100px;
}
.author-txt{}
It's very simple: (there are many other ways too)
.author-img {
display:inline-block;
}
.author-txt {
display:inline-block;
vertical-align: top;
}
Demo: http://jsfiddle.net/sem3qyyo/
If you want to use floating, you will need to "clear" the container:
#author-box:after { /* just one method of clearing, there are others too */
display:table;
clear: both;
content:" ";
}
.author-img {
float:left;
}
.author-txt {
float:left;
}
Demo: http://jsfiddle.net/sem3qyyo/1/
Or use floating and overflow: auto; on the container if your design allows it:
#author-box:after {
overflow: auto; /* add this */
background-color: #ECECEC;
margin-bottom: 10px;
font-size: 15px;
padding: 10px;
}
.author-img {
float:left;
}
.author-txt {
float:left;
}
Demo: http://jsfiddle.net/sem3qyyo/2/
And this can go on!
Related
I have two divs next to each/side by side..
The LEFT div has a FLUID width.
The RIGHT div has a static wdth.
When I resize the screen/browser... it work great! (and as intended).
However because of the way it was set up:
(Fiddle example: http://jsfiddle.net/VHcPT/384/)
The RIGHT div in physically first in the mark-up..(and floated RIGHT).
However at say 768px breakpoint.. I need this RIGHT (static) DIV to stack UNDER the LEFT div.. how can I achieve this?
If I physically have the RIGHT div AFTER the LEFT div in the markup.. it would stack as expected.. but I need to have it FIRST so the fluid/static behavior in place works as it should.
So to re-cap, its NOT about getting the two divs next to each other one fluid, one static.. its how to handle that at a responsive/breakpoint.. and get the static (RIGHT) div to stack UNDER the fluid (LEFT) div
Using the fiddle example.. the RED DIV would go UNDER (stack) the GREEN lines/div.. (the green would then be full width).. at a certain breakpoint.
and because code is required now:
HTML:
<div id="contentcontainer">
<div class="rightcontainer">mm</div>
<div class="leftcontainer">
<div class="item_1">
some text
</div>
<div class="item_2">
some text
</div>
</div>
</div>
CSS:
#directorycontainer {
padding:10px 10px;
display:table;
box-sizing: border-box;
width: 100%;
font-size: 0.8em;
font-weight: normal;
}
.directory {
background: green;
margin-right: 10px;
overflow: hidden;
padding-right: 10px;
position: relative;
}
.mapcontainer {
background: red;
display:table;
width:240px;
height:480px;
float:right;
position:relative;
overflow: hidden;
}
.providercontainer{
background-color: #f7f9fb;
border: 1px solid #e1dacd;
display: table;
margin-bottom: 0.625em;
padding: 0;
width: 100%;
}
OK well looks like this works and should be an acceptable answer/solution:
Fiddle:
http://jsfiddle.net/VHcPT/389/
HTML/Markup:
<div id="contentcontainer">
<div class="leftcontainer">
<div class="item_1">
some text
</div>
<div class="item_1">
some text
</div>
</div>
<div class="rightcontainer">mm</div>
</div>
CSS:
* {box-sizing: border-box;}
#contentcontainer {
padding:10px 10px;
display:table;
box-sizing: border-box;
width: 100%;
font-size: 0.8em;
font-weight: normal;
}
.leftcontainer {
background: green;
overflow: hidden;
padding: 5px;
float:left;
width:calc(100% - 240px);
}
.rightcontainer {
background: red;
display:table;
width:240px;
height:480px;
float:left;
position:relative;
overflow: hidden;
}
.item_1{
background-color: #f7f9fb;
border: 1px solid #e1dacd;
display: table;
margin-bottom: 0.625em;
padding: 0;
width: 100%;
}
works with whatever breakpoints you set and the elements will stack correctly.
you may like my FLEXBOX alternative to you problem. It may take a bit of practice, but it will eventually give you much more control.
The FIDDLE
Below the basic CSS structure, no other 'display', 'position' or 'overflow' needed. With this structure you can mix-match any number of fixed and/or fluid columns.
.flex--box { display: flex; flex-flow: row wrap }
.flex--fluid { flex: 1 1 auto }
.flex--fixed { flex: 0 0 auto; min-width: 240px }
/* MOBILE MQ */
#media all and (max-width: 360px) {
.flex--fluid, .flex--fixed {
flex: 1 1 auto;
}
}
Let me know if you have problem with it.
And of course, do give credit if you think it is worth it.
( BTW: I changed the colors to something less retina intensive &D )
I'm trying to make that one div in a navbar gets a top-padding when I hover it. My problem is that all my divs makes the same effect (they all go down), and I just want one of them to make this (the one I'm hovering), and I want the others to stay in the same place, with the same height, without any changes.
The current situation is this one: http://jsfiddle.net/3S8ZB/1/
This is my current CSS:
div {
height: 2em;
width: 6em;
border-radius: 5px;
background-color: orange;
display:inline-block;
}
div:hover{
padding-top:2em;
}
What do you suggest?
Demo
inline-block elements are vertically bottom alligned by default. Add vertical-align: top;
css
div {
height: 2em;
width: 6em;
border-radius: 5px;
background-color: orange;
display:inline-block;
vertical-align: top; /* add this */
}
div:hover {
padding-top:2em;
}
Not sure if understood becuse it looks like you are very close to that.
Padding on the hovered item and keeping the siblings vertically aligned to the top.
http://jsfiddle.net/2UvSa/
div {
height: 2em;
width: 6em;
border-radius: 5px;
background-color: orange;
display:inline-block;
vertical-align: top;
transition: padding .5s ease-in;
}
div:hover{
**padding-top:2em;**
}
Put vertical-align: top; on div.
JSFiddle Demo
I'm currently learning HTML. I'm trying to add 3 images inside a div, the images need to have the same amount of space between them. How to do this?
Example: https://docs.google.com/drawings/d/1WZdL0WVz-VndX2qP0Ig0S8fZnCGW2k37RHvWXLdgWz0/edit?usp=sharing
The code I currently have:
<style type="text/css">
.maindiv{
position: relative;
width:90%;
height:50%;
border-style:solid;
border-color:Red;
border-width:2px;
}
.imgbott{
height:auto;
width:auto;
max-width:200px;
max-height:200px;
float:left;
text-align: center;
}
</style>
<body>
<div class="maindiv">
<div class="imgbott">
<img src="https://sites.google.com/a/itcld.com.br/portal-de-treinadores/_/rsrc/1377018552616/imagens/images.jpg" alt="">
<a>TESTE</a>
</div>
<div class="imgbott">
<img src="https://sites.google.com/a/itcld.com.br/portal-de-treinadores/_/rsrc/1377018552616/imagens/images.jpg" alt="">
<a>TESTE</a>
</div>
<div class="imgbott">
<img src="https://sites.google.com/a/itcld.com.br/portal-de-treinadores/_/rsrc/1377018552616/imagens/images.jpg" alt="">
<a>TESTE</a>
</div>
</div>
</body>
Code runing: https://script.google.com/a/macros/itcld.com.br/s/AKfycbyjeAIFhKnAXzvXd8lS3S-ND4H0n63i-FBxr-i9Z1omeFmBYtA/exec
Thank you.
Change your css to:
.imgbott{
margin: 0px 10px;
height:auto;
width:auto;
max-width:200px;
max-height:200px;
float:left;
text-align: center;
}
The margin: 0px 10px means 0px margin to the top and bottom, and 10px margin to the left and right. Maybe one would expect 20px margin between the divs then, but there is a effect called "margin collapsing" which prevents that.
is this what you looking for
http://jsfiddle.net/Gfnjz/
.box {
display:table;
table-layout:fixed;
min-width:900px; /* some minimum width is a good idea. */
border-spacing:20px 0; /* note that spacing is also applied to right and left ends */
background-color:#666;
margin:0 auto;
}
.box div {
display:table-cell;
width:33%;
vertical-align:middle;
border:1px solid #bbb;
background-color:#eee;
padding:30px;
}
You can do something like this:
.divName{
width:300px;
display: inline-block;
margin: 0 20px 0 0;
float: left;
}
Then for the last box, apply a .lastBox class as well to force no margin, that way they are perfectly centered, assuming your parent container is centered that is:
.lastBox{
margin-right: 0;
}
The HTML:
<div class="divName">
<p>stuff</p>
</div>
<div class="divName">
<p>stuff</p>
</div>
<div class="divName lastBox">
<p>stuff</p>
</div>
if you only want the same space between the "imgbott" divs, set their margin instead of width attribute.
Your class will looks like
.imgbott{
margin: 0px 10px;
float: left;
text-align: center;
}
.imgbott a
{
display:block;
}
Then doesn't matter what is the width of the images inside, the space will always be 20px between the images.
In additional you can remove the margin-left of the first image using the first-child selector
.imgbott:first-child {
margin-left:0px;
}
You can achieve this result by using inline-blocks and text-align: justify, with adding some fake content before and after the divs to be aligned via pseudo-elements:
.maindiv{
width:90%;
border: 2px solid red;
text-align: justify; /* turns on justification 'magic' */
line-height: 0; /* removes extra space below divs because of extra line */
}
.maindiv:before {
font-size: .1px;
content: 'i'; /* adds nearly invisible fake content in the beginning of the line */
}
.maindiv:after {
font-size: .1px;
content: 'i i'; /* adds nearly invisible fake content in the of the line */
word-spacing: 99in; /* huge word-spacing assures that the 2nd 'i' wraps to the next line making 'justify' work */
background: #ccc;
}
.imgbott{
display: inline-block;
line-height: 1; /* restore the normal line height inside divs */
}
JSFiddle
Optionally, you can prohibit the wrapping of the divs if the container is narrower than the sum of their widths by adding white-space: nowrap to the container and normal to its :after: see edited JSFiddle
This solution may look a bit tricky, but it works for arbitrary number of blocks of arbitrary (possibly different) widths.
Trying to make navigation with Previous and Next button.
Want the Previous and Next to be on both ends of the screen. They need to be responsive and float closer to each other with the size of the screen. However, the previous and next buttons can't be one over the other.
My current CSS and HTML is as follows:
HTML
<div id="navigation_wrapper">
<div>previousnext</div></div>
Connected CSS
div#navigation_wrapper {
width: 100%;
padding: 5px 0px 30px 0px;
background-color: orange;
opacity:0.8;
}
You should float the elements like so
CSS
div#navigation_wrapper {
width: 100%;
background-color: orange;
opacity:0.8;
}
#prev-button {
float:left;
}
#next-button {
float:right;
}
HTML
<div id="navigation_wrapper">
<a id="prev-button" href="previous.html">previous</a>
<a id="next-button" href="next.html">next</a>
</div>
Float the buttons left / right accordingly and to avoid them colliding set min-width on the body tag
quick demo
body{
min-width:120px
}
div#navigation_wrapper {
width: 100%;
padding: 5px 0px;
background-color: orange;
opacity:0.8;
overflow:hidden;
}
a[href*="previous.html"]{
float: left;
}
a[href*="next.html"]{
float: right;
}
So, I had help from before, but my stuff was so unorganized, that it was hard for me to understand what someone was doing. It left me off here, I have my vertical alignment, but now my footer for some reason cuts off half way and my social icons stay right beside my powered by even though they're suppose to be aligned/floating to the right...
http://jsfiddle.net/4KDEM/
HTML
<div id="footer">
<div id="footerContent">
<div id="leftFooter">
$POWERED_BY$
</div>
<div id="rightFooter">
<img src="http://zevoxa.com/images/social/facebook.png" />
<img src="http://zevoxa.com/images/social/twitter.png" />
<img src="http://zevoxa.com/images/social/youtube.png" />
<img src="http://zevoxa.com/images/social/deviantart.png" />
</div>
</div>
</div>
CSS
#footer {
background-image:url('/images/footer_bg.png');
bottom repeat-x;
height: 110px;
display:table-cell;
vertical-align: middle;
}
#footerContent {
display:table;
width:100%;
}
#leftFooter {
float: left;
font-family:maven;
font-size: 15px;
padding-left: 20px;
}
#rightFooter {
float: right;
text-align:right;
}
You can fix the layout by adjusting your CSS as follows:
#footer {
background-image:url('http://zevoxa.com/images/footer_bg.png');
bottom repeat-x;
width:100%;
height: 110px;
}
#footerContent {
display:table;
width: inherit; /* You can adjust this depending on other design factors*/
height: inherit;
}
#leftFooter {
display:table-cell;
vertical-align: middle;
font-family:maven;
font-size: 15px;
padding-left: 20px;
border: 2px dotted yellow; /* just to show where the edges are*/
}
#rightFooter {
display:table-cell;
vertical-align: middle;
text-align:right;
border: 2px dotted yellow;
}
See Fiddle: http://jsfiddle.net/audetwebdesign/Pfrj8/
Set #footerContent to display: table and inherit the height from the parent element (#footer). You can set the width in a variety of ways depending on what you need. In my example, I set it to full width, default behavior.
For the two child elements, set their display type to table-cell and vertical-align: middle, you already have text-align set the right way. By default, the two cells will be of equal size, 50% of the parent's width.
No need for floats.
Aside
You may not need the two wrappers, #footer and #footerContent unless you need the second div for some other purpose (extra background image for example). Depends on other factors in your design. (See second example in fiddle.)
If your site isn't a responsive site, you just need to add a width like so: #footer {width:500px;}