Centering a list in Bootstrap CSS [duplicate] - html

This question already has answers here:
How to horizontally align ul to center of div?
(5 answers)
Closed 6 years ago.
Edit after duplicate report
Apologies I think the suggested duplicate may actually be a duplicate. I tried it first and it didn't work for me hence a new question. Having looked again with the new suggested answer I realise my issues are probably with the out of the box settings of the tool I am using (codepen.io). I think I probably need to look at this tool instead! (whether its's the tool or the default version of bootstrap I haven't checked yet). Thanks.
I am doing a very noddy little page to try and get some front end know-how. Very basic stuff I think, but I'm struggling to centre a list on my page. Essentially I have plugged in bootstrap and I believe one of these built css classes is adding bullet points to the unordered list which I think is good. When I centre the text though the bullet points go to the left of the page while the text is centred. I thought maybe the answer was to split that section into 3 columns and put my list in the middle column which works to an extent but shifts about when I try different screen sizes (I thought the point of bootstrap was top facilitate handling responsive design!?)
Anyway I wondered if anyone could give me a hint on how to centre my list in a way that it will a) be left justified so that it is along the lines of
Item 1
Item 2
Item 3
but in the centre of the page and b) remain centred regardless of screen sizes ?
This is the rough html. I've tried to cut it down a bit to keep to the essentials but let me know if more information would help. I've tried various css based methods and all have failed but I thought (maybe wrongly!) really the answer ought to be a bootstrap class ? and so have left the example code with my attempted bootstrap attempt. In reality though I'm just curious now to see how it ought to be done so an css answer would be equally well appreciated!
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="well text-center maindiv">
<h1 style="color: green" class="text-primary text-center">The Mighty Diamonds</h1>
<h3 class="text-center">The band that brought joy to the hearts of millions</h3>
<div id="div1" class="well text-center">
<div id="div2">
The Mighty Diamonds were a band from Jamaica</div>
</div>
<h3 class="text-center;">A Brief Biog</h3>
<p class="text-left body-para">[Paragraph text]</p>
<h3>Studio albums</h3>
<div class="container">
<div class="row">
<div class="col-xs-4"></div>
<div class="col-xs-4 text-left">
<ul>
<li><span>1964</span> - Album 1</li>
<li><span>1966</span> - Album 2</li>
<li><span>1967</span> - Authentic Album Vol. 2</li>
<li><span>1996</span> - Greetings from Album 4</li>
<li><span>1998</span> - Ball of Fire</li>
<li><span>2009</span> - From Paris with Love</li>
<li><span>2007</span> - On the Right Track</li>
<li><span>2012</span> - Walk With Me Album</li>
<li><span>2016</span> - Platinum Ska</li>
</ul>
</div>
<div class="col-xs-4"></div>
</div>
</div>
</div>

