Display two divs inline - html

I need to display two divs one next to another on the same line, but I can't understand why the second one is slightly lower than the first one.
<div class="cont-title">
<div class="triang-header"></div>
<div class="h2-stripe">
<h2 itemprop="name">
Title
</h2>
</div>
</div>
This is the css:
.cont-title{
margin-right: -7px;
min-width: 90%;
max-width: 100%;
height:51px;
float:right;
text-align:right;
white-space: nowrap;
}
.triang-header{
position:relative;
width:39px;
height:38px;
display:inline-block;
background:url('../images/titlebar.png') no-repeat top left;
}
.h2-stripe{
position:relative;
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
What am I doing wrong?

I think you did not count the line-height,
should be like this the style for .h2-stripe:
.h2-stripe{
position:relative;
line-height: 23px; // <----
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
box-shadow: 2px 3px 5px 0 #555;
}
here it is an example with line-height:23px for .h2-stripe: http://jsfiddle.net/6a0ga3uq/

you misspelled your class
.h2-strispe{
position:relative;
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
should be
.h2-stripe{
position:relative;
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}

The margin of your h2 element causes the second div to shift down. Also, you should vertical-align inline-block elements. See this updated snippet (also with corrected class name in CSS).
.cont-title{
margin-right: -7px;
min-width: 90%;
max-width: 100%;
height:51px;
float:right;
text-align:right;
white-space: nowrap;
}
.cont-title > * {
vertical-align: middle;
}
.triang-header{
position:relative;
width:39px;
height:38px;
display:inline-block;
background:url('http://placehold.it/39x38') no-repeat top left;
margin: 0;
}
.h2-stripe{
position:relative;
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
h2 {
margin:0;
}
<div class="cont-title">
<div class="triang-header"></div><div class="h2-stripe"><h2 itemprop="name">
Title
</h2>
</div>
</div>

In the second div, you have line height and lot of other stuff. So other elements can extend your div. If you want your div to be the same size regardless to its other elements you should change display attribute like this
.h2-strispe{
position:relative;
z-index:10;
display:inline-block;
box-sizing:border-box;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
You can see i added box-sizing to border-box and that will save the position of your div no matter what you do to inner elements

Related

How can I place this div next to the other one?

I was wanting to make a website, just to see if I like doing it and how it would turn out, but I can't seem to get this part done. I want the "informatie" div to be next to the "vertmenu" div and make it fill up the white part and I want the "vertmenu" div to extend till the "voetregel" div. I have no idea how to get this done and I have already tried changing the width and height to percentages, changing the positions to absolute/relative and adding a float property, but I couldn't make it how I wanted it to be. So my question in short, how can I make the "informatie" div next to the "vertmenu" div and make it fill up the white part and get the "vertmenu" div to extend till the "voetregel" div.
body {
margin:0;
padding:0;
background-color:#ffffff;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
#hormenu {
background-color: rgba(0, 0, 0, 0.5);
position:relative;
text-align: center;
width:100%;
height:15%;
line-height:50px;
font-size:100%;
}
#vertmenu {
background-color: rgba(255,0,0, 0.3);
position:relative;
height:100px;
top:15%;
width:15%;
margin:0px 0px 0px 0px;
padding:3px;
overflow:hidden;
}
#informatie {
background-color: rgba(0,0,255, 0.3);
position:relative;
float:left;
height:100%;
width:85%;
left: calc(15% + 6px);
margin:0px 0px 0px 0px;
padding:3px;
overflow:hidden;
}
#voetregel {
background-color: rgba(0,255,0, 0.3);
position:fixed;
width:100%;
height:100px;
top:auto;
right:0;
bottom:0;
margin-left:10px
}
a.hormenu_item {
margin: 10px;
transition: color 0.3s, text-shadow 0.3s, text-decoration-line 0.3s, font 0.3s ease-in-out;
}
a:link.hormenu_item {
color: white;
text-decoration: none;
}
a:visited.hormenu_item {
color: white;
text-decoration: none;
}
a:hover.hormenu_item {
color: gold;
text-decoration:none;
text-shadow: 0px 0px 7px gold;
font-size: 30px;
}
#informatie h1, #vertmenu h1, #voetregel h2 {
color:#FF0000;
font-size:20px;
}
<body>
<div id="hormenu">
Home
Biografie
Features
Contact
</div>
<div id="vertmenu">
<h1>vertmenu</h1>
</div>
<div id="informatie">
<h1>informatie</h1>
</div>
<div id="voetregel">
<h2>voetregel</h2>
</div>
</body>
apply float:left; css in #vertmenu and #informatie
and dont use position:fixed; in #voetregel use clear:both; it will clear the float effect of above 2 div tags
position:fixed; is used for creating menubar in web site so that even with the scrolling that menubar stays at same place
You can add display: inline-block to make them next to each other. Remove position:fixed from #voetregel too.
#vertmenu {
background-color: rgba(255,0,0, 0.3);
width:15%;
margin:0px 0px 0px 0px;
}
#informatie {
background-color: rgba(0,0,255, 0.3);
width:85%;
margin:0px 0px 0px 0px;
}
#voetregel {
background-color: rgba(0,255,0, 0.3);
width:100%;
height:200px;
}
#vertmenu,
#informatie {
display: inline-block;
float: left;
}
#informatie h1,
#vertmenu h1,
#voetregel h2 {
color:#FF0000;
font-size:20px;
}
<div id="vertmenu">
<h1>vertmenu</h1>
</div>
<div id="informatie">
<h1>informatie</h1>
</div>
<div id="voetregel">
<h2>voetregel</h2>
</div>

