How to make two HTML element align in single line? - html

I have two HTML element in one row. Whoch should display something like this:
For that I made both the element display-inline and also I set float left and right respectively. But they are displaying something like this:
You can see they are not being aligned properly.
.selected-account{
display: inline;
float: right;
color: #0679ca;
}
.select-account-accordion{
display: inline;
float: left;
color: #0679ca;
}
<div id="select-account" class="col-sm-12 col-md-12 disabled-billing-accordion">
<h3 id="select-acct" class="select-account-accordion">Select Account(s)</h3>
<span id="account-selected" class="selected-account">0 of 8 account selected</span>
</div>
Can you please suggest on this?
Edit: I think because I put those two element in the div class which I put for creating accordion, so thats why its creating trouble. Please see the style below for that div which is having class "disabled-billing-accordion"
.disabled-billing-accordion h3::before{
background: url("/static/img/accordion.png") no-repeat scroll 0 0
rgba(0, 0, 0, 0);
background-position: -1px -97px;
content: " ";
width: 34px;
height: 34px;
left: 0;
position: absolute;
top: 25px;
margin-left: 1em
}
.disabled-billing-accordion h3{
padding: .2em 0 0 3em;
color: #0679ca;
font-size: 1.5em;
line-height: 2.1875em;
margin-bottom: 8px;
font-weight: 100 !important
}
.disabled-billing-accordion{
padding: 10px;
border-bottom: 1px solid #bdbdbd
}

HI now you can define margin:0; and line-height as like this
.selected-account{
float: right;
color: #0679ca;
margin:0;
line-height:20px;
}
.select-account-accordion{
float: left;
color: #0679ca;
margin:0;
line-height:20px;
}
<div id="select-account" class="col-sm-12 col-md-12 disabled-billing-accordion">
<h3 id="select-acct" class="select-account-accordion">Select Account(s)</h3>
<span id="account-selected" class="selected-account">0 of 8 account selected</span>
</div>

There is margin for h3. Try
#select-acct {
margin: 0;
}

if you use h3 it will take default some margin and line-height if u check in the image while inspect u can see ,reference https://plnkr.co/edit/3O4773wA10jV1tC92zik?p=preview
So u have to add the styles for margin and line-height
.selected-account{
display: inline;
float: right;
color: #0679ca;
margin:0;
line-height:20px;
}
.select-account-accordion{
display: inline;
float: left;
line-height:20px;
margin:0;
}

You can use position:fixed and add left:"width of first one"
Like,
div1{
position:fixed;
width:200px;
height:300px;
}
div2{
position:fixed;
left:200px;
width:200px;
height:300px;
}
Hope it will help.
Edit
I have added some inline css in your code with position:fixed Here is screen shot.

You can simply remove the float: left; property from h3 ie,
.select-account-accordion {
display: inline;
/* float: left; */ //Remove this line
color: #0679ca;
}

Either reduce margin-top: 0px; for
<h3 id="select-acct" class="select-account-accordion">Select Account(s)</h3>
or
add equivalent margin-top example margin-top: 20px for
<span id="account-selected" class="selected-account">0 of 8 account selected</span>
.selected-account{
margin-top: 0px;
display: inline;
float: right;
color: #0679ca;
}
.select-account-accordion{
margin-top: 0px;
display: inline;
float: left;
color: #0679ca;
}
<div id="select-account" class="col-sm-12 col-md-12 disabled-billing-accordion">
<h3 id="select-acct" class="select-account-accordion">Select Account(s)</h3>
<span id="account-selected" class="selected-account">0 of 8 account selected</span>
</div>

Related

CSS Header - Different Alignment