So I figure that your issue here is that your ul is not centered in container > row > text-left
Add display: inline-block to .container > .row > .text-left > ul to let it take as much width as its contents
Add text-align: center to .container > .row > .text-left to center the ul inside.
Add text-align: left to the ul to justify the list to left.
See demo below:
.container > .row > .text-left {
text-align: center;
}
.container > .row > .text-left > ul {
text-align: left;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="well text-center maindiv">
<h1 style="color: green" class="text-primary text-center">The Mighty Diamonds</h1>
<h3 class="text-center">The band that brought joy to the hearts of millions</h3>
<div id="div1" class="well text-center">
<div id="div2">
The Mighty Diamonds were a band from Jamaica</div>
</div>
<h3 class="text-center;">A Brief Biog</h3>
<p class="text-left body-para">[Paragraph text]</p>
<h3>Studio albums</h3>
<div class="container">
<div class="row">
<div class="col-xs-4"></div>
<div class="col-xs-4 text-left">
<ul>
<li><span>1964</span> - Album 1</li>
<li><span>1966</span> - Album 2</li>
<li><span>1967</span> - Authentic Album Vol. 2</li>
<li><span>1996</span> - Greetings from Album 4</li>
<li><span>1998</span> - Ball of Fire</li>
<li><span>2009</span> - From Paris with Love</li>
<li><span>2007</span> - On the Right Track</li>
<li><span>2012</span> - Walk With Me Album</li>
<li><span>2016</span> - Platinum Ska</li>
</ul>
</div>
<div class="col-xs-4"></div>
</div>
</div>
</div>
A more simple solution (if flexbox is an option):
.container > .row > .text-left {
display: flex;
justify-content: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="well text-center maindiv">
<h1 style="color: green" class="text-primary text-center">The Mighty Diamonds</h1>
<h3 class="text-center">The band that brought joy to the hearts of millions</h3>
<div id="div1" class="well text-center">
<div id="div2">
The Mighty Diamonds were a band from Jamaica</div>
</div>
<h3 class="text-center;">A Brief Biog</h3>
<p class="text-left body-para">[Paragraph text]</p>
<h3>Studio albums</h3>
<div class="container">
<div class="row">
<div class="col-xs-4"></div>
<div class="col-xs-4 text-left">
<ul>
<li><span>1964</span> - Album 1</li>
<li><span>1966</span> - Album 2</li>
<li><span>1967</span> - Authentic Album Vol. 2</li>
<li><span>1996</span> - Greetings from Album 4</li>
<li><span>1998</span> - Ball of Fire</li>
<li><span>2009</span> - From Paris with Love</li>
<li><span>2007</span> - On the Right Track</li>
<li><span>2012</span> - Walk With Me Album</li>
<li><span>2016</span> - Platinum Ska</li>
</ul>
</div>
<div class="col-xs-4"></div>
</div>
</div>
</div>

Related

My website is not responding to the media querie

I'm brand new to web development and I have build a little website with 3 pages. My goal is to use #media tags to make it responsive for the following: max-widths: 980px, 768px and 640px. I did the first page and it's been acting weird. How can I make the entire website responsive? Please to assist. My code for all 3 pages and the media is attached. Thanks.
/*first page */
<head>
<title>AboutMe</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<div class="top">
<div class="myname">
<h4 class="firstlast">name</h4>
</div>
<div class="list">
<ul>
<li class="contact">Contact</li>
<li class="portfolio">Portfolio</li>
<li class="about">About</li>
</ul>
</div>
</div>
<div class="middle-about-me">
<div class="center">
<h3> About Me</h3>
<hr>
<p class="myinfo">Hi my name is ..... and I was born on October 9th, 1971 in ......
<img src="assets/img/author.jpg" width="150px" height="150px"><br>
  To briefly introduce the... to you I would say it is a country located on the........>
    shares the same borders with ....... It is the world largest<br>
 producer of coacoa used for chocalate and lotions. In one word, it's the country where chocolate tastes like<br>  real chocolate. Since the last discovery of petrol in the country, it's been a little agitated as France and the<br>US want to control the discovery. After obtaining my masters in Business Management, I worked as the marketing representative for an american company before moving to the US to pursue a degree in Mathematic at UNT Dallas and worked for...,...., and.... as a Math instructor. My goal in this program is to learn to build websites from scratch and later on to build apps from scratch. I've got the right instructional staff and the right TAs to help me reach that goal. All I have to do is to go to work.<br>   "Impossible is nothing", Muhammad Ali.</p>
<p class="smile"><i>hover on my picture and start smiling</i></p>
</div>
</div>
<div class="footer">
<p class="footer-copyright">Copyrigtht © 2019 Portfolio "name" All rights reserved.</p>
</div>
</div>
</body>
/*second page */
<body>
<div class="container">
<div class="top">
<div class="myname">
<h4 class="firstlast">name</h4>
</div>
<div class="list">
<ul>
<li>Contact</li>
<li>Portfolio</li>
<li>About Me</li>
</ul>
</div>
</div>
<div class="middle">
<div class="center-portfolio">
<h3> Portfolio</h3>
<hr>
<div class="div1"><img src="assets/img/career1.jpg" height="120px" width="150px"></div>
<div class="div2"><img src="assets/img/chocolatour.jpg" height="120px" width="150px"></div>
<div class="div3"><img src="assets/img/guildhouse.jpg" height="120px" width="150px"></div>
<div class="div4"><img src="assets/img/career2.jpg" height="120px" width="150px"></div>
<div class="rotateIn div5"><img src="assets/img/Abidjan1.jpg" height="120px" width="150px"></div>
<div class="div6"><p><i>please to hover on the images</i></p></div>
<div class="banner1">career picture 1</div>
<div class="banner2">chocolate tour</div>
<div class="zoomIn banner5">Abidjan</div>
<div class="banner4">career picture 2</div>
<div class="banner3">Guild Brussels</div>
</div>
</div>
<div class="footer">
<p class="footer-copyright"> Copyrigtht © 2019 Portfolio "name" All rights reserved.</p>
</div>
</div>
</body>
/*third page */
<body>
<div class="container">
<div class="top">
<div class="myname">
<h4 class="firstlast">name</h4>
</div>
<div class="list">
<ul>
<li>Contact</li>
<li>Portfolio</li>
<li>About Me</li>
</ul>
</div>
</div>
<div class="middle">
<div class="center">
<h3> Contact</h3>
<hr>
<form>
  Name:<br>
<input id="namebox" type="text" name="name" required="" placeholder="your name">
<br><br>
  Email:<br>
<input id="emailbox" type="Email" name="email" required="" placeholder="example#yahoo.com">
<br><br>
  Message:<br>
<textarea id="messagebox" style="height: 200px; " name="message" placeholder="Enter massage here" required="">
</textarea>
<br><br>
  <input type="submit" value="submit" name="submit">
</form>
<br>
</div>
</div>
<div class="footer">
<p class="footer-copyright">
Copyrigtht © 2019 Portfolio "name" All rights reserved.
</p>
</div>
</div>
</body>
/* Width at 768px and below */
#media screen and (max-width: 768px) {
body {
background-color : #E9967A;
}
.container {
background-color: green;
border-style: none;
width: 50%;
}
.middle-about-me,
.footer, .top{
width: 50%;
}
.middle-about-me{
width: 50%%;
}
}
/*Width at 640px and below */
#media screen and (max-width: 640px) {
body {
background-color : #E9967A;
}
.container {
background-color: green;
border-style: none;
width: 50%;
}
.middle-about-me,
.footer, .top{
width: 50%;
}
.middle-about-me{
width: 50%%;
}
}
Start out by removing fixed width properties. I am having a hard time seeing how you need width: 50% on everything. Then start by just addressing the styles of your .container element.
A good techniques is setting the max-width to the width you have in mind for the site to be viewed on a normal desktop screen, in the demo I used 600px but you can use any value that feels right.
Then in you media query assign a new max-width value that is appropriate for the screen size in the query, here i used 80% becuase typically on small screens you want the content to mostly fill the width of the screen with a little space on the sides, but again you can configure this to your needs in a variety of ways.
The main thing here is that your container element is now responsive and the content inside can fill up the space however you like from there. Run the snippet and click the Full page link to play around with the screen width and see the behavior working.
.container {
max-width: 600px;
margin: 0 auto;
}
#media screen and (max-width: 640px;) {
.container {
max-width: 80%;
}
}
<div class="container">
<div class="top">
<div class="myname">
<h4 class="firstlast">name</h4>
</div>
<div class="list">
<ul>
<li class="contact">Contact</li>
<li class="portfolio">Portfolio</li>
<li class="about">About</li>
</ul>
</div>
</div>
<div class="middle-about-me">
<div class="center">
<h3> About Me</h3>
<hr>
<p class="myinfo">Hi my name is ..... and I was born on October 9th, 1971 in ......
<img src="assets/img/author.jpg" width="150px" height="150px"><br>
  To briefly introduce the... to you I would say it is a country located on the........>
    shares the same borders with ....... It is the world largest<br>
 producer of coacoa used for chocalate and lotions. In one word, it's the country where chocolate tastes like<br>  real chocolate. Since the last discovery of petrol in the country, it's been a little agitated as France and the<br>US want to control the discovery. After obtaining my masters in Business Management, I worked as the marketing representative for an american company before moving to the US to pursue a degree in Mathematic at UNT Dallas and worked for...,...., and.... as a Math instructor. My goal in this program is to learn to build websites from scratch and later on to build apps from scratch. I've got the right instructional staff and the right TAs to help me reach that goal. All I have to do is to go to work.<br>   "Impossible is nothing", Muhammad Ali.</p>
