Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:06:14+00:00 2026-05-31T16:06:14+00:00

I’ve placed a table inside a div and set the table width to 100%.

  • 0

I’ve placed a table inside a div and set the table width to 100%. I am placing an icon to the left of the table within the div, so I used a margin-left property to shift the table over and place the icon using position:absolute and top and left properties. That all works just fine, however the table width is shifted outside of the parent div – apparently because of the left-margin setting. Since I need the table to expand dynamically depending on the browser window’s width I cannot just set a fixed size to keep the table within the div. Ultimately I could wrap all of the div content within a table and layout the elements that way, but I was hoping there would be a better, simpler solution by adjusting my css. Thanks!

What I’m trying to achieve:

|-margin-|
+--------------------------------------------------------------------+
| (div)   +---------------------------------------------------------+|
|         | (table)                                                 ||
|         |                                                         ||
|         +---------------------------------------------------------+|
+--------------------------------------------------------------------+

What I’m getting:

|-margin-|
+--------------------------------------------------------------------+
| (div)   +----------------------------------------------------------|-------+
|         | (table)                                                  |       |
|         |                                                          |       |
|         +----------------------------------------------------------|-------+
+--------------------------------------------------------------------+

Update:
Thanks for all the suggestions. As I was typing out an even longer winded response the answer dawned on me. I thought that width:100% meant “fill but remain within the boundaries of the parent element”, not “assume the designated width of the parent element”. Since the margin-left:80px property set on the table was causing all the trouble I removed it and simply set the div’s padding-left:80px and that fixed the problem.

@Ace – I really wasn’t “asking people to do all the work for me”. Since I described exactly what I did I figured the very simple css wasn’t necessary, but I suppose it might have been helpful. So here it is, along with the final css that worked:

Original css:

.mydiv {
position:relative;
border:1px solid #000000;
}
.myicon {
position:absolute;
left:20;
top:15;
}
.mytable {
border:1px solid #000000; //so I can see it
table-layout:auto;
width:100%;
margin-left:80px;
} 

Final css:

.mydiv {
position:relative;
padding-left:80px;
border:1px solid #000000;
}
.myicon {
position:absolute;
left:20;
top:15;
}
.mytable {
border:1px solid #000000; //so I can see it
table-layout:auto;
width:100%;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:06:15+00:00Added an answer on May 31, 2026 at 4:06 pm

    Removed tables’s margin-left:80px and added padding-left:80px to the div container:

    .mydiv {
    position:relative;
    padding-left:80px;
    border:1px solid #000000;
    }
    .myicon {
    position:absolute;
    left:20;
    top:15;
    }
    .mytable {
    border:1px solid #000000; //so I can see it
    table-layout:auto; 
    width:100%;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.