ul with images doesn't center properly - html

I have a <ul> with images that I want to be displayed horizontally centred, inline but it keeps floating a little to the right and gets my window size to be a little over 100% width. Here's a FIDDLE, you might need to scroll out a little to see it.
Here's the ul:
<div class="row graybackground margin-top-60">
<section id="menuimages" class="margin-top-60">
<ul class="margin-top-60">
<li class="col-md-4 col-sm-6">
<div class="menubg" style="background-image: url({{ URL::asset('img/training/18911510_m.jpg'); }})">
<span>{{ link_to('index/#training', 'TRAINING') }}</span>
</div>
</li>
<li class="col-md-4 col-sm-6">
<div class="menubg" style="background-image: url({{ URL::asset('img/taste/20360155_m.jpg'); }})">
<span>{{ link_to('index/#eat', 'TASTE') }}</span>
</div>
</li>
<li class="col-md-4 col-sm-6">
<div class="menubg" style="background-image: url({{ URL::asset('img/relax/14824877_s.jpg'); }})">
<span>{{ link_to('index/#relax', 'RELAX') }}</span></div>
</li>
</ul>
</section>
</div>
and here the CSS:
.graybackground {
background: rgba(0,0,0,0.15);
padding: 50px;
}
.margin-top-60 {
margin-top:60px;
}
.menubg a {
margin-top:20px;
margin-left: 20px;
display: inline-block;
font-size: 1.7em;
font-weight: bold;
color: #f5f5f5;
background: rgba(0,0,0,0.5);
border-radius: 5px;
padding:2px 4px;
}
.menubg a:hover {
text-decoration: none;
}
No matter where I add margin or padding or whatever, it doesn't move and fit.
I'm using bootstrap 3.
Can someone assist?

The spilling out over 100% of the page is due to the negative margins on .row - and this is important to how bootstrap's nested grid works. Wrapping the whole thing in a .container will correct this for you (it adds padding to the outside to negate the negative margins).
As for the ul being off-center, just do a simple reset on it and its nested lis before you start adding:
http://jsfiddle.net/8b6trqgj/4/

I solved by removing left padding to the ul and adding the same rule as #Brian:
#menuimages ul {
padding-left: 0;
}
.graybackground {
background: rgba(0,0,0,0.15);
padding: 50px;
margin:0;
max-width: 100%;
}
Fiddle

Just add
max-width: 100%;
margin: 0;
to .graybackground
Fiddle

Related

How to ensure IMG Aligns in Center on col-xs, as well as making Divs 'float' in middle of space?