Image of Webpage
I want to add them to the same line so the header looks more tidy, what would be the correct code to use?
.header{
border-bottom:1px solid #eee;
padding:10px 0px;
width:100%;
text-align:left;
}
.header a{
color:#333;
text-decoration: none;
margin-left: 20px;
}
.phone {
text-align: right;
font-weight: bold;
padding-right: 20px;
align-content: right;
}
<div class="header">
Home
Products
<div class="phone"><a>Freephone: 0800 096 1617</a></div>
</div>
You can achieve that with float. Left for the the ones you want to go left, right for the phone number, and a overflow: hidden for the header.
.header{
border-bottom:1px solid #eee;
padding:10px 0px;
overflow: hidden;
width: 100%;
}
.header a{
color:#333;
text-decoration: none;
margin-left: 20px;
float: left;
}
.phone {
font-weight: bold;
margin-right: 20px;
float: right;
}
<div class="header">
Home
Products
<div class="phone"><a>Freephone: 0800 096 1617</a></div>
</div>
you should insert the Freephone: 0800 096 1617 to div class header and use Css position:absolute; right:(you can manipulate it to fix the freephone);
<div class="header">
Home
Products
<a class="freephone">Freephone: 0800 096 1617</a>
<div class="phone"></div>
</div>
.header{
border-bottom:1px solid #eee;
padding:10px 0px;
width:100%;
float:left;
}
.header a{
color:#333;
text-decoration: none;
margin-left: 20px;
}
.phone {
font-weight: bold;
padding-right: 20px;
float:right;
}
<div class="header">
Home
Products
<div class="phone"><a>Freephone: 0800 096 1617</a></div>
</div>
You have to add float:left; to .header class and add float:right; to .phone class
Use floating instead. The .clear class means to stop floating and it is neccessary. Also the phone does not need to be inside of a div and should have the id of phone instead of class of phone because there is only one phone element. You do not need the alignment and text-alignments at all.
.header {
border-bottom: 1px solid #eee;
padding: 10px 0px;
width: 100%;
}
.header a {
color: #333;
text-decoration: none;
margin-left: 20px;
float: left;
}
#phone {
font-weight: bold;
padding-right: 20px;
float: right !important;
}
.clear {
clear: both;
}
<div class="header">
Home
Products
<a id="phone">Freephone: 0800 096 1617</a>
<div class="clear"></div>
</div>
Hope this works as it wasn't tested because I am on mobile right now.

Display an image with a div which can wrap the link

