Media query to move heading to right of image - html

I have a site that needs the placement of an h3 moved depending on the screen size.
The html is currently a table like this:
<table><tr><td><img src="someimage"></td><td><h3>Heading</h3></td></tr></table>
On smaller screens, I would want the h3 to appear above the image, with the image full width, so I start with:
<div class="heading-image">
<h3>Heading</h3>
<img="someimage">
</div>
That just works, but on larger screens I want the h3 to drop to the right of the image, which would be at 50% of the screen:
.heading-image img { max-width: 50% };
.heading-image h3 { max-width: 50%; float:right };
Now the h3 drops next to the image on the right hand side. But then it comes to the age old problem of vertically centering multi-line text inside a div, where the height of the div is unknown (dependent on the size of the image and the current screen width), and the length of the text is unknown (these are entered into a CMS).
I have tried a variety of approaches found on the internet, but I am just not getting my head around it. I tried making both the img and h3 a table-cell to get me back to my original approach but I can't get the alignment to work.

Here's the code. Just change the size you want to collapse in the #media-query.
Working fiddle: http://jsfiddle.net/Hv6x3/
HTML
<div class="heading-image">
<h3>Headline text goes here...</h3>
<img src="http://placeimg.com/640/480/tech" alt=""/>
</div>
CSS
.heading-image img {
float: left;
max-width: 50%;
height: auto;
}
.heading-image h3 {
float: right;
width: 50%;
max-width: 50%;
text-align: left;
}
#media (max-width: 600px) {
.heading-image {
text-align: center;
}
.heading-image img {
float: none;
max-width: 100%
}
.heading-image h3 {
float: none;
max-width: 50%;
}
}

for vertical-align....use display:table-cell
make sure the parent div is set as display:table
jsfiddle demo
html, body {
width:100%;
height:100%;
margin:0;
padding:0;
}
#media only screen and (min-width : 600px) {
.heading-image {
width:100%;
height:100%;
margin:0;
padding:0;
text-align:center;
display: table;
}
.heading-image .img {
float:left;
height:100%;
}
.heading-image .h3 {
float:right;
display: table;
height:100%;
}
.heading-image .h3 h3 {
display: table-cell;
vertical-align: middle;
text-align: center;
}
}
#media only screen and (max-width : 600px) {
.heading-image {
width:100%;
margin:0;
padding:0;
text-align:center
}
.heading-image .img {
width: 100%;
}
.heading-image .img img {
width:auto;
height:auto;
}
.heading-image .h3 {
width: 100%;
vertical-align:middle;
}
}

Related

Center image without link with width 100%

I want to center my Logo, but the hyperlink on it extends itself to width 100%, which perfectly makes sense because I set the margin auto.
But how can I still have my Logo centered and have the link only on the area of my image?
.logo {
height: 50px;
display: inline-block;
vertical-align:middle;
padding: 0px 10px;
}
#media (max-width: 600px) {
#nav ul.desktop-nav li {
display: none;
}
.logo {
display: block;
margin: auto;
}
}
<img class="logo" src="logo.png">
If I understand the question correctly, something like this should do the trick:
Have both the logo and the logo-wrapper be inline-block (they will wrap the content, you don't want them display: block). Since they are inline-block elements they can be center aligned via the text-align property of a main wrapper around them. Resize your browser to see your breakpoint take effect.
.wrapper {
text-align: center;
}
.logo-wrapper {
display: inline-block;
}
.logo {
height: 50px;
display: inline-block;
vertical-align: middle;
padding: 0px 10px;
}
#media (min-width: 600px) {
.wrapper {
text-align: left;
}
}
<div class="wrapper">
<a class="logo-wrapper" href="#">
<img class="logo" src="https://i.vimeocdn.com/portrait/58832_300x300">
</a>
</div>
Maybe you put layers which is you want size on the image. Then you attach the link to this layer.

Not So Basic Div Alignment?

