How to make horizontal strips across full screen without this "hack" - html

I'm building a theme for a site and the behavior I want is for the main content to be contained in a horizontally centered div with a max-width, except for occasional rows that have colored backgrounds extending the entire width of the screen (this is the type of look that a lot of modern sites have). I'm also using bootstrap and I don't know if there are classes built-in for me to do this type of thing. But what I've been doing is like
<div class="container">
<div class="row">
<p>Here's a row that stays contained in the container</p>
</div>
<div class="row expand-full-width">
<div class="container">
<p>Here's a row that is contained in the center but has a background extended all the way across the screen horizontally</p>
</div>
</div/>
<div class="row">
<p>Here's a row that stays contained in the container</p>
</div>
<div class="row expand-full-width">
<div class="container">
<p>Here's a row that is contained in the center but has a background extended all the way across the screen horizontally</p>
</div>
</div>
</div>
.container { width: 200px; margin: 0 auto; }
.row { padding: 15px 5px; }
.expand-full-width { margin-left: -1000000px; margin-right: -1000000px; background: yellow; }
(fiddle: http://jsfiddle.net/pjpuLcat/)
but I'm wondering if there's a better way to do it because the margin-left: -somebignumber; margin-right: -somebignumber; "hack" is messing up the structure of some 3rd-party items I'm trying to incorporate in my site, including a JavaScript carousel. So is there a better way of doing this?

You're definitely right to think that having huge negative margins is not a great idea. Instead of having one .container that wraps everything, you should have .containers within each section.
<div class="row">
<div class="container">
<p>Here's a row that stays contained in the container</p>
</div>
</div>
<div class="row expand-full-width">
<div class="container">
<p>Here's a row that is contained in the center but has a background extended all the way across the screen horizontally</p>
</div>
</div>
<div class="row">
<div class="container">
<p>Here's a row that stays contained in the container</p>
</div>
</div>
<div class="row expand-full-width">
<div class="container">
<p>Here's a row that is contained in the center but has a background extended all the way across the screen horizontally</p>
</div>
</div>
.container { width: 200px; margin: 0 auto; }
.row { padding: 15px 5px; }
.expand-full-width { background: yellow; }
Updated fiddle

Related

How do I put a small text on top and on bottom of a word in a paragraph using css?

I wanna know how do I put a word on top and on bottom of a text using CSS? It's hard to put in words so I've made a rough image on what I really mean
As you can see, the "My name is Marwan and I am 20 years old." part is just the normal paragraph on a web page in large fonts, and uppertext and bottomtext is in small fonts and the words in the paragraph automatically makes the required space in between so that the uppertext and bottomtext are always aligned in the middle. The paragraph is however not aligned and is either LTR or RTL depending on the language.
I have no idea how I can successfully achieve it. Any help would be appreciated.
Is this what you're trying to do? https://codepen.io/anon/pen/JZzMjL
I just created a parent div with a text-align: center; and inside that div I created divs for each section of text. This will make sure all text is centered.
.row-wrap {
text-align: center;
float: left;
margin: 0 10px;
}
.row-middle {
font-size: 30px;
}
<div class="row-wrap">
<div class="row-top">uppertext1</div>
<div class="row-middle">My</div>
<div class="row-bottom">bottomtext1</div>
</div>
<div class="row-wrap">
<div class="row-top">uppertext2</div>
<div class="row-middle">Name</div>
<div class="row-bottom">bottomtext2</div>
</div>
<div class="row-wrap">
<div class="row-top">uppertext3</div>
<div class="row-middle">Is</div>
<div class="row-bottom">bottomtext3</div>
</div>
<div class="row-wrap">
<div class="row-top">uppertext4</div>
<div class="row-middle">Some</div>
<div class="row-bottom">bottomtext4</div>
</div>
<div class="row-wrap">
<div class="row-top">uppertext5</div>
<div class="row-middle">Long Name</div>
<div class="row-bottom">bottomtext5</div>
</div>

Bootstrap 3.0: Full-Width Color Background, Compact Columns in Center

I was looking to make a striped business theme, similar to the one created by W3Schools. The theme can be found here. It is characterized by horizontal sections, separated by different background colors.
The one issue I had with it was that the columns in Services, Portfolio and Pricing, spanned pretty much the full width of the page, which I did not think looked great, particularly for the three pricing boxes, which i feel should be much narrower and still centered. Let's take those pricing boxes as the example for the purpose of the questions.
So, I embarked upon the task of squeezing these three pricing boxes into a narrower shape, centered on the page, while still maintaining the full-width alternating background color. I came up with three ways to do it:
1) Place a Container inside a Container-Fluid:
<div id="pricing" class="container-fluid">
<div class="container">
<div class="row">
<div class="col-sm-4 col-xs-12">
BlaBlaBla
</div>
...
</div>
</div>
</div>
2) Make the following additions/changes to the css and html:
.fixed-width {
display: inline-block;
float: none;
width: 300px;
}
.row-centered {
text-align: center;
}
-
<div id="pricing" class="container-fluid">
<div class="row row-centered">
<div class="col-sm-4 col-xs-12 fixed-width">
BlaBlaBla
</div>
...
</div>
</div>
3) 3x col-sm-2, with empty columns on each side
Keep the container-fluid layout, but instead of having three col-sm-4, I have an empty col-sm-3, three col-sm-2, and finally an empty col-sm-3 (for a total of 12 columns).
4) 3x col-sm-2, with offset-3 to center
Instead of having three col-sm-4, I have one col-sm-2 col-sm-offset-3, then two col-sm-2 (this does not add to 12, but i center with offset).**
The problem with both (3) and (4) is that once i shrink the browser window, the boxes become too small before they wrap to the next line (i.e. the text flows out of the box). In (4) it seems if i use container (as opposed to container-fluid), the boxes become too narrow in full-screen even.
What is the correct way of doing this? I assume this is an issue almost everyone making business websites stumbles across, yet I was not able to find the answer online having worked on it for hours.
Thanks in advance,
Magnus
Below follows what I think is the best way to solve this. I will divide it up in whether or not it is a background image or color we are looking to apply accross the full width.
CSS (formatting for illustration purposes and fixed width)
.content{
padding:20px;
border: 1px solid #269abc;
background:#d6ec94;
}
[class*="col-"] {
padding-top:10px; /* 15px side paddings automatically applied */
padding-bottom:10px;
border: 1px solid grey;
background: transparent;
}
.fixed-width {
display:inline-block;
float:none;
width: 300px;
}
The key here is the fixed-width class, and follows your approach (2). The other styles are just so you can try it and easily see how it works.
CSS (background image)
#one {
background-image: url([insert-url]);
background-repeat: no-repeat;
background-size: contain;
height:500px;
}
The key here is the background-size: contain element. As long as the width/height ratio of your background image is larger than the section's ratio, the image will fill the full background.
CSS (background color)
#two {
background-color: grey;
height:500px;
}
background-color works without any tweaks.
HTML
<section id="one">
<div class="container">
<div class="row text-center">
<div class="col-sm-4 fixed-width">
<div class="content">HERE</div>
</div>
<div class="col-sm-4 fixed-width">
<div class="content">HERE</div>
</div>
<div class="col-sm-4 fixed-width">
<div class="content">HER</div>
</div>
</div>
</div>
</section>
As seen, by adding a <section> around the container, you can apply the background image or color to the full width of the page.
IN Bootstrap,
Col-lg is large screen,
Col-sm is small screen,
Col-md is medium devices,
Col-xs is Small screen.
According to the browser ,we can use the all classes.In my experience we can use the col-lg-offset-3 for large screen,Remaining screen we should use without offset,like us,
UL list format:
<style>
ul{
margin:0;padding:0;
text-align:center;
}
ul li
{
display:inline-block;
text-align:center;
width:300px;
}
</style>
<ul>
<li>box1</li>
<li>box2</li>
<li>box3</li>
</ul>
whatever screen all list will come in center position of screen.
other format:
<div class="container">
<div class="row text-center">
<div class="col-lg-offset-3 col-lg-2 col-sm-4 col-md-4 col-xs-12">contenbox..</div>
<div class="col-lg-2 col-sm-4 col-md-4 col-xs-12">contenbox..</div>
<div class="col-lg-2 col-sm-4 col-md-4 col-xs-12">contenbox..</div>
</div>
</div>
we should use all classes to our business requirement.if we can alter-ate the various offset class for col-sm-offset-,col-md-offset.,
<div class="col-sm-4 col-xs-12">
Is the important line. The col-sm-4 is saying on small screens and above, take up 4 of 12 bootstrap columns. So, try decreasing this to 3 of 12 bootstrap columns, i.e. col-sm-3. Here it is within the example source code:
<div class="col-sm-3 col-xs-12">
<div class="panel panel-default text-center">
<div class="panel-heading">
<h1>Basic</h1>
</div>
<div class="panel-body">
<p><strong>20</strong> Lorem</p>
<p><strong>15</strong> Ipsum</p>
<p><strong>5</strong> Dolor</p>
<p><strong>2</strong> Sit</p>
<p><strong>Endless</strong> Amet</p>
</div>
<div class="panel-footer plan">
<h3>$19</h3>
<h4>per month</h4>
<button class="btn btn-lg">Sign Up</button>
</div>
</div>