I am working on a simple html/css web page.
What I am trying to do is having an image and a div. Both will be inline display and in div I want to put a link. But when I put a long link title it is not what I expect it to be.
My code is this-
code
<div class="heading"> featured posts
</div>
<div class="img_src">
<img style="height:120px;" src="/uploads/1.jpg"></img>
</div>
<div class="link_src">
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
</div>
CSS-
.img_src{
display: inline-block;
margin-top: 3px;
margin-left:-2%;
}
.link_src{
display: inline-block;
background-color: white;
height: 120px;
line-height: 120px;
width: 61%;
margin-top: 3px;
text-transform: uppercase;
}
.inside_link{
margin-left: 2%;
margin-right: 2%;
font-size: 15px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
I searched on google and StackOverflow but I did not get anything useful.
I want it to look like this(DIV wraps full)-
Any suggestion?
You csn use diplay:table-cell instead of inline-block but also I made edit in html by adding div.post that contain the image and title, and remove the inline-style that gave height to the image
<div class="post">
<div class="img_src">
<img src="http://i.dailymail.co.uk/i/pix/2016/03/22/13/32738A6E00000578-3504412-image-a-6_1458654517341.jpg">
</div>
<div class="link_src">
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
</div>
and in the css I give width:20%; to .img_src and width:80%; to .link_src (you can change the widths as you like) and remove height and line height from them and the diplay:table-cell will handle those height
.post{
font-size:0;
display:table;
width:100%;
}
.img_src{
display: table-cell;
vertical-align:top;
width:20%;
}
.img_src img{
width:100%;
}
.link_src{
display: table-cell;
background-color: white;
margin-top: 3px;
text-transform: uppercase;
vertical-align:middle;
width:80%;
}
.inside_link{
margin-left: 2%;
margin-right: 2%;
font-size: 15px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
https://jsfiddle.net/IA7medd/gg7ygdLs/17/
You can achieve that by changing the inline-block display to table-cell and then apply the vertical-align:middle; property on the text container.
That way, the text will be perfectly vertically centered if there are one, two, three lines of content.
.parent{
display: table;
border: 5px solid #ccc;
width: 100%;
}
.img_src{
display: table-cell;
}
.link_src{
display: table-cell;
vertical-align: middle;
background-color: white;
width: 61%;
text-transform: uppercase;
}
See this fiddle
Ok you are using the wrong approach. Line height is causing you the problem. Your html should look like this
<img class="img_src" style="height:120px;" src="/uploads/1.jpg">
<div class="link_src">
<div class="inner_link_src">
<div class="inner_margin">
Link will go here but if there is a long title then it may create some problems..
</div>
</div>
</div>
and your css like this
.img_src{
float:left
}
.link_src{
float:left;
position:relative;
width: 61%;
text-transform: uppercase;
background-color: white;
vertical-align: top;
display:table;
height:120px;
}
.inner_link_src{
display:table-cell;
width:100%;
height:100%;
vertical-align:middle;
margin-left:10px;
}
.inner_margin{
margin-left:10px;
}
see the jsfiddle it is working great
https://jsfiddle.net/gg7ygdLs/27/
You just change your CSS and HTML by following and then you get the desired result.
CSS:
.img_src{
display: inline-block;
margin-top: 3px;
margin-left:-2%;
}
.link_src{
display: inline-block;
background-color: white;
height: 120px;
width: 100%;
margin: 10px 0 10px 3px;
-webkit-box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
-moz-box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
}
.inside_link{
margin: 2%;
display: inline-block;
position:absolute;
padding: 8px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
HTML:
<div class="heading"> featured posts
</div>
<div class="link_src">
<img style="height:120px;" src="http://smashinghub.com/wp-content/uploads/2011/11/Text-Shadow-Box.jpg" />
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
Demo
You can simplify your code a lot by using Flexbox.
You can use it for your header as well, to center the title.
.your-header {
display: flex;
align-items: center;
justify-content: center;
}
Then the image container. Use it's more semantic and it's a block element, perfect to wrap an image with a caption or a link in your case:
<figure class="your-figure">
<img class="your-image" src="http://pipsum.com/200x150.jpg"></img>
<a class="your-link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</figure>
and the CSS
.your-figure {
display: flex;
align-items: center;
padding: 4px;
border: 1px solid #ccc;
background-color: #fff;
}
.your-image {
margin-right: 10px;
}
Have a look here for the complete code ;)
Follow this if you don't know Flexbox, might seems daunting at first, but when it clicks in your head it will change your life :) Complete guide to Flexbox

Navbar align part right part left errors

I'm trying to create a navbar with some items on the left and some items on the right (Item 1 on the left, items 2 and 3 on the right). My JSFiddle has my current code.
What I have tried to fix this issue:
float: right
text-align:right
None of them seem to work. I'm sure there is a super simple solution, but I just can't think of it.
HTML:
<div class="navbar">
<!--Create the button home -->
<p class="innav">Num1</p>
<p class="HL">|</p>
<p class="rightIn">Num2</p>
<p class="HL">|</p>
<p class="rightIn">NUM 3</p>
<p class="HL">|</p>
</div>
CSS:
div.navbar{
width:100%;
height: 30px;
background-color: #03572c;
}
p{
display: inline;
}
p.innav{
color:white;
font-size: 24px;
width: 30px;
height: 30px;
margin-left: 10px;
margin-top: 10px;
}
p.rightIn{
color:white;
font-size: 24px;
width: 30px;
height: 30px;
margin-left: 10px;
margin-top: 10px;
}
.HL{
margin-left: 10px;
color:white;
font-size:24px;
}
JSfiddle
Any help would be greatly appreciated! :)
Add these style to your css.
p.rightIn,
p:nth-child(4),
p:nth-child(6)
{
float: right;
margin: 0px 5px;
width: auto;
}
Jsfiddle
I would recommend that you use a CSS grid system for this, since you are likely to need this functionality over a over on your sites.
Here are some grid systems that I have used in the past:
Pure CSS
http://purecss.io/grids/
Foundation
http://foundation.zurb.com/docs/components/grid.html
Bootstrap
http://getbootstrap.com/css/#grid
Semantic UI
http://semantic-ui.com/collections/grid.html
Or, if you feel like creating your own grid system, here is a good article about it:
http://www.sitepoint.com/understanding-css-grid-systems/
nav {
background: #000000;
width: 100%;
display: block;
padding: 8px 0;
font-family: arial;
font-size: 13px;
}
nav span {
display:block;
width:100%;
line-height: normal;
text-align:right;
}
nav a {
color: #ffffff;
padding: 0 10px;
text-decoration: none;
display:inline-block;
border-right:1px solid #ffffff;
}
nav a:first-child{
float:left;
}
nav a:last-child{
border:none;
}
<nav>
<span>
Link 1
Link 2
Link 3
</span>
</nav>
Demo

Why won't my elements display horizontally?

I have two sections of my website that should be displaying in a similar manor. One displays correctly, while the other does not. The top one puts each element on its own line, while the bottom puts the above and the two images side by side how I want them.
My two questions are:
1: Why is the broken version broken?
2: What part of the working version is enabling it to display properly (or a better follow up question, what parts of the css are not aiding in it displaying properly and can be deleted?
Broken:
html:
<div id="maintitle">
<span id="chara1"><img src= "<?= $charused ?>" width="150" alt="char2"/></span>
<span id="maintitletext"><h1> Welcome to Born4battle's Wolfenstein 3D page</h1></span>
<span id="chara2"><img src= "<?= $charused ?>" width="150" alt="char2"/></span>
</div>
css:
#maintitle{
color: #ffff00;
text-align: center;
}
#maintitle ul{
margin:0;
padding: 0;
list-style-type: none;
}
#maintitle li{
display: inline;
}
#chara1, #chara2, #maintitletext{
margin-top: 0px;
margin-right: auto;
margin-left: auto;
display: inline;
padding: .5em;
width: 110px;
}
Working:
html:
<div id="share">
<p> Get the official shareware for Wolfenstein 3D and Spear of Destiny below </p>
<span id="getwolf"><img src="http://www.timsooley.com/wolfnow.gif" alt="getwolf"></span>
<span id="getspear"><img src="http://www.timsooley.com/getspear.gif" alt="getspear"></span>
</div>
css:
#share ul{
margin: 0;
padding: 0;
list-style-type: none;
}
#share li{
display:inline;
}
#getspear, #getwolf{
margin-top: 0px;
margin-right: auto;
margin-left: auto;
display: inline;
/*background: #bbbbbb;
border-top: solid 2px #333333;
border-left: solid 2px #333333;
border-right: solid 3px #999999;
border-bottom: solid 3px #999999;*/
padding: .5em;
width: 110px;
}
Please see the Fiddle .
After reading your question what i have understood is that you want your images should be side by side and text should be in middle. in you broken code.
please let me know if i am lagging some where. So i can make changes as per your needs.
see the css rules what i added:
#maintitle{ color: #ffff00; text-align: center; overflow:hidden; width:480px; border:1px solid red; }
#maintitle span { width:148px; display:block; font-size:12px; }
#chara1, #chara2, #maintitletext{ margin-top: 0px; margin-right: auto; margin-left: auto; display: inline; padding: .5em; width: 110px; float:left; // added to make all elements in horizontal manner }
To show the text and images in same line, make these changes in your code:
http://jsfiddle.net/S3CBj/2/
#maintitle{
color: #ffff00;
text-align: center;
}
#maintitle ul{
margin:0;
padding: 0;
}
#chara1, #chara2, #maintitletext{
margin-top: 0px;
margin-right: auto;
margin-left: auto;
display: inline;
float: left;
padding: .5em;
width: 150px;
}​