I am somewhat new to CSS and thought I was trying to do something simple.
I am creating a responsive page. My goal is to accomplish the following:
Anything smaller than 768px - center each div horizontally. That is happening just fine.
Between 768px and 1024px, Center the main container on the page, with the two divs side by side main container div. Everything is currently not centering.
1024px wide and above - image div on left, text on right - flush to edge of nav.
I am getting super wonky behavior here.
I am fairly certain that I have missed something fairly obvious since I am very new to this and have jumped headfirst into making something I thought was simple. I have been looking at this for quite some time. Could someone attempt to explain this to me for this scenario? Am I nullifying something by declaring referencing code it in my media queries (I did notice I had an issue since I declared mismatched properties at an earlier time)?
<body>
<header>
<img class="style-logo" src="Prism_images/RuckerLogo.png" alt="Logo">
<nav class="style-nav">
<ul>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
<div id="Content">
<div class ="style-img">
<img src="Prism_images/Miles---Headshot_200.png">
</div>
<div class="style-main" id="Text">
<p>premire cabinetmaker</p>
</div>
</div>
<footer></footer>
</body>
And here is the CSS:
header {
padding: 20px;
}
.style-logo {
margin-left: auto;
margin-right: auto;
display: block;
background-color: antiquewhite;
}
.style-nav ul {
list-style-type: none;
display: block;
padding: 0px;
}
.style-nav ul li a {
text-decoration: none;
color: #414040;
text-align: center;
display: block;
text-transform:uppercase;
padding: 2px;
}
.style-img {
margin-left:auto;
margin-right:auto;
width: 200px;
}
.style-main {
margin-left:auto;
margin-right:auto;
width: 450px;
}
.style-main p {
color: slategrey;
text-align:left;
margin-top:0px;
margin-left:10px;
display:block;
}
#Content{
margin-left:auto;
margin-right:auto;
}
/*Tablet View*/
#media (min-width: 768px){
body {
max-width: 778px;
}
.style-logo {
float: center;
}
.style-nav ul li {
display: inline-block;
}
.style-nav ul {
text-align: center;
}
.style-img{
margin-top:0px;
width:200px;
display:inline-block;
}
.style-main {
margin-top:0px;
display:inline-block;
}
#Content {
margin-left:auto;
margin-right:auto;
display:block;
}
}
#media (min-width: 1024px){
body {
max-width: 1100px;
}
.style-logo {
float: left;
}
.style-nav {
float: right;
}
.style-img {
margin-top: 40px;
float:right;
display:inline-block;
}
.style-main {
padding:20px;
display: inline-block;
}
}
This is how to center everything ^^
div {
display: table;
margin: 0 auto;
}
<div>I'm centered<div>
That or this.
div {
display:block;
margin:0 auto;
}

Social Media Links with HTML and CSS

I am a stuck on trying to change the size and location on social media links on a test web page. No matter what size I change the height and width to in the CSS the image remains super large.
#footer {
height: 40px;
background-color: #69D2E7;
clear:both;
font-family:Open Sans;
}
#footer a {
display: inline-block;
margin-right: 5px;
}
#footer img a {
width: auto;
height: 10px;
max-height: 10px;
}
<div id=“footer”><img src="facebook.png"></div>
<div id=“footer”> <img src="pinterest.png"></div>
<div id=“footer”> <img src="instagram.png"></div>
<div id=“footer”><img src="linkedin.png"></div>
Its a matter of position, the img tag is actually inside a tag, so the one with
#footer img a{}
should be changed into
#footer a img {
width: auto;
height: 10px;
max-height: 10px;
}
Hi I have tested this code and its changing height and width of image. Please try this code: #footer a img { height: 30px; width: 35px; }
#footer a img {
width: auto;
height: 10px;
max-height: 10px;
}
To center the hyperlinks, try this:
#footer {
/* other styles */
text-align: center;
}
If that didn't work, try removing inline-block from a
#footer a {
display: inline-block; /* remove this line, if needed. */
}

White space when using 100% Width