<p class="smile"><i>hover on my picture and start smiling</i></p>
</div>
</div>
<div class="footer">
<p class="footer-copyright">Copyrigtht © 2019 Portfolio "name" All rights reserved.</p>
</div>
</div>
I wish you had a sketch of what the final product will look like it would have been very helpful. There is more to making a page responsive than writing just valid HTML tag and corresponding styles and mind typos because from your code the extra % sign will make
.middle-about-me{
width: 50%%;
}
misbehave.
There a couple of things you need to know to be able to make a page responsiveness effective and very close to what you want.
Firstly you should consider resetting the default styles that the browser naturally applies to valid HTML tags by using normalize.css or utilize the power of universal selector which is almost as good in modern browsers, something like:
*,
*::before,
*::after{
padding: 0;
margin: 0;
box-sizing: inherit; /* to inherit the value declared in the body selector */
}
html{
font-size: 62.5% /* (10/16) * 100% and this is possible because by default the value of 100% will be computed to 16px by the browser and equal to 1(r)em, with this conversion we can reduce the calculations whenever you want to convert a value from px to (r)em since the are in multiples of 10 eg 1(r)em == 10px and 10(r)em == 100px*/
}
body{
box-sizing: border-box;
}
img{
width: 100%;
min-width: 27rem; /* to make the images responsive and look good on smaller screens */
}
so with the that basic reset you can always rely on using ems or rems for fonts an percentages for images and other block element when it feels appropriate.
This little write up is not enough to teach you all you need to know about responsiveness in the web but I hope it shed light on your path. Meanwhile those were not my original ideas i took a course by 'Jonas Schmedtman', He actually thought me those.
If you have a sketch of what the final pages should look like or you are still not very clear with what i have tried to explain so far please don't hesitate to add a comment so that we tidy it up together.