Extra padding inside a div

I m having problem to determine from where extra padding is added to a div.
The div containing the text "Video Title" has too much padding added to it. Which is very much unwanted. And i have no idea from where this extra padding is coming.
I have added the styles, the html codes and the link to a page using this sample page.
Please have a look, I'm about to go insane.
The style --
<style type="text/css">
html *
{
margin: 0;
padding: 0;
border: 0;
outline: 0;
vertical-align: baseline;
}
table.video_list
{
width: 100%;
border-collapse: collapse;
}
table.video_list td
{
padding: 5px;
width: 33%;
}
div.vid_container
{
/*float:left;*/
/*margin-bottom:15px;
margin-left:5px;
margin-right:15px;*/
position: relative;
display: inline-block;
/*width:242px;*/
margin: 10px;
/*width: 300px;*/
}
div.vid_container div.duration
{
/*background-color:#160A07;*/
/*background-color: transparent;
background-image: url(../images/backs/duration_back_58x24.png);
background-position: center center;
background-repeat: no-repeat;*/
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
background-color: #1b1b1b;
bottom:27px;
color:#FFFFFF;
float:right;
font-size:14px;
padding:4px;
position:relative;
right:2px;
text-align:center;
width:50px;
filter: alpha(opacity = 85);
opacity: 0.85;
font-weight: bold;
}
div.vid_container div.info_holder
{
width: 248px;
margin: auto;
display: block;
}
div.vid_container div.thumb_holder
{
width: 244px;
height: 184px;
vertical-align: middle;
border: solid 1px #323434;
padding: 1px;
margin: auto;
}
div.vid_container div.thumb_holder img.thumb
{
width: 236px;
height: 176px;
vertical-align: middle;
border: solid 1px #323434;
}
div.vid_container a.title
{
color:#DBA0AC;
display:block;
font-size:14px;
height:35px;
overflow:hidden;
text-decoration:none;
white-space:pre-line;
width:248px;
padding-top: 1px;
padding-bottom: 1px;
}
div.vid_container a.title:hover
{
text-decoration: underline;
}
div.vid_container div.info_holder div.info_text
{
margin-top:5px;
text-align: left;
padding-top: 1px;
padding-bottom: 1px;
}
div.vid_container div.info_holder div.time
{
color: #ccc;margin-top: 5px;font-size: 90%;
text-align: left
}
/******************************************
Videos list
******************************************/
.vid_container .site_name
{
text-transform: capitalize !important;
}
.vid_container img.thumb
{
width: 242px !important;
height: 182px !important;
border:1px solid #323434 !important;
}
/******************************************
List View
******************************************/
div.vid_container_listview
{
width: 100% !important;
}
div.vid_container_listview div.thumb_holder
{
float: left !important;
}
div.vid_container_listview div.info_holder
{
float: left !important;
margin-left: 10px;
}
div.vid_container_listview div.info_holder div.title_holder
{
min-height:30px;width:600px;
}
div.vid_container_listview div.info_holder div.info_text
{
color: #ccc;margin-top: 5px;
}
div.vid_container_listview div.info_holder div.info_text div.site_name
{
font-size: 100%;margin-top:15px;
}
div.vid_container_listview div.info_holder div.info_text div.likes_and_views
{
font-size: 100%;margin-top:15px;
}
div.vid_container_listview div.info_holder div.added_at
{
color: #ccc;margin-top: 5px;font-size: 100%;
}
div.vid_container_listview a.title
{
font-size: 16px;
font-weight: bold;
}
.float_left
{
float: left;
}
.float_right
{
float: right;
}
.clear
{
clear: both;
}
</style>
And the Html:
<div class="vid_container">
<div class="thumb_holder">
<a href="#" title="Brunette Teen Paige Taylor">
<img alt="Brunette Teen Paige Taylor" class="thumb" src="empty_thumb.png" norotate="1" />
</a>
<div class="duration">30:16</div>
</div>
<div class="info_holder">
<div class="info_text">
<a class="title" href="#" title="Brunette Teen Paige Taylor">Video Title</a>
</div>
<div class="time">16 days ago</div>
<div style="color: #ccc;margin-top: 5px;">
<div class="float_left site_name" style="font-size: 90%;">Youtube</div>
<div class="float_right" style="text-align:right;padding-right: 2px;font-size: 90%;">1 likes — 140 views</div>
<div class="clear"></div>
</div>
</div>
</div>
The link to this sample page is: Sample Page
You need to change the div.vid_container a.title rule
remove the overflow:hidden and change the height:35px to
height:auto!important;
height:35px;
min-height:35px;
UPDATE
i see ... the problem is that the .duration box is positioned relative and so it remains in the flow of the DOM .. that is what takes the space above the .title..
you need to set the .duration to have position:absolute and margin-top:-27px; (and remove the bottom property
that should take care of all problems..
download firefox if you dont have it.
install firebug (an addon)
open up firebug in firefox and load your page.
right click on the div with video title and select inspect element
look at the style and computed tabs to see what is affecting the padding.
According to my Firebug addin, the extra padding is caused by these two properties of the <a> element contained in the <div>
div.vid_container a.title {
height:35px;
width:248px;
}
Disabling these rules in the css editor removed the extra padding (top and bottom).
Edit : It seems that the overflow could also be due to this property on the <div> :
div.vid_container div.info_holder div.info_text {
padding-top:1px;
}
You can try disabling this rule if it fits your needs better. It will remove the extra padding on the top of the div.
You will however still have extra space on the bottom of the title, which is caused by the height of the <a> element, as explained above.
div.vid_container a.title has a height of 35px which is making your link bigger. I believe this is what is causign the extra space you don't expect (found courtesy of firebug in firefox).
Edit: Didn't even notice the horizontal padding at first but as Thibault Falise there is just a width in there as well.
according to Firebug (which I would recommend you to use) and checking the link you provided that div has a padding of 1px and a top margin of 5px, as specified in the css. So there is no extra padding in itself.
As suggested, maybe you want to change the size of the a.title (height, width).