col-lg-8 not using 8/12ths of the screen?

Hi all I'm using this bit of code
<section id="post1">
<div class="container-fluid post-1">
<div class="row">
<div class="col-lg-12">
<div class="col-lg-8 oblongbig">
</div>
<div class="col-lg-4">
<div class="row">
<div class="=col-lg-6 oblong">
</div>
</div>
<div class="row">
<div class="col-lg-6 oblong">
</div>
</div>
</div>
</div>
</div>
</div>
</section>
to create three boxes, have a look at http://deliciousproductions.com.au
My problem is that the first and larger box is fine but the second two boxes should start after the first col-lg-8, but they just start right up against the large box, as though there's no padding/margin. I added a 10px margin so it's easier to understand. So the col-lg-8 isn't making it's width 8/12's of the screen?
The 2 boxes in rows also aren't responsive, they are but when you make the page smaller this happens: https://gyazo.com/4929147de70b0a88ac54d29f4ff2c243
and then finally: gyazo[.]com/c57374233a4e0f14fc4f757841893cc5
What would you recommend to make it so when the page resizes the 2 smaller boxes resize so they fit next to each horizontally under the larger box. This is for a blog style site btw.
cheers, Nik
here's the css for each box too
.oblongbig {
float: left;
width: 600px;
height: 300px;
background-color: #050505;
border-width: 1px;
border-style: solid;
border-color: rgba(0,0,0,.2);
margin: 10px;
}
.oblongbig:hover, .oblong:hover {
background-color: #121212;
}
.oblong {
float: left;
width: 300px;
height: 150px;
background-color: #050505;
border-width: 1px;
border-style: solid;
border-color: rgba(0,0,0,.2);
margin: 10px;
}
similar to this: demo
There is some problem with your grid code. Use this one
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-8">
<div style="height:330px;background:#000;"></div>
</div>
<div class="col-lg-4">
<div class="row">
<div class="col-sm-12">
<div style="height:150px;background:#000;margin-bottom:30px;"></div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div style="height:150px;background:#000;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Also don't apply styles directly on grid column. Place content div inside grid column and apply whichever styles you want on that div.
Check out this URL for better understanding of Bootstrap grid system - http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-grid-system.php
To count a column you need to consider the value of the intervals between them.
Here you can see a visual explanation
There are a couple of issues going on in your code. For Bootstrap columns to work properly, you can't have a column div inside another column div without starting a row. For example, you must format it like this:
<div class="container-fluid">
<div class="row">
<div class="col-lg-8">
<div class="row">
<div class="col-lg-6"></div>
<div class="col-lg-6"></div>
</div><!-- .row -->
</div>
<div class="col-lg-4"></div>
</div><!-- .row -->
</div>
In your example you have two nested columns with no row in between. This will mess up your column padding & margins.
Refer to the docs: http://getbootstrap.com/css/#grid-nesting
Next, you're applying your own classes (.oblong, .oblongbig) with set float, fixed width, and margin to the Bootstrap column div. These are overriding the Bootstrap styles and preventing your columns from working properly.
The best idea is to use elements with Bootstrap classes to build your layout, then put elements inside these layout elements with your own custom classes. For example:
<div class="col-lg-6">
<div class="oblong">Your content here, separate from the Bootstrap element</div>
</div>
Avoid overriding the framework's styles, as this results in confusing code. Once you reformat your code so that columns are correctly nested and you're not overriding the Bootstrap classes with your own custom widths, it should come together how you want.