How do I get the h2 and h3 elements I have on the same line as my div objects?

Title says all basically. I want the text right next to the slideshow.
<div class="displayBorder">
<div class="displayContainer">
<div class="pictureContainer">
<div class="photoContainer">
<div class="switchPhoto" id="switchLeft-wexford" onclick="lastPhoto('wexford-1')"><</div>
<img src="css/img/wexford-1.jpg" id="wexford-image" />
<div class="switchPhoto" id="switchRight-wexford" onclick="nextPhoto('wexford-1')">></div>
</div>
</div>
<h2 id="wexford">17 My Street - Some Town, New York</h2>
<h3>$1,249,999</h3>
</div>
</div>
H tags have a specific purpose, to act as a header under which other content will fall. To use h tags side by side goes against their intended use (and is invalid html). The span tag does what an H tag does, but is an inline element (display:inline), where a H tag is a block level element (and acts like a div)(display:block). You can change the 'display' property of an H tag's css to do what a span does.
With that in mind, I would actually use 'display:inline-block' in your situation.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
h1 {
display: inline-block;
}
h2.asCouple {
display: inline-block;
margin-left: 15px;
}
</style>
</head>
<body>
<div>
<h1>Topic - <h2 class="asCouple">Subtopic</h2></h1>
</div>
</body>
</html>
Hope this helps.
You can do it inline when declaring the HTML element, I did something like this:
<h6 style="display: inline">Posted by <h4 style="display: inline">{{.}}</h4></h6>
By doing this, you don't change the style of all <hSOMETHING> elements
<div class="displayBorder">
<div class="displayContainer">
<div class="displayTable">
<div class="pictureContainer">
<div class="photoContainer">
<div class="switchPhoto" id="switchLeft-wexford" onclick="lastPhoto('wexford-1')"><</div>
<img src="css/img/wexford-1.jpg" id="wexford-image" />
<div class="switchPhoto" id="switchRight-wexford" onclick="nextPhoto('wexford-1')">></div>
</div>
</div>
<div class="txt-con">
<h2 id="wexford">Location</h2> <br />
<h3>$1,249,999</h3>
<p>Custom Built Home With Every Bell And Whistle !/ Ch Colonial With 6 Generous Bdrms, 2 Master Suites Or Use Lge Area For Office, 5 Full Baths, Wood Floors Thru-Out, Granite Eik W/ Center Isle, Top Appliances, Andersen Windows, Lots Of Details, Full Finished Basement W/ Ose, Full Wet Bar, Theater Tv Area, Playrm, Lots Of Storage, Custom Freeform Salt Pool, Custom Pool House</p>
</div>
</div>
<button class="learn-btn">LEARN MORE</button>
</div>
#Jared Scarito is this what you need??
CSS
.displayContainer{
display:table;
}
.photoContainer,.txt-con{
display:table-cell;
vertical-align:middle;
}
HTML
<div class="displayBorder">
<div class="displayContainer">
<div class="pictureContainer">
<div class="photoContainer">
<div class="switchPhoto" id="switchLeft-wexford" onclick="lastPhoto('wexford-1')">
<</div> <img src="https://i.stack.imgur.com/rhy46.png" id="wexford-image" />
<div class="switchPhoto" id="switchRight-wexford" onclick="nextPhoto('wexford-1')">></div>
</div>
</div>
<div class="txt-con">
<h2 id="wexford">1234 My Street - Sometown, New York</h2>
<h3>$1,249,999</h3>
</div>
</div>
</div>
changed the image to demonstrate
Pretty much the same HTML, added extra div around h3 and h2..

