I want to make a div grid with a bigger center div in the middle, but the small divs won't wrap properly. What must I change? I'm trying not to use tables because of bandwith and so on.
My HTML:
<div id="main">
<!-- a lot of .icon's here -->
<div class="icon"></div>
<div class="title"></div>
<div class="icon"></div>
<!-- a lot of .icon's here -->
</div>
My CSS:
#main {
display: inline-block;
margin: 5em 0 3em 0;
width: 66.2em;
height: 35.2em;
text-align: left;
overflow: hidden;
}
.icon {
background: #000;
height: 5em;
width: 5em;
margin: 0 0.2em 0.2em 0;
display: inline-block;
}
.title {
background: #777;
height: 10.2em;
width: 21.4em;
margin: 0 0.2em 0.2em 0;
display: inline-block;
}
Thanks in advance!
Here you go: Fiddle http://jsfiddle.net/fx62r/2/
inline-block leaves white-space between elements. I would use float: left; instead of inline block
Write elements on same line to avoid white-space. Like this:
<div class="icon"></div><div class="title"></div><div class="icon"></div>
And remove Margin:
.icon {
margin: 0 0.2em 0.2em 0; //Remove.
}
.title {
margin: 0 0.2em 0.2em 0; //Remove
}
#main {
display: inline-block;
margin: 5em 0 3em 0;
width: 66.2em;
height: 35.2em;
text-align: left;
overflow: hidden;
}
.icon {
background: #000;
float:left;
height: 5em;
width: 5em;
margin: 4% 0.2em 0.2em 0;
display: inline-block;
}
.title {
background: #777;
height: 10.2em;
width: 21.4em;
margin: 0 0.2em 0 0;
display: inline-block;
float:left;
}
please see this code, i hope it will helpful.
Related
I have a wrapper div, a navigation menu bar (floated to the left) and a button (floated to the right). How do I center the navigation bar (floated to the left) within the wrapper minus the area the button (floated to the right) takes up?
So instead of it being centered directly in the middle of the wrapper, it will be centered to the the left a bit more because the area the button takes up is not within the (center) calculation; if you will. Here's a quick graphic:
<div class="wrapper">
<div class="nav">
Center Me
</div>
<div class="cta">
Book Now
</div>
</div>
.wrapper {
max-width: 1200px;
margin: 0 auto;
background: #000;
color: #fff;
overflow: hidden;
}
div:not(.wrapper) {
display: inline-block;
}
div.cta {
float: right;
width: 100px;
background: #444;
padding: 20px 0;
text-align: center;
}
div.nav {
float: left;
background: #777;
text-align: center;
padding: 20px 0;
margin: 0 auto;
}
Use flexbox. Floats can be difficult and behave inconsistently. Flexbox is a great utility.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox
.wrapper {
max-width: 1200px;
margin: 0 auto;
background: #000;
color: #fff;
overflow: hidden;
display:flex;
flex-wrap: nowrap;
}
div:not(.wrapper) {
/* display: inline-block; */
}
div.cta {
/* float: right; */
/* width: 100px; */
background: #444;
padding: 20px 0;
text-align: center;
flex: 0 0 100px;
}
div.nav {
/* float: left; */
background: #777;
text-align: center;
padding: 20px 0;
margin: 0 auto;
flex: 1 0 auto;
}
I removed float from your .nav and added width (totalling 100%) to each container to get this result.
.wrapper {
max-width: 1200px;
margin: 0 auto;
background: #000;
color: #fff;
overflow: hidden;
}
div:not(.wrapper) {
display: inline-block;
}
div.cta {
float: right;
width: 20%;
background: #444;
padding: 20px 0;
text-align: center;
}
div.nav {
width: 80%;
text-align: center;
padding: 20px 0;
margin: 0 auto;
}
<div class="wrapper">
<div class="nav">
Center Me
</div>
<div class="cta">
Book Now
</div>
</div>
.div-1 {
background-color: #deb887;
margin: 0 auto;
width: 100%;
height: auto;
display: inline-block;
}
.div-2 {
background-color: #87ceeb;
margin: 0 auto;
width: 100%;
padding: 32px 0;
text-align: center;
}
<div class="div-1">..... some code here </div>
<div class="div-2">..... some code here</div>
a white space is coming between 2 div, under one another
I found some solution of this problem, but they are not working.
vertical-align: top; ----- not working
line-height: 0px; ------ it effects on the text of div
font-size: 0px; ------- it also effects on text
*{
margin:0;
padding:0;
------------------ not working
Please help, thanks in advance.
.div-1{
display: block;
width: 100%;
background-color: #deb887;
margin: 0 auto;
height: auto;
}
.div-2 {
height: 10px;
vertical-align: top;
background-color: #87ceeb;
margin: 0 auto;
width: 100%;
padding: 32px 0;
text-align: center;
}
Try this way:
<div class="div-1">..... some code here </div><!--
--><div class="div-2">..... some code here</div>
Please note the comment syntax
HTML:
<div id='inner'>I am sam <em>I am em</em> I am sam</div>
CSS:
#inner {
width: 400px;
height: 400px;
background-color: cyan;
}
em {
margin: 1em;
padding: 1em;
display: inline-block;
vertical-align: top;
}
Result: https://jsfiddle.net/cbukkt3m/1/
Why does it throw the surrounding text to the top and not the em itself?
It is aligned to the top, it's being pushed down by:
margin: 1em;
padding: 1em;
try removing these or changing them to
margin: 0 1em;
padding: 0 1em;
Having trouble getting my image to center, while remaining on the same horizontal level as my icon.
HTML
<div class="smalltop w3-top">
<span class="w3-opennav w3-xlarge" onclick="w3_open()"><i id="menui" class="material-icons w3-xxlarge">menu</i></span>
<img id="smalllogo" src="img/navlogo-invert.jpg">
</div>
CSS
#smalllogo {
max-height: 50px;
width: auto;
display: block;
margin: 0 auto;
border: 5px solid;
margin-top: 5px;
}
#menui {
left: 0;
}
.smalltop {
background-color: #FFF;
list-style-type: none;
margin: 0 auto;
}
https://jsfiddle.net/pzLbruhx/
Add relative positioning to the container and absolute positioning to the icon
#menui {
left: 0;
position:absolute;
}
.smalltop {
background-color: #FFF;
list-style-type: none;
margin: 0 auto;
position:relative;
}
jsFiddle example
Just give property float:left to #menui, and see the result
Use display:table\table-row\table-cell and vertical-align on icon
#smalllogo {
max-height: 50px;
width: auto;
display: table-cell;
margin: 0 auto;
border: 5px solid black;
margin-top: 5px;
}
.w3-opennav {
display: table-cell;
vertical-align: middle;
}
.smalltop {
background-color: #FFF;
list-style-type: none;
margin: 0 auto;
display: table-row;
}
Fiddle
I am trying to put a margin in left and right of the rhombus but couldn't.
Basically I am styling < hr > in to a custom styled hr
Code:
<div class="container">
<hr class="square gold">
<p>some text</p>
</div>
Demo :http://jsfiddle.net/squidraj/03xw85w0/
Any help is highly appreciated. Thanks in advance.
Basically, you can't do this with an hr...you would have to use a span or some such other element.
Then you can follow the techniques as detailed in the linked question HERE.
body {
text-align: center;
}
.divider {
width: 70%;
margin: 20px auto;
overflow: hidden;
text-align: center;
line-height: 1.2em;
display: inline-block;
}
.divider:before,
.divider:after {
content: "";
vertical-align: top;
display: inline-block;
width: 50%;
height: 0.65em;
border-bottom: 1px solid black;
margin: 0 2% 0 -55%;
}
.divider:after {
margin: 0 -55% 0 2%;
}
<span class="divider">◊◊</span>