Bootstrap 3 | Responsive col width and height

I'm working on a Bootstrap page for the first time. Used to working in HTML/CSS and all just not bootstrap. I'm having some difficulty with the following:
I created a fluid ( full width ) container that spans 4 columns.
The 1st column contains an image, the 2nd text, the 3rd an image and the 4th text again. The next row of columns is alternating.
I want my columns to have a responsive width and height so that if i adjust the viewport, the colums are always squared and stretching the full page. I just can't seem to get this to work. Tried various things. Setting max width, using percentages, background images, img scr tags that scale to 100% etc. but nothing seems to work.
Can anyone tell me how i can make this happen?
Greatly appreciated. No problem if JS or JQuery is needed to make it work. I got the basics covered so i know how to do that if someone points me in the right direction ( not a JS wizard to figure this one out on my own just yet ).
For example, i provided my HTML markup.
The CSS is pretty basic. Just provided the background images in the ft-img columns and some styling for the fonts. Also, currently all col have a fixed height of 400 pixels but that is abviously not the way to go. :P
<div class="container-fluid main-content">
<div class="row">
<div class="col-md-3 ft-img ft-1">
</div>
<div class="col-md-3 ft-text">
<h1>Heading</h1>
<hr>
<p>Paragraph </p>
</div>
<div class="col-md-3 ft-img ft-2">
</div>
<div class="col-md-3 ft-text">
<h1>Heading</h1>
<hr>
<p>Paragraph </p>
</div>
</div>
<div class="row">
<div class="col-md-3 ft-text">
<h1>Heading</h1>
<hr>
<p>Paragraph </p>
</div>
<div class="col-md-3 ft-img ft-1">
</div>
<div class="col-md-3 ft-text">
<h1>Heading</h1>
<hr>
<p>Paragraph </p>
</div>
<div class="col-md-3 ft-img ft-2">
</div>
</div>
</div>
As asked, here's the CSS. I initially did not provide it since it's just the basics and it's just one of the things i tried. As said above.
.ft-img {
background-size: 100%;
background-position: center center;
height: 400px;
}
.ft-text {
background: url('../img/bg.png');
background-position: 10% 10%;
height: 400px;
color: #fff;
font-family: 'Lato', sans-serif;
padding: 40px;
}
.ft-text h1 {
font-size: 2.5em;
font-weight: bold;
}
.ft-text p {
font-size: 1.2em;
}
.ft-1 {
background: url('../img/ft/ft-1.jpg') no-repeat;
}
.ft-2 {
background: url('../img/ft/ft-2.jpg') no-repeat;
}
If you want to be fluid, you can't specify fixed units (px).
Consider using the vw unit to make your heights relative to their widths to maintain squares.
http://www.w3.org/TR/css3-values/#viewport-relative-lengths

