How to align these two elements inside a div - html

I am having a little trouble aligning two elements inside a div (the quote and the arnold pic).
Here is what it looks like:
<div class="container">
<div id="quote">
<p id="tagline-quote">"As a personal fitness trainer, I'm asked on a weekly basis where the best place to buy supplements is, and my answer is always bodybuilding.com"</p>
<img id="q-image" alt="" src="http://www.cheapestsupplementsonline.com/wp-content/uploads/2012/03/arnold_schwarzenegger.jpg"></img>
</div> <!-- end #quote -->
Here is the css:
.container {
margin: 0 auto;
position: relative;
text-align: left;
width: 960px;
}
#quote {
padding: 60px 400px 20px 13px;
text-align: center;
}
p#tagline-quote {
color: #777676;
font-family: Georgia,serif;
font-size: 20px;
font-style: italic;
line-height: 30px;
text-shadow: 1px 1px 0 #FFFFFF;
}
#q-image{
}

This is a textbook "css floats 101" question. Oh, wait, I thought that was original but that's exactly what the article on alistapart is called. You can position the image inside the quote/paragraph and float it right - that's pretty much what the floats were made for before semantic layouts took over :)
<div class="container">
<div id="quote" class="clearfix">
<img id="q-image" alt="" src="http://www.cheapestsupplementsonline.com/wp-content/uploads/2012/03/arnold_schwarzenegger.jpg" />
<p id="tagline-quote">“As a personal fitness trainer, I'm
asked on a weekly basis where the best place to buy supplements is,
and my answer is always bodybuilding.com”</p>
</div>
</div>​​​​​​​​​​​​​​​​​​​​​
For CSS, I've thrown out some of the original padding :
#q-image{
float:right;
/*add some margin so that there is space between text and photo*/
margin-left:10px;
}
Now the issue that you were having with KodeKreachor's code was seemingly incorrectly "garbling" the divs below and you probably saw the quote container looking shorter than it should be. The workaround is using a "clearfix" that expands the parent container so that the floated element can fit inside. Remove it from the code and see how the (temporarily) highlighted container acts.
On a side note... try adding more paragraphs and move the image into one of them. Now that "odd" behaviour makes perfect sense - paragraphs start flowing nicely around that floated image without massive gaps.
Fiddle: http://jsfiddle.net/EvdV8/ Also: proper quotes. Also: img is a self-closing element so original markup was not valid.

If you're talking about side-by-side, you use a combination of "float: left;" and "display: inline-block" to force them next to each other.
.container {
margin: 0 auto;
text-align: left;
width: 960px;
}
#quote {
padding: 60px 400px 20px 13px;
text-align: center;
display: inline;
}
p#tagline-quote {
color: #777676;
font-family: Georgia,serif;
font-size: 20px;
font-style: italic;
line-height: 30px;
text-shadow: 1px 1px 0 #FFFFFF;
position:relative;
width:400px;
display: inline-block;
}
#q-image{
position:relative;
float: left;
}

Related

I am trying to get the text to appear on the right hand side of the image, and for the actual image box to be a lot slimmer that it currently is