I'm trying to understand 3 problems.
1) When minimizing to Col-XS, the picture is slightly off from centre - How do I fix this?
2) When the logo sits inside the Column, it forces the entire menu to widen due to the logo taking up space. This causes a huge amount of background colour (from the menu) to appear when not needed. Can anyone recommend a suitable fix for this (whether this be a design recommendation or a coding fix)?
3) If the above cannot be fixed, how do I make the 4x Menu items move from the top of the bar to the bottom? Would this be a job for Display: Relative or something like that? Or do the display tags not work within bootstrap (v3.3.5)?
Thanks in advance!
Snippet
.logo {
width: 150px;
height: 150px;
}
.header {
background: #5A1FD3;
border: 2px solid #46248B;
}
.header li {
list-style-type: none;
background: #5A1FD3;
font-weight: bold;
font-size: 20px;
text-align: center;
}
.header li:hover {
transition: 1.5s;
background: #46248B;
}
.header a:link {
color: azure;
}
.header a:visited {
color: azure;
}
.header a:active {
color: azure;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<!-- NAV MENU -->
<div class="container-fluid">
<div class="row">
<div class="header col-sm-12 col-xs-12">
<div class="row text-center col-sm-3 col-xs-0">
<img class="logo center-block" src="Pictures\Jamie Bohanna.png" alt="Logo">
</div>
<ul>
<li class="col-sm-2 col-xs-12">Home
</li>
<li class="col-sm-2 col-xs-12">Portfolio
</li>
<li class="col-sm-2 col-xs-12">Rates
</li>
<li class="col-sm-2 col-xs-12">Contact
</li>
</ul>
</div>
</div>
</div>
It is, for logical reasons, practical to use two rows. One for the logo and one for the list. And together they are the header:
<div class="container-fluid">
<div class="header">
<div class="row">
<div class="col-..."
<img class="logo" />
</div>
</div>
<div class="row">
<div class="col-..."
<ul class="list-unstyled"><!-- .list-unstyled is a bootstrap class -->
<li>...</li>
<li>...</li>
</ul>
</div>
</div>
</div><!-- End of .header -->
</div>
.container-fluid has a padding-left: 15px and a padding-right: 15px, so that one can make
.header {
margin: 0 -15px;
...
}
so that there will be no gap on the right and left side.
Example

How to position element between two sections while also being responsive?

First, here's an example I'm trying to achieve:
Here's the code I'm using to achieve that
HTML:
<div class="card demo-card-header-pic" style="margin:15px;">
<div style="background-image:url(https://pbs.twimg.com/profile_banners/6253282/1431474710/web_retina)" valign="bottom" class="card-header color-white no-border"></div>
<div class="avatar">
<img src="http://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_bigger.png" style="border-radius:50px;">
</div>
<div class="card-content">
<div class="card-content-inner">
<div>
<p><b>****</b> wants to know what you think of him!</p>
</div>
<div>
<span class="text-muted" style="float:left;">Asked two days ago</span>
<span style="float:right;" class="text-muted"> 5 comments</span>
</div>
</div>
</div>
<div class="card-footer">Footer</div>
</div>
CSS:
.demo-card-header-pic .card-header
{
height: 40vw;
background-size: cover;
background-position: center;
}
.avatar
{
border-radius: 50px;
}
.card > .avatar
{
position: relative;
top: -40px;
left:5px;
}
.text-muted {
color: #777;
}
My question is how do I get rid of all the white space that is between the header of the card and the text? I tried using position:absolutebut that would mess up anytime the display was changed, even when using percentages.
A quick solution would be to give .card-content a negative margin-top value. I do agree that it's not the most elegant solution, but it get's the job done. Also adding a clear:both to the footer will prevent the overlay of both DIVs that you have at the moment
CSS:
.card-content{
margin-top: -40px;
}
.card-footer{
clear: both;
}
just remove margin form your main div and also if you want to remove body default white space then use following css on body
body{
margin:0;
padding:0;
}

HTML/CSS Css box messing up margin top

So I have this CSS box:
.navigation-div
{
text-align:right;
margin-top:14px;
box-shadow:0px 0px 10px rgba(0,0,0,0.47);
padding: 0;
color:#E3E3E3;
background-color: #333;
}
With an image and a piece of text inside of it
#mailtext
{
margin-top:-10px;
display:inline-block;
font-size:20px;
color:white;
font-style:italic;
}
#mailpicture
{
display:inline-block;
margin-top:16px;
}
This is the HTML I have for it:
<div class="navigation-div">
<nav class="navigation">
<h1 id="mailtext">Mail Us</h1>
<img id="mailpicture" src="images/gmail.png">
</nav>
</div>
Currently there is no styling for the class navigation. The Mail picture is in the correct position, but the text I want to go upwards. As you can see from the #mailtext styling I have margin-top:-10px; This does not move the text upwards.
How would I move this text upwards with or without using margin-top.
This question is like my previous question in a way, but now the text will not go to where I want it to (upwards). Using margin-left is bad, but when I did that I could move the margin top also. Since the navigation-div has a text align of right, this might be messing it up.
How would I keep the text in the same position with moving the margin top without using margin left. I would like to keep the text on the same line with the image, not above. The picture is in the right place, all i want to move is the text higher. I want the text to be parallel to the center of the image on the same line.
The previous question I have posted was about keeping all the elements on the same line, this one is about moving the margin-top.
To align the text a little higher you need to replace margin-top with position: relative and top:-10px, like in the code snippet and fiddle.
For a more efficient solution i recommend using the CSS property vertical-align. In this case if the image(size) is changed, it will still align with the text.
JSFiddle
.navigation-div {
text-align: right;
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
}
#mailtext {
position: relative;
top: -10px;
display: inline-block;
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture {
display: inline-block;
margin-top: 16px;
}
<div class="navigation-div">
<nav class="navigation">
<h1 id="mailtext">Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="images/gmail.png">
</a>
</nav>
</div>
Edit:
.navigation {
margin-top:14px;
box-shadow:0px 0px 10px rgba(0, 0, 0, 0.47);
padding: 0;
color:#E3E3E3;
background-color: #333;
width: 100%;
height: 100px;
}
.container {
display: flex;
align-items: center;
justify-content: center;
float: right;
line-height: 0.5;
text-align: center;
margin-right: 20px;
}
#mailtext {
align-self: center;
font-size: 20px;
color: white;
font-style: italic;
margin-right: 15px;
}
#mailpicture {
align-self: center;
}
<nav class="navigation">
<div class="container">
<h1 id="mailtext">Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="images/gmail.png">
</a>
</div>
</nav>
JS Fiddle
There are issues with inline-block elements, especially when one is a block element and the other is an inline element. What I'd do is set parent font-size to 0 and come back to the H1 element to set the desired font-size. Then, I'd set vertical alignment to middle.
Mention: setting an id to the image element doesn't work, IMHO, without working with the link that contains it. They're both inline elements and one has to include the other, acting like a block, right?
Check the code, its a bit simplified, but you will definitely work it out.
.navigation-div {
background: #333;
color: #fff;
font-size: 0;
text-align: right;
}
#mailtext {
font-size: 20px;
margin-right: 5px;
}
.navigation a,
#mailtext {
display: inline-block;
vertical-align: middle;
}
#mailpicture {
display: block;
}
<div class="navigation-div">
<nav class="navigation">
<h1 id="mailtext">Mail Us</h1>
<img id="mailpicture" src="images/gmail.png">
</nav>
</div>
I don't know how big your logo will be, but here is an approach that is relatively clean.
For the two inline-block elements, #mailtext and #mailpicture, set vertical-align: middle.
For #mailtext, zero-out the default margins from the h1 tag.
For #mailpicture, adjust the left and right margins as need to get horizontal white space suitable with your design. and then set the top and bottom margin accordingly.
The vertical-align property will keep the two elements centered with respect to each other.
However, if your image is such that the visual center of the image is not at the mid-height of the image, you can add position: relative to #mailtext and adjust the top or bottom offset (use one or the other).
If your image height is actually less than the height of the text, apply the position-relative adjustment to the image instead of the text.
.navigation-div {
text-align: right;
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
}
#mailtext {
display: inline-block;
vertical-align: middle;
margin: 0; /* zero out h1 margins */
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture {
display: inline-block;
margin: 10px; /*adjust as needed */
vertical-align: middle;
}
.ex2 #mailtext {
font-size: 2.5em;
margin: 10px 0;
}
.tweak #mailpicture {
position: relative;
bottom: 5px; /* use top if you want to move the image downward */
}
<div class="navigation-div">
<nav class="navigation">
<h1 id="mailtext">Large Logo - Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="http://placehold.it/100x50">
</a>
</nav>
</div>
<div class="navigation-div ex2">
<nav class="navigation">
<h1 id="mailtext">Small Logo - Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="http://placehold.it/100x10">
</a>
</nav>
</div>
<div class="navigation-div ex2 tweak">
<nav class="navigation">
<h1 id="mailtext">Position Tweak - Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="http://placehold.it/100x10">
</a>
</nav>
</div>