Div not taking height of parent div (w/ bootstrap)

I'll start off by stating that I know this question has been asked a lot, but none of the answers I saw seemed to work for me.
Basically, I have some divs inside of a larger div. They'll have dynamic text, so I don't know how many lines each will be. The problem is that I can't seem to get the divs to size themselves to the parent's height. I want the column divs to take up the entire height of the row div (basically, I want that blue part to fill all the space between the bars).
HTML:
<div class="container">
<div class="row divOne">
<div class="col-xs-3 divTwo">Some Text</div>
<div class="col-xs-3">
Some text that could wrap to multiple lines
</div>
</div>
<div class="row divOne">
<div class="col-xs-3 divTwo">Different Text</div>
<div class="col-xs-3 divThree">
With some more text
</div>
</div>
</div>
CSS:
.divOne
{
border-top:10px solid black;
}
.divTwo
{
background-color: #32649b;
height:100%;
color:white;
}
jsfiddle:
Now, what I've learned from other versions of this question are that
float:left might be screwing it up
height:100% doesn't work if the parent's height is defined
position:relative might help on the parent
The problem with the float is that I'm using bootstrap, and that's where the float is coming from, so I don't really want to mess with that.
I can't really define parent height, because it'll be dynamic based on the children.
I also tried messing around with position:relative on the parent and absolute on the child, but that seemed to get really screwy. I'm also guessing this won't work because I'm using bootstrap. It's possible that I'm just missing something, though. I'll admit to not being the greatest with CSS.
I don't know if I'm having these issues because I'm using bootstrap, or because I'm just being an idiot right now.
Something else that seems to be throwing a wrench into things: These columns will be laid out differently on smaller screens vs. larger ones. I actually want something along the lines of col-xs-12 col-md-3 for these.
The short answer is that you can't really achieve this within the constraints of the bootstrap framework. There are plenty of articles that explain why div elements can't stretch to the height of their container, and how to get around this problem. One of the solutions I'm most fond of is Faux Columns.
But, let's get a little more creative then that.
I came up with something that might work for your scenario, but requires a bit of change to your markup. Here's a solution that wraps the bootstrap grid with display: table.
http://jsfiddle.net/Wexcode/13Lfqmjo/
HTML:
<div class="table-container">
<div class="table-row divOne">
<div class="col-xs-3 divTwo">Some Text</div>
<div class="col-xs-3">
Some text that could wrap to multiple lines
</div>
<div class="col-xs-6"></div>
</div>
</div>
CSS:
.table-container {
margin: 0 -15px;
}
.table-row {
display: table;
width: 100%;
}
.table-row [class^="col"] {
display: table-cell;
padding: 0 15px;
float: none;
}
Note that for this solution to work, you must include enough col elements to stretch it all 12 columns (see that I added an empty .col-xs-6 div).
You can add
display:flex;
to divOne , and will act like you wanted.
in bootstrap 4 'row' class applies this on div, but in ealier versions you need to add manually if you expect such behavior.
Give .divOne a display: flex and remove the height: 100% from .divTwo:
.divOne
{
border-top:10px solid black;
display: flex;
}
.divTwo
{
background-color: #32649b;
/*height:100%;*/
color:white;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row divOne">
<div class="col-xs-3 divTwo">Some Text</div>
<div class="col-xs-3">
Some text that could wrap to multiple lines
</div>
</div>
<div class="row divOne">
<div class="col-xs-3 divTwo">Different Text</div>
<div class="col-xs-3 divThree">
With some more text
</div>
</div>
</div>