This is the css I have atm but it is all going chaotic and this is how the section of the page looks:
[![
#firstborder{
border: #3063A5;
border-style: double;
font-size: 9.5px;
font-family: "Palatino Linotype", serif;
padding-left: 5px;
float: left;
margin: 0 20px 20px 0;
}
.linguistics_paragraph{
margin-left: 385px;
padding: 3px; margin-top: 5px;
top: 40px;
font-family: "Palatino Linotype", serif;
margin-right: 3px;
margin: 0 0 10px 10px;
float: right;
}
]1]1
To make the image box slimmer I would suggest using the max-width property and setting it to your desired width so it never gets any bigger than that.
I can make a code snippet but as far as your text issue, are you trying to get the text within the bordered box? Also what is your desired outcome for the legend?
I'm gonna answer this question on a conceptual basis as you don't have your HTML provided
So as you said everything gets messy when you change the width of the browser therefore
we have to first work on making it responsive. So just go to your Html file and make a div wrapper or container that would hold both of your image and the paragraph tags
for example, something that would look like this:
<div class="container">
<img src="files/exampleimg.png" id="pic">
<p id="text">This is something</p>
</div>
Now in your CSS file remove the margin-left or margin-right you used to position the image and the paragraph tags and use flex or grid or anything similar to make it responsively positioned, I'm gonna go with flex so here it goes:
.container{
display:flex;
justify-content: space-between; /*putting img to left and paragraph to right*/
}
#pic {
padding-left: 50px; /*as per your requirement*/
}
#text {
padding-right: 50px; /*as per your requirement*/
}
and that's pretty much it for the responsive part, all we have to do now is make the image box slimmer, so for that do this:
#firstborder{
border: 1px solid #707070; /*this would make it slimmer but play with it to find out what suits best*/
}
you change the 1px to 4 px its gonna get thicker and you crank it down and it would get slimmer, there you go, now you have a responsive page and your image-box slimmed up.
and oh for your legend part add this to your HTML
<img src="files/legend.png" id="legend">
CSS:
.container{
display:flex;
justify-content: space-between;
position: relative; /*binding up the legend with container*/
}
#legend {
padding-left: 50px;
position: absolute; /*stiching the legend to that pic*/
top: 40px; /*as per your requirement*/
}

Aligning inline-block center

What would be the easiest way to center align an inline-block element?
Ideally, I don't want to set a width to the elements. This way depending on the text inputted within the elements, the inline-block element will expand to the new width without having to change the width within the CSS. The inline-block elements should be centered on top of one another (not side by side), as well as the text within the element.
See code below or see on jsFiddle.
The current HTML:
<div>
<h2>Hello, John Doe.</h2>
<h2>Welcome and have a wonderful day.</h2>
</div>
The current SCSS:
#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,600);
body {
margin: 0 auto;
background: rgba(51,51,51,1);
font-family: 'Open Sans', sans-serif;
}
div {
width: 100%;
height: auto;
margin: 15% 0;
text-align: center;
h2 {
margin: 0 auto;
padding: 10px;
text-align: center;
float: left;
clear: left;
display: inline-block;
&:first-child {
color: black;
background: rgba(255,255,255,1);
}
&:last-child {
color: white;
background: rgba(117,80,161,1);
}
}
}
Adding a br between the two elements and taking out the float: left/clear: left may be the easiest way; however, I was curious if there was another way going about this.
Like this? http://jsfiddle.net/bcL023ko/3/
Remove the float:left left and add margin: 0 auto to center the element. Or is it something else that your are looking for?

HTML/CSS - How can I change the spacing or add whitespace so the boxes are equal?

I'm new to the frontend and work out of the backend. I found a layout I am interested in using however noticed that when typing in these boxes if the text length isn't equal the sizing of the box changes for one of the boxes in the row and not all.
I want them all the be sized equally so if one box is using one line of text and the others two lines, the one line provide white space to match the size.
E.g.
I'd like all the boxes on that row to add in the whitespace so the boxes are equal in size so I don't get the layout issues since in the pic above.
Like this:
How do I change the css for the boxes to automatically resize all the boxes and not just one?
This is the layout I am using: http://adapt-trackers.blogspot.in/
It seems as though right now their spacing is determined by the margin/padding/border values. Try setting a height and width so that they are all the same.
For example:
#selectable li { margin: 3px; padding: 1px; float: left; width: 165px; height: 160px; font-size: 1.5em; text-align: center; }
try this (courtesy of CSS the Missing Manual):
<div id="gallery">
<div class="figure">
<div class="photo">
<img src="../images/carpet.jpg" alt="Carpet Grass" width="200" height="200" /> </div>
<p>Figure 1: Even the carpet-like <em>Carpetorium Pratensis</em> requires mowing. </p>
</div>
In this example, the gallery div wraps all the images together; the photo class wraps each image and caption together. Here's the CSS:
.figure {
float: left;
width: 210px;
margin: 0 10px 10px 10px;
}
.photo {
background: url(drop_shadow.gif) no-repeat right bottom;
}
.photo img {
border: 1px solid #666;
background-color: #FFF;
padding: 4px;
position: relative;
top: -5px;
left:-5px;
}
.figure p {
font: 1.1em/normal Arial, Helvetica, sans-serif;
text-align: center;
margin: 10px 0 0 0;
height: 5em;
}
Also, there's several gallery frameworks that you could use instead. Or stag some code from dynamicdrive.com
I'd give your tag for ... a minimum height.
add class to your anchor tags:
Link:
...
css:
.link-title{
min-height: 150px;
}