A friend and I are working on a website, but for some reason there is still white space when I use 100% width. How can I fix this? These are the main css elements
#info_container{
height:100%;
width:100%;
display:inline-block;
padding-top:3%;
background-color:#D3D3D3;
}
#main_header {
background: -webkit-linear-gradient(#2a2a2a, #545454);
text-align: center;
align-items: center;
vertical-align: middle;
position: absolute;
width:100%;
height:8%;
margin:-1em;
position:fixed;
display: table;
width: 100%;
table-layout: fixed;
/* For cells of equal size */
}
JSFiddle
First best practice is to put universal selector * { padding: 0; margin: 0;}
to avoid the margins and paddings overflow.
I updated your fiddle
Changes to your CSS
* { padding: 0; margin: 0; }
#main_header {
background: -webkit-linear-gradient(#2a2a2a, #545454);
text-align: center;
align-items: center;
vertical-align: middle;
position: absolute;
width:100%;
position:fixed;
display: table;
width: 100%;
table-layout: fixed;
/* For cells of equal size */
}
#main_header a {
display:inline-block;
text-decoration:none;
color:#567aa9;
display: table-cell;
vertical-align: middle;
padding:.5%;
}
a span {
text-decoration:none;
color:#878787;
font-size:55px;
top: 10%;
overflow: hidden;
left:50%;
}
.a1:hover {
color:#bababa;
}
.a2:hover{
color:#bababa;
}
.a3:hover{
color:#bababa;
}
.a4:hover{
color:#bababa;
}
#info_container{
height:100%;
width:100%;
display:inline-block;
padding-top:7%;
}
html {
font-size: 62.5%;
}
body {
font-size: 1em;
}
#media (max-width: 300px) {
html {
font-size: 70%;
}
}
#media (min-width: 500px) {
html {
font-size: 80%;
}
}
#media (min-width: 700px) {
html {
font-size: 120%;
}
}
#media (min-width: 1200px) {
html {
font-size: 200%;
}
}
#info_container{
height: 100px; // changed this from 100%;
width:100%;
padding-top: 3%; // removed
display:inline-block;
background-color:#D3D3D3;
}
EDIT: UPDATED THE FIDDLE
There is a very simple fix to this. You have a background color on your text which goes on the whole line, so to make it only on the text area in your info container, simply put that text into a span class. Now just remove that background color from the original class and put it into your span! You can give a class to the span if you will put it into another css file, but I have just put it directly into the html here.
<p><span style="background-color:red;">Hello World</span></p>

CSS For responsive sidebar and main content?

I found what im looking for ALMOST, (http://codepen.io/anon/pen/PqxQVN).
But the only problem is i need the container to have height of auto and the sidebar to have a height of 100%. When i do that the sidebar disappears.
#container { height:500px; width:100% }
.sidebar { background:red; float:right; height:100%; width:20% }
.content { background:green; height: 100px; width:80%; float:left; margin-top: 20px;}
#media screen and (max-width: 1000px) {
.sidebar { clear:both; width:100% }
.content { width:100%; }
}
Any help would be appreciated. :)
I have used the universal selector (*) to remove padding and margin, therefore the sidebar will be 100% of height.
For what concerns the green container, by simply removing the height from 100px to "auto" it will automatically fill the content.
Link to codepen
*{
margin: 0;
padding: 0;
}
#container { height:500px; width:100% }
.sidebar { background:red; float:right; height:100%; width:20% }
.content { background:green; height: auto; width:80%; float:left; margin-top: 20px}
#media screen and (max-width: 1000px) {
.sidebar { clear:both; width:100% }
.content { width:100%; }
}
This design isn't perfect as you might find some text going under the sidebar, but should be a good start.
Regards,
-Gallo
give the height to sidebar as .sidebar{height:500px;} not to container
*{
margin: 0;
padding: 0;
}
#container { height:auto; width:100% }
.sidebar { background:red; float:right; height:500px; width:20% }
.content { background:green; height: 100px; width:80%; float:left; margin-top: 20px;}
#media screen and (max-width: 1000px) {
.sidebar { clear:both; width:100% }
.content { width:100%; }
}