How to add padding between paragraph and list

In my footer I have breadcrumb list and under that is some text.
My question then is how to set the padding between the breadcrumb list and the Copyright paragraph.
I solved this using <br> tag, but I think it's not semantically correct.
I tried with padding-top but without success.
.col-xs-12 .breadcrumb{
background-color: #2b2b2b;
}
.breadcrumb > li + li:before {
content: none;
}
.breadcrumb li a {
color: white;
font-family: TW Cen MT;
font-size:17px;
}
.container-fluid p{
bottom: 0;
position: absolute;
margin-left: 34em;
}
<div class="container-fluid footer">
<div class="row">
<div class="col-xs-12">
<img src="img/Gallery/fb.png" alt=""> &nbsp
<img src="img/Gallery/twitter.png" alt=""> &nbsp
<img src="img/Gallery/youtube.png" alt=""> &nbsp
<img src="img/Gallery/myspace.png" alt="">
<ol class="breadcrumb">
<li><a class="active">Home</a></li> &nbsp
<li>Gallery</li> &nbsp
<li> FAQ</li> &nbsp
<li> Contact</li>
</ol>
<p><small>Copyright <span class="glyphicon glyphicon-copyright-mark"></span> All Right Reserved | Testing Website </small></p>
</div>
</div>
Set a margin-bottom to the ordered list, like so:
.breadcrumb {
margin-bottom: 50px;
}
Your paragraph is positionned in absolute, it's out the flow.
1st solution
Remove absolute positionning.
2nd solution
Add a padding-bottom in your list.
The size of padding correspond to the height of the paragraph and the margin you want.
Like so:
.breadcrumb {
padding-bottom: 50px; // 20px height paragraph, 30px height margin
}
The solution is to add a margin-bottom:; to the list (.breadcrumb), and please remove the properties
.container-fluid p{
bottom: 0;
position: absolute;
margin-left: 34em;
}
you won't need them anymore.