Links with images do not stay in middle

So, I got set of links set up like this. Apologies for bad names, but to keep it easy to understand, I chose to not to use real paths/names. However, all paths check out in when page is shown/used.
<nav>
<div class="center">
<img src="folder/image1.gif" alt="">
<img src="folder/image2.gif" alt="">
<img src="folder/image3.gif" alt="">
</div>
</nav>
Now, I want each image stick to each other, so that they form a one long bar. With the current set up, they all line up in the middle of the page in one row. However... there are spaces in between each. Here is the CSS:
.center {
margin: 0 auto;
text-align: center;
display: block;
}
a.navigointi
{
float:left;
margin: 0px;
padding: 0px;
}
img.navigointi
{
margin: 0px;
padding: 0px;
border: 0px;
}
However, if I designate images as navigointi class... they do stick together, forming a one long bar, but at the same time, it breaks the centering. All images float to left side of the screen. Even if I remove all content from the img.navigointi, so it becomes empty style, it still remains the same. If I don't give the images a class, they return to the middle, but once again with the spaces in between them.
Any idea what is causing the centering to break?
Here's a FIDDLE.
The line that removes the single space between the anchors is font-size: 0px;
(found on CSS-Tricks)
CSS
.center {
margin: 10px auto;
text-align: center;
display: block;
border: 1px solid black;
font-size: 0px;
}
.navigointi{
margin-left: 0px;
padding: 0px;
}
img
{
margin-left: 0px;
padding: 0px;
border: 1px solid red;
}
If I understand, you should use display: inline instead of float: left.
Here an example : http://jsfiddle.net/YTn2b/

How to stack in-line-block elements

Is it possible to stack in-line-block elements?
I have a DIV which I want the elements inside it (h1 and P) to be centred. So I set the DIV to text-align centre and initally set the H1 and P tag to inline-blocks.respectively.
The idea was to display the two elements (H1 and P) as in-line-block elements so content is centred and a transparent png shows in the background for the length of the text.
But the problem I have is that having elements as inline-blocks means they will appears next to each other (I don't want this to happen), so I set the P tag as block element but it's resulting in the transparent png being as wide.
HTML:
<div id="hero">
<div class="container">
<div class="row">
<div class="span12" id="hero-text">
<h2>Heading line</h2>
<p>Paragraph line goes here</p>
</div>
</div>
</div>
</div>
CSS
#hero {
height: 435px;
width: 100%;
background: url(../img/hero-image.png) 0 0 no-repeat;
background-color: #999;
position: relative;
color: #FFF;
border-bottom: 3px solid #E6E6E6;
}
#hero-text {
position: absolute;
top: 33%;
text-align: center;
}
#hero h2 {
font-size: 4em;
font-style: normal;
line-height: 50px;
padding-top: 10px;
background: url(../img/bg-heading.png) repeat;
display: inline-block;
padding: 10px 20px;
}
#hero p {
font-size: 2em;
line-height: 30px;
display: block;
background: url(../img/bg-heading.png) repeat;
padding: 10px 20px;
}
Any help is appreciated.
This was actually tougher to solve than I originally thought. I could find two options for you. If you don't want to change your markup:
Give both #hero h2 and #hero p display:inline-block, and give them widths so that their combined width is greater than 100%. They both can be width:51%, or one can be wider than the other, just as long as their total is more than the width of the parent. This will cause the p to break to a new line. See http://codepen.io/anon/pen/cjDiH OR
2.If you want their widths to be fluid, I'd add an element in between the h2 and p that is display:block. I added hr, then took away its margin, padding and border to make it not visible other than to cause the line break. See http://codepen.io/anon/pen/AGDti
I see you figured out out to get them to stack like in your screenshot.
Now,
try adding width: auto; to #hero p in your css.