Place a DIV side by side with a SPAN, inside another DIV

I need to place the promo div in the right side of the alert div, just like this:
Please, can some CSS expert help me with this code: https://jsfiddle.net/08rnpxbt/4/
body {
width:640px;
float:left;
margin:0 6px 0 6px;
padding:18px;
font-family:Arial, Helvetica, sans-serif;
}
p {
padding:0;
margin:8px 0 0 0;
}
div.alert {
padding:8px 12px 8px 12px;
margin:20px auto 20px auto;
text-align:justify;
border:2px solid #389CF2;
border-radius:8px;
background-color:#F5F5F5;
background-image:url(http://i61.tinypic.com/1oxi50.png);
background-repeat:no-repeat;
background-position:8px 11px;
}
div.alert span {
display:block;
//float:left;
padding-bottom:2px;
margin-left:40px;
font-size:15px;
line-height:1.3em;
color:#5C5C5C;
}
div#promo {
display:block;
width:80px;
height:32px;
padding:4px 2px 2px 2px;
text-align:center;
line-height:15px;
font-size:14px;
color:#FF0000;
border:2px dotted #585858;
border-radius:16px;
background-color: #FFFFD5;
}
<body>
<div class="alert" style="width:530px; margin:0 auto 10px auto;">
<span>
<b>Windows 7 Home Premium - 02 License(s)</b><br>
Price: U$ 225.00 up to 10X or R$ 210.00 in cash
</span>
<div id="promo">15,00% de desconto !</div>
</div>
</body>
Just add this CSS rule to your #promo element:
#promo{
float: right;
}
and change this in your CSS:
div.alert span{
display: inline-block;
}
If you don' set inline-block the #promo will break in new line like you had it before.
Try it here
You can use flexbox attribute for this
just add display:flex and justify-content:space-between
div.alert {
display:flex;
justify-content:space-between;
padding:8px 12px 8px 12px;
margin:20px auto 20px auto;
text-align:justify;
border:2px solid #389CF2;
border-radius:8px;
background-color:#F5F5F5;
background-image:url(http://i61.tinypic.com/1oxi50.png);
background-repeat:no-repeat;
background-position:8px 11px;
}

How to center a div within a div? (margin: 0 auto; not working)

I have a div that is going to be used as a button, but it doesn't want to center within the larger div!
This is my CSS for the larger div:
.news-quarters{
width:189px;
height:300px;
position:relative;
float:left;
padding:10px;
padding-top:0px;
margin:10px;
text-align:left;
}
and for the button div:
.green-button{
width:auto;
height:auto;
position: relative;
float:none;
padding:0px;
margin: 0 auto;
background: #0A9C00;
background-size:auto;
border:1px outset #0A9C00;
border-radius: 3px;
-webkit-box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
-moz-box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
overflow:auto;
display:inline-block;
}
.green-button h4{
text-align:center;
color:white;
line-height:1;
margin:0px;
font-size:12px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
width:auto;
}
And my html like this:
<div class="news-quarters">
<div class="green-button">
<h4>Insert button text here</h4>
</div>
</div>
Can someone please help? This is severely p***ing me off :(
Thank you!
In the style .news-quarters change text-align:left to text-align:center;
There are already many existing answers for this problem see How to horizontally center a <div> in another <div>?

What CSS method would remove an outline of a div cross browser

I have two divs that join together that contain an image. The way the it is layered out the image is in two half's.
This works as intended but only views correctly in chrome. In the other browsers there is an outline or some layout error which causes the document to look different.
I presumed that outline:0; and border:0; would do the trick.
This is how the image should look. This is taken form chrome. As you can see there is nothing visually wrong with this.
Internet Explore
FireFox
Safari
CSS:
.login{
position:absolute;
left:50%;
margin-left:-150px;
top:50%;
margin-top:-200px;
width:300px;
height:400px;
border-radius:10px;
text-align:center;
display:table-cell;
vertical-align:central;
padding:0 0 0 0;
border:0;
border-style:none;
outline:0;
}
.login header{
height:75px;
width:100%;
margin-bottom:0;
padding:0 0 0 0;
border-style:none;
outline:0;
border:0;
}
.login header .logo{
width:150px;
height:75px;
outline:none;
margin-left:75px;
border:0;
border-style:none;
outline:0;
background:url(assests/logo_tiny.png) center 0px no-repeat;
background-color:#000;
border-radius:75px;
border-bottom-left-radius:0px;
border-bottom-right-radius:0px;
box-shadow:5px 5px 10px #000;
-moz-box-shadow:5px 5px 10px #000;
-webkit-box-shadow:5px 5px 10px #000;
-ms-box-shadow:5px 5px 10px #000;
-o-box-shadow:5px 5px 10px #000;
}
.login form{
outline:none;
width:100%;
height:245px;
padding:0 0 0 0;
padding-top:80px;
border:0;
border-style:none;
box-shadow:5px 5px 10px #000;
background:url(assests/logo_tiny.png) center -75px no-repeat;
background-color:#000;
-moz-box-shadow:5px 5px 10px #000;
-webkit-box-shadow:5px 5px 10px #000;
-ms-box-shadow:5px 5px 10px #000;
-o-box-shadow:5px 5px 10px #000;
border-radius:10px;
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
color:#FFF;
}
HTML:
<div class="login">
<header>
<div class="logo"></div>
</header>
<form>
</form>
</div>
Update: Fiddle
You made a mistake by flattening your logo.
It was 150px wide and only 75px high. Besides you've removed the border-radius at the bottom. On order to have a circle cast a circular shadow the whole div has to be square and the border-radius have to be equal.
See attached fiddle.
http://jsfiddle.net/mbh6W/2/
So the line you saw was in fact the box shadow of the circle that was flattened at the bottom.

IE7 doesn't put sentence a child row, cutting sentence

There are a lot of varying length tag divs in tag wrapper div. There isn't any problem for IE8,9, FF,Chrome,Safari and opera but it broken for IE7. How can I fix this issue?
HTML:
<div class="tag-wrapper">
<div class="tag">text text text</div>
<div class="tag">text text</div>
<div class="tag">text text</div>
<div class="tag">text text text</div>
<div class="tag">text text text text</div>
</div>
CSS:
.tag-wrapper{
float: left;
height: 200px;
padding: 12px 12px 12px 20px;
width: 500px;
overflow:hidden;
border:1px solid #000;
}
.tag-wrapper .tag{
background:url(img/corner02.png) no-repeat 0 0;
vertical-align:middle;
padding: 0 0 0 10px;
display:inline-block;
height:24px;
margin: 0 10px 9px 0;
float:left;
}
.tag-wrapper .tag a:link{
width:auto;
overflow:visible;
height:24px;
line-height:24px;
padding:0 5px 0 5px;
background:#F00;
float:left;
color:#FFF;
text-decoration:none;
font-weight:bold;
}
.tag-wrapper .tag a:hover{
color:#000;
}
Screenshot for IE8,IE9,Chrome,Firefox,Safari,Opera
Screenshot for IE7
http://jsfiddle.net/B7Tjw/2/
try this code: it is working fine.
.tag-wrapper .tag a:link{
width:auto;
overflow:visible;
height:24px;
line-height:24px;
padding:0 5px 0 5px;
background:#F00;
float:left;
color:#FFF;
text-decoration:none;
font-weight:bold;
white-space:pre;
}