Uneven padding on row elements in Bootstrap

I have a grid layout consisting of 4 rows in Twitter Bootstrap.
I would like each row to be even in height, with equal padding between the content of each row.
However the padding on the rows are currently unequal.
For example the space at the foot of the li items in 'Technologies' and the hr line is significantly narrower than the space at the foot of 'Education'.
I cannot see in my CSS where I am going wrong, but how can I apply equal padding throughout? Thanks in advance
Here is the link to my website where the issue is.
<div class="container">
<div id="greeting">
<p>
My interest in coding primarily stemmed from my day job which exposed me to the basics of HTML. I've still got a long way to go but it's my ambition to forge a long-term career as a developer, and I'm very determined to reach my goal.
</p>
</div>
<div class="hr"><hr></div>
<div class="row">
<div class="col-md-4">
<h2 class="sideheader">Technologies</h2>
</div>
<div class="col-md-4">
<h2 class="tech-header">Comfortable</h2>
<ul>
<li> HTML5</li>
<li> CSS3</li>
<li> Bootstrap</li>
<li> Adobe PhotoShop</li>
</ul>
</div>
<div class="col-md-4">
<h2 class="tech-header">Finding my feet</h2>
<ul>
<li> JavaScript</li>
<li> JQuery</li>
<li> PHP</li>
<li> SQL</li>
</ul>
</div>
</div>
<div class="hr"><hr></div>
<div class="row">
<div class="col-md-4">
<h2 class="sideheader">Experience</h2>
</div>
<div class="col-md-8">
<h2>Reader Offer Administrator / Account Manager</h2><br><h3>Thompson & Morgan - March 2007 to August 2015</h3>
<p>A highly varied role acting as support to a successful and fast-moving sales team as well as contact to our client base. My primary duties were to maintain the smooth running of our order processing system, as well as oversee a range of product content across several CMSs. It was this latter part of my job which has spurred me to establish a career in web development.</p>
</div>
</div>
<div class="hr"><hr></div>
<div class="row">
<div class="col-md-4">
<h2 class="sideheader">Education</h2>
</div>
<div class="col-md-8">
<h2>University of Brighton</h2><br><h3>October 2003 to July 2006</h3>
<ul>
<li> BA(Hons) Social Science (2:1)</li>
</ul>
</div>
</div>
<div class="hr"><hr></div>
<div class="row">
<div class="col-md-12" id="button">
View my full CV
</div>
</div>
Here is your specific code :
HTML :
<div class="col-md-8">
<h2>Reader Offer Administrator / Account Manager</h2>
<br> <----- REMOVE THIS
<h3>Thompson & Morgan - March 2007 to August 2015</h3>
<p>A highly varied role acting as support to a successful and fast-moving sales team as well as contact to our client base. My primary duties were to maintain the smooth running of our order processing system, as well as oversee a range of product content across several CMSs. It was this latter part of my job which has spurred me to establish a career in web development.</p>
</div>
Css:
#resume h3, #resume .col-md-8 li, #resume .col-md-8 p {
top: -60px; <----- REMOVE THIS
position: relative;
}
If you remove the <br/> and the top:60px; every thing returns to the normal.