Weird margins on inline-block elements and unable to vertically align element inside them

I think I'm going insane over this now, no idea how to resolve it... please help guys.
I have three divs on a page that should all fit onto one line. They have to be square (with rounded corners) so I have to set a width and a height to keep the 1:1 aspect ratio. I have a heading inside them that should be vertically and horizontally centered. The wording of the heading may change and might run over 2 lines so a simple margin-top is not enough in this case.
First problem: there are weird margins at the top despite there not being anything else affecting that (well there must be but I can't see what). If I float the divs they line up but floating isn't the way to go is it... why is inline-block not working?
Second issue (which is likely related, so I'm posting it in one go) is that I'm unable to vertically center the title divs. Any ideas?
Here's a jsfiddle to illustrate: http://jsfiddle.net/fydC4/
The HTML:
<div id="container">
<div class="nav-left">
<p id="nav-left-title">In this section…</p>
<ul>
<li><a class="light" href="#">page title here</a></li>
<li><a class="light" href="#">page title here</a></li>
<li><a class="light" href="#">page title here</a></li>
</ul>
</div>
<div id="main">
<h1>Assignments</h1>
<p>Click on the titles of the assignments to find out more.</p>
<div class="box" id="good-designs">
<h2 class="box">3 good designs</h2>
</div>
<div class="box" id="temp">
<h2 class="box">title here</h2>
</div>
<div class="box" id="temp2">
<h2 class="box">title here</h2>
</div>
</div><!--end main-->
</div>
</div><!--end container-->
The CSS:
#container {
max-width: 960px;
margin: auto;
}
#main {
display: table-cell;
width: 73em;
padding: 1em 2em 2em;
background-color: white;
}
#nav-left-title {
padding-bottom: 0.5em;
margin: 0;
color: white;
}
.nav-left{
display: table-cell;
width: 14em;
background-color: #87a8b1;
padding: 1.1em;
font-size: 1.2em;
}
.nav-left li {
padding: 0.5em 0;
border-bottom: 1px solid white;
}
h2.box {
padding: 15px 0;
margin: 50% 15px;
margin: auto;
text-transform: uppercase;
text-align: center;
}
div.box {
padding: 15px;
height: 180px;
width: 180px;
border-radius: 50%;
margin-top: 25px;
margin-left: 1.5em;
display:inline-block;
/* float: left; */
}
#good-designs {
background-color: green;
}
#temp, #temp2 {
background-color: yellow;
}
Hi you may use two properties to align all your elements
vertical-align:middle;
display:inline-table on div.box and
display:table-cell on h2.box; (for the texts inside your divs)
Check this code http://jsfiddle.net/fydC4/16/
This worked for me, replace inline-block with float left.
you are also calling margins twice on some element which are not necessary
here you go
jsfiddle.net/fydC4/14