Bullet points on li element not displaying on page

In the below code unordered list bullet symbols are not displaying. Can any one help me.
expected output:
Smart class (Digital Technology) as a part of classroom teaching.
html
<section class="container">
<div class="row">
<!-- main content -->
<section class="col-sm-8 maincontent">
<h3>Our Facilities</h3>
<img src="assets/images/about.jpg" alt="" class="img-rounded pull-right" width="300" />
<ul>
<li>Smart class (Digital Technology) as a part of classroom teaching.</li>
<li>Karate Classes</li>
<li>Well equipped, Compute Lab and Science Lab.</li>
<li>CET classes,</li>
<li>Sports Academy.</li>
<li>Eco and Environment Club,Adventure Club.</li>
</ul>
</div>
</div>
</section>
</div>
</section>
Check your CSS. Make sure it contains something similar to ul {list-style-type: circle;}.
For other style types, see the reference.

Non-navigation NON fixed navbar bottom not stretching full width

I am trying to get the bottom navbar which is inverse and non fixed and non navigation to stretch full width to cover the complete viewport...well in terms of the design effect it is to have a nice footer stretching full width non fixed...
it used to work when I was on an navbar-default navbar-inverse navbar-fixed-bottom role=presentation. I've tried to change div into row, set row before navbar... it is either I loose the full length or either I loose the inverse... each time I'm gaining something I'm loosing something else... Aaarrrggh... I don't know where to look anymore and I don't have enough knowledge to go and mess around with the media attributes... Anyone has a solution? Thanks a bunch... Max
<nav class="navbar-default navbar-inverse" role="presentation">
<div class="row">
<div class="col-md-3">
<ul>
<li><strong>Partner Companies:</strong><br>
Monsoon Restaurant<br>
Kasha Boutique Hotel<br>
Konokono Beach Villas<br>
Livingstone Restaurant<br>
Seyyida Hotel & Spa</li>
<span><a class="glyphicon-copyright-mark"></a>Copyright SERENE TOURS ZNZ 2014</span>
</ul>
</div>
<div class="col-md-3">
<ul>
<li><strong>Office Tanzania:</strong><br>
Kenyatta Shangani<br>
P.O. Box 1370<br>
Stonetown Zanzibar<br>
+255242234402 Tel<br>
+244242234411 Fax<br></li>
</ul>
</div>
<div class="col-md-3">
<ul>
<li><strong>US Office:</strong><br>
250 Gabriel Circle #9<br>
Sapphire Lakes<br>
Naples FL US-34104<br>
+12393008592 Tel<br>
+12393528777 Fax<br></li>
</ul>
</div>
<div class="col-md-3">
<ul>
<li><strong>Follow us:</strong><br>
<img src="_images/youtube30x30.jpg"> You Tube<br>
<span id="tumblr_button_abc123"></span><br>
<img src="http://www.socialmediabuttons.com/images/facebook6.gif" title=""><br>
<img src="_images/instagram.jpg" alt="Instagram"> Instagram</li>
</ul>
</div>
</div>
</nav>